diff --git a/src/main/java/org/openrewrite/staticanalysis/BigDecimalRoundingConstantsToEnums.java b/src/main/java/org/openrewrite/staticanalysis/BigDecimalRoundingConstantsToEnums.java index ce690768a..077f06070 100644 --- a/src/main/java/org/openrewrite/staticanalysis/BigDecimalRoundingConstantsToEnums.java +++ b/src/main/java/org/openrewrite/staticanalysis/BigDecimalRoundingConstantsToEnums.java @@ -114,8 +114,7 @@ private boolean isConvertibleBigDecimalConstant(J elem) { return false; } - @Nullable - private String getTemplateText(J elem) { + private @Nullable String getTemplateText(J elem) { String roundingName = null; if (elem instanceof J.FieldAccess && ((J.FieldAccess) elem).getTarget().getType() instanceof JavaType.FullyQualified) { J.FieldAccess fa = (J.FieldAccess) elem; diff --git a/src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java b/src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java index cdd0c930a..6907d8f4a 100644 --- a/src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java +++ b/src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java @@ -132,8 +132,7 @@ public static J.Binary concatAdditionBinary(Expression left, Expression right) { /** * Concat expressions to an expression with '+' connected. */ - @Nullable - public static Expression additiveExpression(Expression... expressions) { + public static @Nullable Expression additiveExpression(Expression... expressions) { Expression expression = null; for (Expression element : expressions) { if (element != null) { @@ -143,8 +142,7 @@ public static Expression additiveExpression(Expression... expressions) { return expression; } - @Nullable - public static Expression additiveExpression(List expressions) { + public static @Nullable Expression additiveExpression(List expressions) { return additiveExpression(expressions.toArray(new Expression[0])); } diff --git a/src/main/java/org/openrewrite/staticanalysis/ExplicitLambdaArgumentTypes.java b/src/main/java/org/openrewrite/staticanalysis/ExplicitLambdaArgumentTypes.java index 9bf1ae0a3..eddb95980 100755 --- a/src/main/java/org/openrewrite/staticanalysis/ExplicitLambdaArgumentTypes.java +++ b/src/main/java/org/openrewrite/staticanalysis/ExplicitLambdaArgumentTypes.java @@ -122,8 +122,7 @@ private J.VariableDeclarations maybeAddTypeExpression(J.VariableDeclarations mul return multiVariable; } - @Nullable - private TypeTree buildTypeTree(@Nullable JavaType type, Space space) { + private @Nullable TypeTree buildTypeTree(@Nullable JavaType type, Space space) { if (type == null || type instanceof JavaType.Unknown) { return null; } else if (type instanceof JavaType.Primitive) { @@ -209,8 +208,7 @@ private TypeTree buildTypeTree(@Nullable JavaType type, Space space) { return null; } - @Nullable - private JContainer buildTypeParameters(List typeParameters) { + private @Nullable JContainer buildTypeParameters(List typeParameters) { List> typeExpressions = new ArrayList<>(); for (JavaType type : typeParameters) { diff --git a/src/main/java/org/openrewrite/staticanalysis/FinalizePrivateFields.java b/src/main/java/org/openrewrite/staticanalysis/FinalizePrivateFields.java index 4da74bc9d..914ae99cf 100644 --- a/src/main/java/org/openrewrite/staticanalysis/FinalizePrivateFields.java +++ b/src/main/java/org/openrewrite/staticanalysis/FinalizePrivateFields.java @@ -299,14 +299,14 @@ private static boolean isInLambda(Cursor cursor) { @Value @EqualsAndHashCode(callSuper = false) private static class FindLastIdentifier extends JavaIsoVisitor> { + /** * Find the last identifier in a J.FieldAccess. The purpose is to check whether it's a private field. * * @param j the subtree to search, supposed to be a J.FieldAccess * @return the last Identifier if found, otherwise null. */ - @Nullable - static J.Identifier getLastIdentifier(J j) { + static @Nullable J.Identifier getLastIdentifier(J j) { List ids = new FindLastIdentifier().reduce(j, new ArrayList<>()); return !ids.isEmpty() ? ids.get(ids.size() - 1) : null; } diff --git a/src/main/java/org/openrewrite/staticanalysis/ForLoopIncrementInUpdate.java b/src/main/java/org/openrewrite/staticanalysis/ForLoopIncrementInUpdate.java index 110fac692..8a635ac9f 100644 --- a/src/main/java/org/openrewrite/staticanalysis/ForLoopIncrementInUpdate.java +++ b/src/main/java/org/openrewrite/staticanalysis/ForLoopIncrementInUpdate.java @@ -89,9 +89,9 @@ public J visitForLoop(J.ForLoop forLoop, ExecutionContext ctx) { //noinspection ConstantConditions f = f.withBody((Statement) new JavaVisitor() { - @Nullable + @Override - public J visit(@Nullable Tree tree, ExecutionContext ctx) { + public @Nullable J visit(@Nullable Tree tree, ExecutionContext ctx) { return tree == unary ? null : super.visit(tree, ctx); } }.visit(f.getBody(), ctx)); diff --git a/src/main/java/org/openrewrite/staticanalysis/InlineVariable.java b/src/main/java/org/openrewrite/staticanalysis/InlineVariable.java index 8e3714663..6a0fd9c47 100644 --- a/src/main/java/org/openrewrite/staticanalysis/InlineVariable.java +++ b/src/main/java/org/openrewrite/staticanalysis/InlineVariable.java @@ -94,8 +94,7 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) { return bl; } - @Nullable - private String identReturned(List stats) { + private @Nullable String identReturned(List stats) { Statement lastStatement = stats.get(stats.size() - 1); if (lastStatement instanceof J.Return) { J.Return return_ = (J.Return) lastStatement; diff --git a/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java b/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java index 53f674ec2..8bd449292 100644 --- a/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java +++ b/src/main/java/org/openrewrite/staticanalysis/InstanceOfPatternMatch.java @@ -268,8 +268,7 @@ private String patternVariableName(J.InstanceOf instanceOf, Cursor cursor) { return VariableNameUtils.generateVariableName(baseName, cursor, INCREMENT_NUMBER); } - @Nullable - public J processTypeCast(J.TypeCast typeCast, Cursor cursor) { + public @Nullable J processTypeCast(J.TypeCast typeCast, Cursor cursor) { J.InstanceOf instanceOf = replacements.get(typeCast); if (instanceOf != null && instanceOf.getPattern() != null) { String name = ((J.Identifier) instanceOf.getPattern()).getSimpleName(); @@ -288,8 +287,7 @@ public J processTypeCast(J.TypeCast typeCast, Cursor cursor) { return null; } - @Nullable - public J processVariableDeclarations(J.VariableDeclarations multiVariable) { + public @Nullable J processVariableDeclarations(J.VariableDeclarations multiVariable) { return multiVariable.getVariables().stream().anyMatch(variablesToDelete::containsValue) ? null : multiVariable; } } @@ -302,8 +300,7 @@ public UseInstanceOfPatternMatching(InstanceOfPatternReplacements replacements) this.replacements = replacements; } - @Nullable - static J refactor(@Nullable J tree, InstanceOfPatternReplacements replacements, Cursor cursor) { + static @Nullable J refactor(@Nullable J tree, InstanceOfPatternReplacements replacements, Cursor cursor) { return new UseInstanceOfPatternMatching(replacements).visit(tree, 0, cursor); } @@ -362,8 +359,7 @@ public J visitTypeCast(J.TypeCast typeCast, Integer executionContext) { @SuppressWarnings("NullableProblems") @Override - @Nullable - public J visitVariableDeclarations(J.VariableDeclarations multiVariable, Integer integer) { + public @Nullable J visitVariableDeclarations(J.VariableDeclarations multiVariable, Integer integer) { multiVariable = (J.VariableDeclarations) super.visitVariableDeclarations(multiVariable, integer); return replacements.processVariableDeclarations(multiVariable); } diff --git a/src/main/java/org/openrewrite/staticanalysis/JavaElementFactory.java b/src/main/java/org/openrewrite/staticanalysis/JavaElementFactory.java index b0e3f1412..26a4283bd 100644 --- a/src/main/java/org/openrewrite/staticanalysis/JavaElementFactory.java +++ b/src/main/java/org/openrewrite/staticanalysis/JavaElementFactory.java @@ -120,8 +120,7 @@ static J.MemberReference newInstanceMethodReference(Expression containing, Strin ); } - @Nullable - static J.FieldAccess newClassLiteral(@Nullable JavaType type, boolean qualified) { + static @Nullable J.FieldAccess newClassLiteral(@Nullable JavaType type, boolean qualified) { JavaType.Class classType = getClassType(type); if (classType == null) { return null; @@ -142,8 +141,7 @@ static J.FieldAccess newClassLiteral(@Nullable JavaType type, boolean qualified) ); } - @Nullable - private static JavaType.Class getClassType(@Nullable JavaType type) { + private static @Nullable JavaType.Class getClassType(@Nullable JavaType type) { if (type instanceof JavaType.Class) { JavaType.Class classType = (JavaType.Class) type; if (classType.getFullyQualifiedName().equals("java.lang.Class")) { diff --git a/src/main/java/org/openrewrite/staticanalysis/NoPrimitiveWrappersForToStringOrCompareTo.java b/src/main/java/org/openrewrite/staticanalysis/NoPrimitiveWrappersForToStringOrCompareTo.java index 4e32ff2ff..37e4b4848 100644 --- a/src/main/java/org/openrewrite/staticanalysis/NoPrimitiveWrappersForToStringOrCompareTo.java +++ b/src/main/java/org/openrewrite/staticanalysis/NoPrimitiveWrappersForToStringOrCompareTo.java @@ -123,8 +123,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu return mi; } - @Nullable - private Expression getSingleArg(@Nullable List args) { + private @Nullable Expression getSingleArg(@Nullable List args) { if (args != null && args.size() == 1 && !(args.get(0) instanceof J.Empty)) { return args.get(0); } diff --git a/src/main/java/org/openrewrite/staticanalysis/RemoveMethodCallVisitor.java b/src/main/java/org/openrewrite/staticanalysis/RemoveMethodCallVisitor.java index 2ae53e2ff..7423225d2 100644 --- a/src/main/java/org/openrewrite/staticanalysis/RemoveMethodCallVisitor.java +++ b/src/main/java/org/openrewrite/staticanalysis/RemoveMethodCallVisitor.java @@ -46,21 +46,18 @@ public class RemoveMethodCallVisitor

extends JavaIsoVisitor

{ private final BiPredicate argumentPredicate; @SuppressWarnings("NullableProblems") - @Nullable @Override - public J.NewClass visitNewClass(J.NewClass newClass, P p) { + public @Nullable J.NewClass visitNewClass(J.NewClass newClass, P p) { return visitMethodCall(newClass, () -> super.visitNewClass(newClass, p)); } @SuppressWarnings("NullableProblems") - @Nullable @Override - public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, P p) { + public @Nullable J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, P p) { return visitMethodCall(method, () -> super.visitMethodInvocation(method, p)); } - @Nullable - private M visitMethodCall(M methodCall, Supplier visitSuper) { + private @Nullable M visitMethodCall(M methodCall, Supplier visitSuper) { if (!methodMatcher.matches(methodCall)) { return visitSuper.get(); } diff --git a/src/main/java/org/openrewrite/staticanalysis/RenameToCamelCase.java b/src/main/java/org/openrewrite/staticanalysis/RenameToCamelCase.java index 52ee5f7b1..4b4463951 100644 --- a/src/main/java/org/openrewrite/staticanalysis/RenameToCamelCase.java +++ b/src/main/java/org/openrewrite/staticanalysis/RenameToCamelCase.java @@ -85,8 +85,7 @@ protected String computeKey(String identifier, J context) { return identifier; } - @Nullable - protected JavaType.Variable getFieldType(J tree) { + protected @Nullable JavaType.Variable getFieldType(J tree) { if (tree instanceof J.Identifier) { return ((J.Identifier) tree).getFieldType(); } diff --git a/src/main/java/org/openrewrite/staticanalysis/SimplifyConsecutiveAssignments.java b/src/main/java/org/openrewrite/staticanalysis/SimplifyConsecutiveAssignments.java index d68202f86..9579a4934 100644 --- a/src/main/java/org/openrewrite/staticanalysis/SimplifyConsecutiveAssignments.java +++ b/src/main/java/org/openrewrite/staticanalysis/SimplifyConsecutiveAssignments.java @@ -101,8 +101,7 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) { * @return The name of a numeric variable being assigned or null if not a numeric * variable assignment. */ - @Nullable - private String numericVariableName(Statement s) { + private @Nullable String numericVariableName(Statement s) { if (s instanceof J.Assignment) { return singleVariableName(((J.Assignment) s).getVariable()); } else if (s instanceof J.VariableDeclarations) { @@ -114,8 +113,7 @@ private String numericVariableName(Statement s) { return null; } - @Nullable - private Expression numericVariableAccumulation(Statement s, String name) { + private @Nullable Expression numericVariableAccumulation(Statement s, String name) { if (s instanceof J.Unary) { if (name.equals(singleVariableName(((J.Unary) s).getExpression()))) { return new J.Literal(Tree.randomId(), Space.EMPTY, Markers.EMPTY, 1, "1", null, @@ -130,8 +128,7 @@ private Expression numericVariableAccumulation(Statement s, String name) { return null; } - @Nullable - private String numericVariableOperator(Statement s, String name) { + private @Nullable String numericVariableOperator(Statement s, String name) { if (s instanceof J.Unary) { if (name.equals(singleVariableName(((J.Unary) s).getExpression()))) { switch (((J.Unary) s).getOperator()) { @@ -175,8 +172,7 @@ private String numericVariableOperator(Statement s, String name) { return null; } - @Nullable - private String singleVariableName(Expression e) { + private @Nullable String singleVariableName(Expression e) { JavaType.Primitive type = TypeUtils.asPrimitive(e.getType()); return type != null && type.isNumeric() && e instanceof J.Identifier ? ((J.Identifier) e).getSimpleName() : diff --git a/src/main/java/org/openrewrite/staticanalysis/SimplifyDurationCreationUnits.java b/src/main/java/org/openrewrite/staticanalysis/SimplifyDurationCreationUnits.java index 89421d564..336dde90c 100644 --- a/src/main/java/org/openrewrite/staticanalysis/SimplifyDurationCreationUnits.java +++ b/src/main/java/org/openrewrite/staticanalysis/SimplifyDurationCreationUnits.java @@ -112,8 +112,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu }); } - @Nullable - public static Long getConstantIntegralValue(Expression expression) { + public static @Nullable Long getConstantIntegralValue(Expression expression) { if (expression instanceof J.Literal) { J.Literal literal = (J.Literal) expression; if (literal.getType() != JavaType.Primitive.Int && literal.getType() != JavaType.Primitive.Long) { diff --git a/src/main/java/org/openrewrite/staticanalysis/TernaryOperatorsShouldNotBeNested.java b/src/main/java/org/openrewrite/staticanalysis/TernaryOperatorsShouldNotBeNested.java index f81a59ecc..d8ec002ee 100644 --- a/src/main/java/org/openrewrite/staticanalysis/TernaryOperatorsShouldNotBeNested.java +++ b/src/main/java/org/openrewrite/staticanalysis/TernaryOperatorsShouldNotBeNested.java @@ -299,8 +299,7 @@ private Optional findConditionIdentifier(final J.Ternary ternary) } - @Nullable - private static J.Identifier xorVariable(J first, J second) { + private static @Nullable J.Identifier xorVariable(J first, J second) { J.Identifier result = null; if (isVariable(first) && isVariable(second)) { return null; diff --git a/src/main/java/org/openrewrite/staticanalysis/UnnecessaryThrows.java b/src/main/java/org/openrewrite/staticanalysis/UnnecessaryThrows.java index 1d63357ce..253cdf202 100644 --- a/src/main/java/org/openrewrite/staticanalysis/UnnecessaryThrows.java +++ b/src/main/java/org/openrewrite/staticanalysis/UnnecessaryThrows.java @@ -67,9 +67,9 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex if (!unusedThrows.isEmpty()) { new JavaIsoVisitor() { - @Nullable + @Override - public J visit(@Nullable Tree tree, ExecutionContext ctx) { + public @Nullable J visit(@Nullable Tree tree, ExecutionContext ctx) { if (unusedThrows.isEmpty()) { return (J) tree; } diff --git a/src/main/java/org/openrewrite/staticanalysis/UpperCaseLiteralSuffixes.java b/src/main/java/org/openrewrite/staticanalysis/UpperCaseLiteralSuffixes.java index 23006a5bb..d43837de7 100644 --- a/src/main/java/org/openrewrite/staticanalysis/UpperCaseLiteralSuffixes.java +++ b/src/main/java/org/openrewrite/staticanalysis/UpperCaseLiteralSuffixes.java @@ -77,8 +77,7 @@ public J.VariableDeclarations.NamedVariable visitVariable(J.VariableDeclarations return nv; } - @Nullable - private String upperCaseSuffix(@Nullable String valueSource) { + private @Nullable String upperCaseSuffix(@Nullable String valueSource) { if (valueSource == null || valueSource.length() < 2) { return valueSource; } diff --git a/src/main/java/org/openrewrite/staticanalysis/UseDiamondOperator.java b/src/main/java/org/openrewrite/staticanalysis/UseDiamondOperator.java index 22f339b73..5212481c7 100644 --- a/src/main/java/org/openrewrite/staticanalysis/UseDiamondOperator.java +++ b/src/main/java/org/openrewrite/staticanalysis/UseDiamondOperator.java @@ -198,8 +198,7 @@ public J.Return visitReturn(J.Return _return, ExecutionContext ctx) { return return_; } - @Nullable - private List parameterizedTypes(J.ParameterizedType parameterizedType) { + private @Nullable List parameterizedTypes(J.ParameterizedType parameterizedType) { if (parameterizedType.getTypeParameters() == null) { return null; } diff --git a/src/main/java/org/openrewrite/staticanalysis/UseLambdaForFunctionalInterface.java b/src/main/java/org/openrewrite/staticanalysis/UseLambdaForFunctionalInterface.java index ba3296dfd..c85e0978e 100644 --- a/src/main/java/org/openrewrite/staticanalysis/UseLambdaForFunctionalInterface.java +++ b/src/main/java/org/openrewrite/staticanalysis/UseLambdaForFunctionalInterface.java @@ -385,9 +385,8 @@ public J visitNewClass(J.NewClass newClass, List variables) { return newClass; } - @Nullable @Override - public J visit(@Nullable Tree tree, List variables) { + public @Nullable J visit(@Nullable Tree tree, List variables) { if (getCursor().getNearestMessage("stop") != null) { return (J) tree; } @@ -427,8 +426,7 @@ public J visitMethodInvocation(J.MethodInvocation method, AtomicBoolean atomicBo } // TODO consider moving to TypeUtils - @Nullable - private static JavaType.Method getSamCompatible(@Nullable JavaType type) { + private static @Nullable JavaType.Method getSamCompatible(@Nullable JavaType type) { JavaType.Method sam = null; JavaType.FullyQualified fullyQualified = TypeUtils.asFullyQualified(type); if (fullyQualified == null) {