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

Add @SuppressWarnings("all") to stop scanning tool complaints #52

Merged
merged 2 commits into from
Dec 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
}

for (Set<String> imports : imports.values()) {
imports.removeIf(i -> "java.lang".equals(i.substring(0, i.lastIndexOf('.'))));
imports.removeIf(i -> {
int endIndex = i.lastIndexOf('.');
return endIndex < 0 || "java.lang".equals(i.substring(0, endIndex));
});
imports.remove(BEFORE_TEMPLATE);
imports.remove(AFTER_TEMPLATE);
}
Expand All @@ -179,6 +182,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
String refasterRuleClassName = classDecl.sym.fullname.toString().substring(classDecl.sym.packge().fullname.length() + 1);
recipe.append("/**\n * OpenRewrite recipe created for Refaster template {@code ").append(refasterRuleClassName).append("}.\n */\n");
String recipeName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1);
recipe.append("@SuppressWarnings(\"all\")\n");
recipe.append("@NonNullApi\n");
recipe.append(descriptor.classDecl.sym.outermostClass() == descriptor.classDecl.sym ?
"public class " : "public static class ").append(recipeName).append(" extends Recipe {\n\n");
Expand Down Expand Up @@ -340,6 +344,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
if (outerClassRequired) {
out.write("/**\n * OpenRewrite recipes created for Refaster template {@code " + inputOuterFQN + "}.\n */\n");
String outerClassName = className.substring(className.lastIndexOf('.') + 1);
out.write("@SuppressWarnings(\"all\")\n");
out.write("public class " + outerClassName + " extends Recipe {\n");
out.write(" /**\n");
out.write(" * Instantiates a new instance.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void visitIdent(JCTree.JCIdent ident) {
out.write("\n");
out.write("/**\n * OpenRewrite `" + templateName.getValue() + "` template created for {@code " + templateFqn.split("_")[0] + "}.\n */\n");
String templateClassName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1);
out.write("@SuppressWarnings(\"all\")\n");
out.write("public class " + templateClassName + " {\n");
out.write(" /**\n");
out.write(" * Instantiates a new instance.\n");
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/refaster/EscapesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.sun.tools.javac.util.Convert;
import com.sun.tools.javac.util.Constants;

@SuppressWarnings("all")
public class EscapesRecipes extends Recipe {
public EscapesRecipes() {}

Expand All @@ -57,6 +58,7 @@ public List<Recipe> getRecipeList() {
);
}

@SuppressWarnings("all")
@NonNullApi
public static class ConstantsFormatRecipe extends Recipe {
public ConstantsFormatRecipe() {}
Expand Down Expand Up @@ -104,6 +106,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
}
}

@SuppressWarnings("all")
@NonNullApi
public static class SplitRecipe extends Recipe {
public SplitRecipe() {}
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/refaster/MatchingRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;


@SuppressWarnings("all")
public class MatchingRecipes extends Recipe {

public MatchingRecipes() {}
Expand All @@ -60,6 +60,7 @@ public List<Recipe> getRecipeList() {
);
}

@SuppressWarnings("all")
@NonNullApi
public static class StringIsEmptyRecipe extends Recipe {

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/refaster/MethodThrowsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.nio.file.Path;
import java.nio.charset.StandardCharsets;

@SuppressWarnings("all")
@NonNullApi
public class MethodThrowsRecipe extends Recipe {

Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/refaster/MultipleDereferencesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.nio.file.Files;
import java.nio.file.Path;

@SuppressWarnings("all")
public class MultipleDereferencesRecipes extends Recipe {

public MultipleDereferencesRecipes() {}
Expand All @@ -59,6 +60,7 @@ public List<Recipe> getRecipeList() {
);
}

@SuppressWarnings("all")
@NonNullApi
public static class VoidTypeRecipe extends Recipe {

Expand Down Expand Up @@ -106,6 +108,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
}
}

@SuppressWarnings("all")
@NonNullApi
public static class StringIsEmptyRecipe extends Recipe {

Expand Down Expand Up @@ -149,6 +152,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
}
}

@SuppressWarnings("all")
@NonNullApi
public static class EqualsItselfRecipe extends Recipe {

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/refaster/NestedPreconditionsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.HashMap;
import java.util.Hashtable;

@SuppressWarnings("all")
@NonNullApi
public class NestedPreconditionsRecipe extends Recipe {

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/ParameterReuseRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;


@SuppressWarnings("all")
@NonNullApi
public class ParameterReuseRecipe extends Recipe {

Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/refaster/ShouldAddImportsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import static java.util.Objects.hash;

@SuppressWarnings("all")
public class ShouldAddImportsRecipes extends Recipe {

public ShouldAddImportsRecipes() {}
Expand All @@ -60,6 +61,7 @@ public List<Recipe> getRecipeList() {
);
}

@SuppressWarnings("all")
@NonNullApi
public static class StringValueOfRecipe extends Recipe {

Expand Down Expand Up @@ -103,6 +105,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
}
}

@SuppressWarnings("all")
@NonNullApi
public static class ObjectsEqualsRecipe extends Recipe {

Expand Down Expand Up @@ -162,6 +165,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
}
}

@SuppressWarnings("all")
@NonNullApi
public static class StaticImportObjectsHashRecipe extends Recipe {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;


@SuppressWarnings("all")
public class ShouldSupportNestedClassesRecipes extends Recipe {

public ShouldSupportNestedClassesRecipes() {}
Expand All @@ -56,6 +56,7 @@ public List<Recipe> getRecipeList() {
);
}

@SuppressWarnings("all")
@NonNullApi
public static class NestedClassRecipe extends Recipe {

Expand Down Expand Up @@ -99,6 +100,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) {
}
}

@SuppressWarnings("all")
@NonNullApi
public static class AnotherClassRecipe extends Recipe {

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 @@ -33,7 +33,7 @@

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;


@SuppressWarnings("all")
@NonNullApi
public class SimplifyBooleansRecipe extends Recipe {

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/refaster/UseStringIsEmptyRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
/**
* OpenRewrite recipe created for Refaster template `UseStringIsEmpty`.
*/
@SuppressWarnings("all")
@NonNullApi
public class UseStringIsEmptyRecipe extends Recipe {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package foo;
import org.openrewrite.java.*;

@SuppressWarnings("all")
public class ParameterReuseRecipe$1_before {
public ParameterReuseRecipe$1_before() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package foo;
import org.openrewrite.java.*;

@SuppressWarnings("all")
public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after {
public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package foo;
import org.openrewrite.java.*;

@SuppressWarnings("all")
public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before {
public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package foo;
import org.openrewrite.java.*;

@SuppressWarnings("all")
public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_after {
public ShouldAddClasspathRecipes$PrimitiveRecipe$1_after() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package foo;
import org.openrewrite.java.*;

@SuppressWarnings("all")
public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_before {
public ShouldAddClasspathRecipes$PrimitiveRecipe$1_before() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package foo;
import org.openrewrite.java.*;

@SuppressWarnings("all")
public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after {
public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package foo;
import org.openrewrite.java.*;

@SuppressWarnings("all")
public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before {
public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before() {}

Expand Down