diff --git a/src/main/java/spoon/pattern/PatternParameterConfigurator.java b/src/main/java/spoon/pattern/PatternParameterConfigurator.java index 1a9c96f2668..7c7cf0c3733 100644 --- a/src/main/java/spoon/pattern/PatternParameterConfigurator.java +++ b/src/main/java/spoon/pattern/PatternParameterConfigurator.java @@ -132,16 +132,16 @@ public PatternParameterConfigurator parameter(String paramName) { return this; } - public PatternParameterConfigurator setMinOccurence(int minOccurence) { - currentParameter.setMinOccurrences(minOccurence); + public PatternParameterConfigurator setMinOccurrence(int minOccurrence) { + currentParameter.setMinOccurrences(minOccurrence); return this; } - public PatternParameterConfigurator setMaxOccurence(int maxOccurence) { - if (maxOccurence == ParameterInfo.UNLIMITED_OCCURRENCES || maxOccurence > 1 && currentParameter.isMultiple() == false) { + public PatternParameterConfigurator setMaxOccurrence(int maxOccurrence) { + if (maxOccurrence == ParameterInfo.UNLIMITED_OCCURRENCES || maxOccurrence > 1 && currentParameter.isMultiple() == false) { throw new SpoonException("Cannot set maxOccurrences > 1 for single value parameter. Call setMultiple(true) first."); } - currentParameter.setMaxOccurrences(maxOccurence); + currentParameter.setMaxOccurrences(maxOccurrence); return this; } diff --git a/src/test/java/spoon/test/template/PatternTest.java b/src/test/java/spoon/test/template/PatternTest.java index 7203936d4c3..a0c511bbb65 100644 --- a/src/test/java/spoon/test/template/PatternTest.java +++ b/src/test/java/spoon/test/template/PatternTest.java @@ -325,7 +325,7 @@ public void testMatchGreedyMultiValueUnlimited() throws Exception { @Test public void testMatchGreedyMultiValueMaxCountLimit() throws Exception { //contract: it is possible to stop matching after a specific number of times - // This is done with method parameterBuilder.setMaxOccurence(maxCount) + // This is done with method parameterBuilder.setMaxOccurrence(maxCount) // explanation: greedy matching eats everything until max count = 3 CtType ctClass = ModelUtils.buildClass(MatchMultiple.class); @@ -514,7 +514,7 @@ public void testMatchPossesiveMultiValueUnlimited() throws Exception { } @Test public void testMatchPossesiveMultiValueMaxCount4() throws Exception { - //contract: maxCount (#setMaxOccurence) can be used to stop Quantifier.POSSESSIVE for matching too much + //contract: maxCount (#setMaxOccurrence) can be used to stop Quantifier.POSSESSIVE for matching too much CtType ctClass = ModelUtils.buildClass(MatchMultiple.class); // note that if we set maxCount = 3, it fails because there is one dangling statement before System.out.println("something") @@ -554,7 +554,7 @@ public void testMatchPossesiveMultiValueMinCount() throws Exception { // pattern // public void matcher1() { // statements1.S(); // Quantifier.GREEDY -// statements2.S(); // Quantifier.POSSESSIVE with setMinOccurence and setMaxOccurence set +// statements2.S(); // Quantifier.POSSESSIVE with setMinOccurrence and setMaxOccurrence set // System.out.println("something"); // "something" -> anything // } @@ -568,7 +568,7 @@ public void testMatchPossesiveMultiValueMinCount() throws Exception { .configurePatternParameters() .configurePatternParameters(pb -> { pb.parameter("statements1").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.GREEDY); - pb.parameter("statements2").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.POSSESSIVE).setMinOccurence(countFinal).setMaxOccurence(countFinal); + pb.parameter("statements2").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.POSSESSIVE).setMinOccurrence(countFinal).setMaxOccurrence(countFinal); pb.parameter("printedValue").byFilter((CtLiteral literal) -> "something".equals(literal.getValue())); }) .build(); @@ -590,7 +590,7 @@ public void testMatchPossesiveMultiValueMinCount2() throws Exception { // pattern: // public void matcher1(List something) { // statements1.S(); // Quantifier.GREEDY -// statements2.S(); // Quantifier.POSSESSIVE with setMinOccurence and setMaxOccurence set +// statements2.S(); // Quantifier.POSSESSIVE with setMinOccurrence and setMaxOccurrence set // for (String v : something) { // System.out.println(v); // can be inlined // } @@ -606,8 +606,8 @@ public void testMatchPossesiveMultiValueMinCount2() throws Exception { .configurePatternParameters(pb -> { pb.byTemplateParameter(); pb.parameter("statements1").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.GREEDY); - pb.parameter("statements2").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.POSSESSIVE).setMinOccurence(countFinal).setMaxOccurence(countFinal); - pb.parameter("inlinedSysOut").byVariable("something").setMatchingStrategy(Quantifier.POSSESSIVE).setContainerKind(ContainerKind.LIST).setMinOccurence(2).matchInlinedStatements(); + pb.parameter("statements2").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.POSSESSIVE).setMinOccurrence(countFinal).setMaxOccurrence(countFinal); + pb.parameter("inlinedSysOut").byVariable("something").setMatchingStrategy(Quantifier.POSSESSIVE).setContainerKind(ContainerKind.LIST).setMinOccurrence(2).matchInlinedStatements(); }) .build(); @@ -624,8 +624,8 @@ public void testMatchPossesiveMultiValueMinCount2() throws Exception { Pattern pattern = PatternBuilder.create(new PatternBuilderHelper(ctClass).setBodyOfMethod("matcher1").getPatternElements()) .configurePatternParameters().build(); // pb.parameter("statements1").setMatchingStrategy(Quantifier.GREEDY); -// pb.parameter("statements2").setMatchingStrategy(Quantifier.POSSESSIVE).setMinOccurence(countFinal).setMaxOccurence(countFinal); -// pb.parameter("inlinedSysOut").setMatchingStrategy(Quantifier.POSSESSIVE).setContainerKind(ContainerKind.LIST).setMinOccurence(2); +// pb.parameter("statements2").setMatchingStrategy(Quantifier.POSSESSIVE).setMinOccurrence(countFinal).setMaxOccurrence(countFinal); +// pb.parameter("inlinedSysOut").setMatchingStrategy(Quantifier.POSSESSIVE).setContainerKind(ContainerKind.LIST).setMinOccurrence(2); // }); List matches = pattern.getMatches(ctClass.getMethodsByName("testMatch1").get(0).getBody()); @@ -647,9 +647,9 @@ public void testMatchGreedyMultiValueMinCount2() throws Exception { .configurePatternParameters(pb -> { pb.byTemplateParameter(); pb.parameter("statements1").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.RELUCTANT); - pb.parameter("statements2").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.GREEDY).setMaxOccurence(count); + pb.parameter("statements2").setContainerKind(ContainerKind.LIST).setMatchingStrategy(Quantifier.GREEDY).setMaxOccurrence(count); pb.parameter("printedValue").byVariable("something").matchInlinedStatements(); - pb.parameter("printedValue").setMatchingStrategy(Quantifier.GREEDY).setContainerKind(ContainerKind.LIST).setMinOccurence(2); + pb.parameter("printedValue").setMatchingStrategy(Quantifier.GREEDY).setContainerKind(ContainerKind.LIST).setMinOccurrence(2); }) .build(); List matches = pattern.getMatches(ctClass.getMethodsByName("testMatch1").get(0).getBody()); @@ -1054,7 +1054,7 @@ public void testMatchInSet() throws Exception { //add matcher for other arbitrary throwables .setConflictResolutionMode(ConflictResolutionMode.APPEND) .setContainerKind(ContainerKind.SET) - .setMinOccurence(0) + .setMinOccurrence(0) .byRole(CtRole.THROWN, new TypeFilter(CtMethod.class)); }) .configurePatternParameters(pb -> { diff --git a/src/test/java/spoon/test/template/testclasses/match/MatchMultiple.java b/src/test/java/spoon/test/template/testclasses/match/MatchMultiple.java index be703a6b098..a3e0b27fba9 100644 --- a/src/test/java/spoon/test/template/testclasses/match/MatchMultiple.java +++ b/src/test/java/spoon/test/template/testclasses/match/MatchMultiple.java @@ -26,10 +26,10 @@ public static Pattern createPattern(Quantifier matchingStrategy, Integer minCoun pb.setMatchingStrategy(matchingStrategy); } if (minCount != null) { - pb.setMinOccurence(minCount); + pb.setMinOccurrence(minCount); } if (maxCount != null) { - pb.setMaxOccurence(maxCount); + pb.setMaxOccurrence(maxCount); } pb.parameter("printedValue").byFilter((CtLiteral literal) -> "something".equals(literal.getValue())); })