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

Match method overrides in precondition #100

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
signing

id("nebula.maven-resolved-dependencies") version "17.3.2"
id("nebula.release") version "15.3.1"
id("com.netflix.nebula.release") version "19.0.10"
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"

id("com.github.hierynomus.license") version "0.16.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private Set<String> getImportsAsStrings(Map<TemplateDescriptor, Set<String>> imp
}
String methodName = method.name.toString();
methodName = methodName.equals("<init>") ? "<constructor>" : methodName;
usesVisitors.add("new UsesMethod<>(\"" + method.owner.getQualifiedName().toString() + ' ' + methodName + "(..)\")");
usesVisitors.add("new UsesMethod<>(\"" + method.owner.getQualifiedName().toString() + ' ' + methodName + "(..)\", true)");
}

preconditions.put(beforeTemplate.method.name.toString() + (arity == 1 ? "" : "$" + i), usesVisitors);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/ArraysRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String join(..)"),
new UsesMethod<>("java.lang.String join(..)", true),
javaVisitor
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/resources/refaster/EscapesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
return Preconditions.check(
Preconditions.and(
new UsesType<>("com.sun.tools.javac.util.Convert", true),
new UsesMethod<>("java.lang.String format(..)"),
new UsesMethod<>("com.sun.tools.javac.util.Convert quote(..)")
new UsesMethod<>("java.lang.String format(..)", true),
new UsesMethod<>("com.sun.tools.javac.util.Convert quote(..)", true)
),
javaVisitor
);
Expand Down Expand Up @@ -174,7 +174,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String split(..)"),
new UsesMethod<>("java.lang.String split(..)", true),
javaVisitor
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/FindListAddRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
return Preconditions.check(
Preconditions.and(
new UsesType<>("java.util.List", true),
new UsesMethod<>("java.util.List add(..)")
new UsesMethod<>("java.util.List add(..)", true)
),
javaVisitor
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/GenericsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
return Preconditions.check(
Preconditions.and(
new UsesType<>("java.util.List", true),
new UsesMethod<>("java.util.Iterator next(..)"),
new UsesMethod<>("java.util.List iterator(..)")
new UsesMethod<>("java.util.Iterator next(..)", true),
new UsesMethod<>("java.util.List iterator(..)", true)
),
javaVisitor
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/MatchingRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
};
return Preconditions.check(
Preconditions.and(
new UsesMethod<>("java.lang.String isEmpty(..)"),
new UsesMethod<>("java.lang.String substring(..)")
new UsesMethod<>("java.lang.String isEmpty(..)", true),
new UsesMethod<>("java.lang.String substring(..)", true)
),
javaVisitor
);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/MethodThrowsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
new UsesType<>("java.nio.file.Files", true),
new UsesType<>("java.nio.charset.StandardCharsets", true),
new UsesType<>("java.nio.file.Path", true),
new UsesMethod<>("java.nio.file.Files readAllLines(..)")
new UsesMethod<>("java.nio.file.Files readAllLines(..)", true)
),
javaVisitor
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/MultipleDereferencesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
Preconditions.and(
new UsesType<>("java.nio.file.Files", true),
new UsesType<>("java.nio.file.Path", true),
new UsesMethod<>("java.nio.file.Files delete(..)")
new UsesMethod<>("java.nio.file.Files delete(..)", true)
),
javaVisitor
);
Expand Down Expand Up @@ -172,7 +172,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String isEmpty(..)"),
new UsesMethod<>("java.lang.String isEmpty(..)", true),
javaVisitor
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/refaster/NestedPreconditionsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public J visitNewClass(J.NewClass elem, ExecutionContext ctx) {
Preconditions.or(
Preconditions.and(
new UsesType<>("java.util.HashMap", true),
new UsesMethod<>("java.util.HashMap <constructor>(..)")
new UsesMethod<>("java.util.HashMap <constructor>(..)", true)
),
Preconditions.and(
new UsesType<>("java.util.LinkedHashMap", true),
new UsesMethod<>("java.util.LinkedHashMap <constructor>(..)")
new UsesMethod<>("java.util.LinkedHashMap <constructor>(..)", true)
)
)
),
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/PicnicRulesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String replaceAll(..)"),
new UsesMethod<>("java.lang.String replaceAll(..)", true),
javaVisitor
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/resources/refaster/RefasterAnyOfRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String length(..)"),
new UsesMethod<>("java.lang.String length(..)", true),
javaVisitor
);
}
Expand Down Expand Up @@ -197,11 +197,11 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
Preconditions.or(
Preconditions.and(
new UsesType<>("java.util.LinkedList", true),
new UsesMethod<>("java.util.LinkedList <constructor>(..)")
new UsesMethod<>("java.util.LinkedList <constructor>(..)", true)
),
Preconditions.and(
new UsesType<>("java.util.Collections", true),
new UsesMethod<>("java.util.Collections emptyList(..)")
new UsesMethod<>("java.util.Collections emptyList(..)", true)
)
)
),
Expand Down Expand Up @@ -271,8 +271,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
};
return Preconditions.check(
Preconditions.or(
new UsesMethod<>("java.lang.String valueOf(..)"),
new UsesMethod<>("java.lang.String copyValueOf(..)")
new UsesMethod<>("java.lang.String valueOf(..)", true),
new UsesMethod<>("java.lang.String copyValueOf(..)", true)
),
javaVisitor
);
Expand Down
14 changes: 7 additions & 7 deletions src/test/resources/refaster/ShouldAddImportsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String valueOf(..)"),
new UsesMethod<>("java.lang.String valueOf(..)", true),
javaVisitor
);
}
Expand Down Expand Up @@ -186,9 +186,9 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
Preconditions.or(
Preconditions.and(
new UsesType<>("java.util.Objects", true),
new UsesMethod<>("java.util.Objects equals(..)")
new UsesMethod<>("java.util.Objects equals(..)", true)
),
new UsesMethod<>("java.lang.Integer compare(..)")
new UsesMethod<>("java.lang.Integer compare(..)", true)
),
javaVisitor
);
Expand Down Expand Up @@ -245,7 +245,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.util.Objects hash(..)"),
new UsesMethod<>("java.util.Objects hash(..)", true),
javaVisitor
);
}
Expand Down Expand Up @@ -302,8 +302,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
return Preconditions.check(
Preconditions.and(
new UsesType<>("java.nio.file.Path", true),
new UsesMethod<>("java.io.File exists(..)"),
new UsesMethod<>("java.nio.file.Path toFile(..)")
new UsesMethod<>("java.io.File exists(..)", true),
new UsesMethod<>("java.nio.file.Path toFile(..)", true)
),
javaVisitor
);
Expand Down Expand Up @@ -351,7 +351,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String isEmpty(..)"),
new UsesMethod<>("java.lang.String isEmpty(..)", true),
javaVisitor
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String length(..)"),
new UsesMethod<>("java.lang.String length(..)", true),
javaVisitor
);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String length(..)"),
new UsesMethod<>("java.lang.String length(..)", true),
javaVisitor
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/SimplifyBooleansRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String replaceAll(..)"),
new UsesMethod<>("java.lang.String replaceAll(..)", true),
javaVisitor
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/UseStringIsEmptyRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) {

};
return Preconditions.check(
new UsesMethod<>("java.lang.String length(..)"),
new UsesMethod<>("java.lang.String length(..)", true),
javaVisitor
);
}
Expand Down
Loading