Skip to content

Commit

Permalink
fix: typo in patterns (#2249)
Browse files Browse the repository at this point in the history
@monperrus 

This PR is follow up to refactor: fix naming occurences (re-introduced) #2214
As you merged #2214, this one should be too.
This PR finishes partial fix from #2214

Previous discussion: #2206
@pvojtechovsky 
> ... it is interesting how much work might be to fix one missing r ... :-(

It is even more - it looks like I forgot to rename:
- setMinOccurence method and its argument
- setMaxOccurence
- patterns

so I created this PR.

Because we cannot have pair:
- setMinOccurence (single *r*)
- setMaxOccurrence (double *r*)

this PR is required for consistency and to clean a mess. Sorry!

I think now we have consistent min/max methods & their arguments & correct patterns. Someone please take a look.

I am ready to merge.
  • Loading branch information
zielint0 authored and surli committed Jul 30, 2018
1 parent a1d0861 commit f499611
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
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

0 comments on commit f499611

Please sign in to comment.