Skip to content

Commit 47cdf1e

Browse files
authored
Merge branch 'main' into inline-returned-value
2 parents 32d2713 + 9092e3c commit 47cdf1e

File tree

44 files changed

+975
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+975
-201
lines changed

src/main/java/org/openrewrite/staticanalysis/AddSerialVersionUidToSerializable.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,14 @@ private J.VariableDeclarations maybeFixVariableDeclarations(J.VariableDeclaratio
126126
private boolean requiresSerialVersionField(@Nullable JavaType type) {
127127
if (type == null) {
128128
return false;
129-
} else if (type instanceof JavaType.Primitive) {
129+
}
130+
if (type instanceof JavaType.Primitive) {
130131
return true;
131-
} else if (type instanceof JavaType.Array) {
132+
}
133+
if (type instanceof JavaType.Array) {
132134
return requiresSerialVersionField(((JavaType.Array) type).getElemType());
133-
} else if (type instanceof JavaType.Parameterized) {
135+
}
136+
if (type instanceof JavaType.Parameterized) {
134137
JavaType.Parameterized parameterized = (JavaType.Parameterized) type;
135138
if (parameterized.isAssignableTo("java.util.Collection") || parameterized.isAssignableTo("java.util.Map")) {
136139
//If the type is either a collection or a map, make sure the type parameters are serializable. We

src/main/java/org/openrewrite/staticanalysis/AvoidBoxedBooleanExpressions.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ public J visitUnary(J.Unary unary, ExecutionContext ctx) {
7878
private boolean isControlExpression(Expression expression) {
7979
Cursor parentCursor = getCursor().getParentTreeCursor();
8080
if (parentCursor.getValue() instanceof J.ControlParentheses &&
81-
parentCursor.getParentTreeCursor().getValue() instanceof J.If) {
81+
parentCursor.getParentTreeCursor().getValue() instanceof J.If) {
8282
return true;
83-
} else if (parentCursor.getValue() instanceof J.Ternary) {
83+
}
84+
if (parentCursor.getValue() instanceof J.Ternary) {
8485
return ((J.Ternary) parentCursor.getValue()).getCondition() == expression;
8586
}
8687
return false;

src/main/java/org/openrewrite/staticanalysis/BigDecimalRoundingConstantsToEnums.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
107107
private boolean isConvertibleBigDecimalConstant(J elem) {
108108
if (elem instanceof J.Literal) {
109109
return true;
110-
} else if (elem instanceof J.FieldAccess && ((J.FieldAccess) elem).getTarget().getType() instanceof JavaType.FullyQualified) {
110+
}
111+
if (elem instanceof J.FieldAccess && ((J.FieldAccess) elem).getTarget().getType() instanceof JavaType.FullyQualified) {
111112
J.FieldAccess fa = (J.FieldAccess) elem;
112113
return fa.getTarget().getType() != null && TypeUtils.isOfClassType(fa.getTarget().getType(), "java.math.BigDecimal");
113114
}

src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,12 @@ public static boolean flatAdditiveExpressions(Expression expression, List<Expres
185185
}
186186

187187
return flatAdditiveExpressions(b.getLeft(), expressionList) &&
188-
flatAdditiveExpressions(b.getRight(), expressionList);
189-
} else if (expression instanceof J.Literal ||
190-
expression instanceof J.Identifier ||
191-
expression instanceof J.MethodInvocation ||
192-
expression instanceof J.Parentheses) {
188+
flatAdditiveExpressions(b.getRight(), expressionList);
189+
}
190+
if (expression instanceof J.Literal ||
191+
expression instanceof J.Identifier ||
192+
expression instanceof J.MethodInvocation ||
193+
expression instanceof J.Parentheses) {
193194
expressionList.add(expression.withPrefix(Space.EMPTY));
194195
return true;
195196
}

src/main/java/org/openrewrite/staticanalysis/CombineSemanticallyEqualCatchBlocks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,8 @@ private static List<NameTree> getCaughtExceptions(J.Try.Catch aCatch) {
18001800
TypeTree typeExpr = aCatch.getParameter().getTree().getTypeExpression();
18011801
if (typeExpr instanceof J.MultiCatch) {
18021802
return ((J.MultiCatch) typeExpr).getAlternatives();
1803-
} else if (typeExpr != null) { // Can be J.Identifier or J.FieldAccess
1803+
}
1804+
if (typeExpr != null) { // Can be J.Identifier or J.FieldAccess
18041805
return singletonList(typeExpr);
18051806
}
18061807
return emptyList();

src/main/java/org/openrewrite/staticanalysis/ControlFlowIndentation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) {
9999
boolean shouldReformat(Statement s) {
100100
if (s instanceof J.If) {
101101
return shouldReformat((J.If) s);
102-
} else if (s instanceof Loop) {
102+
}
103+
if (s instanceof Loop) {
103104
Statement body = ((Loop) s).getBody();
104105
return !(body instanceof J.Block);
105106
}

src/main/java/org/openrewrite/staticanalysis/DefaultComesLastVisitor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ private List<J.Case> maybeReorderFallthroughCases(List<J.Case> cases, P p) {
111111
} else if (defaultCase != null) {
112112
if (!aCase.getStatements().isEmpty() && i != cases.size() - 1) {
113113
return cases;
114-
} else {
115-
postDefaultCases.add(aCase);
116114
}
115+
postDefaultCases.add(aCase);
117116
} else {
118117
preDefaultCases.add(aCase);
119118
}

src/main/java/org/openrewrite/staticanalysis/EmptyBlockVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ private boolean isEmptyBlock(Statement blockNode) {
214214
J.Block block = (J.Block) blockNode;
215215
if (EmptyBlockStyle.BlockPolicy.STATEMENT == emptyBlockStyle.getBlockPolicy()) {
216216
return block.getStatements().isEmpty();
217-
} else if (EmptyBlockStyle.BlockPolicy.TEXT == emptyBlockStyle.getBlockPolicy()) {
217+
}
218+
if (EmptyBlockStyle.BlockPolicy.TEXT == emptyBlockStyle.getBlockPolicy()) {
218219
return block.getStatements().isEmpty() && block.getEnd().getComments().isEmpty();
219220
}
220221
}

src/main/java/org/openrewrite/staticanalysis/ExplicitInitializationVisitor.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,21 @@ public J.VariableDeclarations.NamedVariable visitVariable(J.VariableDeclarations
4646
if (maybeBlockOrGType.getParent() == null || maybeBlockOrGType.getParent().getParent() == null) {
4747
// Groovy type.
4848
return v;
49-
} else {
50-
J maybeClassDecl = maybeBlockOrGType
51-
.getParentTreeCursor() // maybe J.ClassDecl or J.NewClass
52-
.getValue();
53-
if (!(maybeClassDecl instanceof J.ClassDeclaration || maybeClassDecl instanceof J.NewClass)) {
54-
return v;
55-
}
49+
}
50+
J maybeClassDecl = maybeBlockOrGType
51+
.getParentTreeCursor() // maybe J.ClassDecl or J.NewClass
52+
.getValue();
53+
if (!(maybeClassDecl instanceof J.ClassDeclaration || maybeClassDecl instanceof J.NewClass)) {
54+
return v;
55+
}
5656

57-
if (!(maybeClassDecl instanceof J.NewClass) &&
58-
J.ClassDeclaration.Kind.Type.Class != ((J.ClassDeclaration) maybeClassDecl).getKind()) {
59-
return v;
60-
}
57+
if (!(maybeClassDecl instanceof J.NewClass) &&
58+
J.ClassDeclaration.Kind.Type.Class != ((J.ClassDeclaration) maybeClassDecl).getKind()) {
59+
return v;
60+
}
6161

62-
if (!(variableDeclsCursor.getValue() instanceof J.VariableDeclarations)) {
63-
return v;
64-
}
62+
if (!(variableDeclsCursor.getValue() instanceof J.VariableDeclarations)) {
63+
return v;
6564
}
6665
Iterator<Cursor> clz = getCursor().getPathAsCursors(c -> c.getValue() instanceof J.ClassDeclaration);
6766
if (clz.hasNext() && service(AnnotationService.class).matches(clz.next(), LOMBOK_VALUE)) {

src/main/java/org/openrewrite/staticanalysis/ExplicitLambdaArgumentTypes.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,16 @@ private J.VariableDeclarations maybeAddTypeExpression(J.VariableDeclarations mul
117117
private @Nullable TypeTree buildTypeTree(@Nullable JavaType type, Space space) {
118118
if (type == null || type instanceof JavaType.Unknown) {
119119
return null;
120-
} else if (type instanceof JavaType.Primitive) {
120+
}
121+
if (type instanceof JavaType.Primitive) {
121122
return new J.Primitive(
122123
Tree.randomId(),
123124
space,
124125
Markers.EMPTY,
125126
(JavaType.Primitive) type
126127
);
127-
} else if (type instanceof JavaType.FullyQualified) {
128+
}
129+
if (type instanceof JavaType.FullyQualified) {
128130

129131
JavaType.FullyQualified fq = (JavaType.FullyQualified) type;
130132

@@ -153,11 +155,11 @@ private J.VariableDeclarations maybeAddTypeExpression(J.VariableDeclarations mul
153155
new JavaType.Parameterized(null, fq, fq.getTypeParameters())
154156
);
155157

156-
} else {
157-
maybeAddImport(fq);
158-
return identifier;
159158
}
160-
} else if (type instanceof JavaType.Array) {
159+
maybeAddImport(fq);
160+
return identifier;
161+
}
162+
if (type instanceof JavaType.Array) {
161163
JavaType.Array arrayType = (JavaType.Array) type;
162164
// Get the base element type
163165
JavaType elemType = arrayType.getElemType();

0 commit comments

Comments
 (0)