Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typo: Occurence->Occurrence (important for consistency, see previous changes!) #2249

Merged
merged 5 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/spoon/pattern/PatternParameterConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/spoon/test/template/PatternTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
// }

Expand All @@ -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();
Expand All @@ -590,7 +590,7 @@ public void testMatchPossesiveMultiValueMinCount2() throws Exception {
// pattern:
// public void matcher1(List<String> 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
// }
Expand All @@ -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();

Expand All @@ -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<Match> matches = pattern.getMatches(ctClass.getMethodsByName("testMatch1").get(0).getBody());
Expand All @@ -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<Match> matches = pattern.getMatches(ctClass.getMethodsByName("testMatch1").get(0).getBody());
Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
})
Expand Down