Skip to content

Commit ea97e58

Browse files
committed
Address some static code analysis issues
1 parent 90ac5b3 commit ea97e58

13 files changed

+33
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ public J.Case visitCase(J.Case _case, J j) {
603603
return _case;
604604
}
605605

606-
this.visit(_case.getPattern(), compareTo.getPattern());
606+
this.visit(_case.getExpressions().get(0), compareTo.getExpressions().get(0));
607607
for (int i = 0; i < _case.getStatements().size(); i++) {
608608
this.visit(_case.getStatements().get(i), compareTo.getStatements().get(i));
609609
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public String getDescription() {
6767
}
6868

6969
@Override
70-
public Validated validate() {
71-
Validated v = super.validate();
70+
public Validated<Object> validate() {
71+
Validated<Object> v = super.validate();
7272
v = v.and(Validated.required("variantTypes", variantTypes));
7373
if (v.isValid()) {
7474
for (String variantType : variantTypes) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private boolean isDefaultCaseLastOrNotPresent(J.Switch switch_) {
186186
}
187187

188188
private boolean isDefaultCase(J.Case case_) {
189-
Expression elem = case_.getPattern();
189+
Expression elem = case_.getExpressions().get(0);
190190
return elem instanceof J.Identifier && ((J.Identifier) elem).getSimpleName().equals("default");
191191
}
192192

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public J.InstanceOf visitInstanceOf(J.InstanceOf instanceOf, ExecutionContext ct
181181
if (Boolean.TRUE.equals(operatorWrapStyle.getLiteralInstanceof())) {
182182
if (OperatorWrapStyle.WrapOption.NL == operatorWrapStyle.getWrapOption()) {
183183
if (i.getClazz().getPrefix().getWhitespace().contains("\n")) {
184-
i = i.getPadding().withExpr(
184+
i = i.getPadding().withExpression(
185185
i.getPadding().getExpression().withAfter(
186186
i.getClazz().getPrefix()
187187
)
@@ -198,7 +198,7 @@ public J.InstanceOf visitInstanceOf(J.InstanceOf instanceOf, ExecutionContext ct
198198
i.getPadding().getExpression().getAfter()
199199
)
200200
);
201-
i = i.getPadding().withExpr(
201+
i = i.getPadding().withExpression(
202202
i.getPadding().getExpression().withAfter(
203203
i.getPadding().getExpression().getAfter().withWhitespace(" ")
204204
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private static J.MethodInvocation asEqualsMethodInvocation(J.Binary binary, Java
8181
JavaType.Primitive.Boolean,
8282
singletonList("o"),
8383
singletonList(TYPE_OBJECT),
84-
null, null, null
84+
null, null, null, null
8585
)
8686
);
8787
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.time.Duration;
3535
import java.util.*;
3636
import java.util.concurrent.atomic.AtomicBoolean;
37-
import java.util.stream.Collectors;
3837

3938
@Value
4039
@EqualsAndHashCode(callSuper = false)
@@ -235,7 +234,7 @@ public J visitStatement(Statement s, ExecutionContext ctx) {
235234
if (s == statement) {
236235
Space prefix = s.getPrefix();
237236
// If we have at least one comment and there is no newline
238-
if (prefix.getComments().size() > 0 && !prefix.getWhitespace().contains("\n")) {
237+
if (!prefix.getComments().isEmpty() && !prefix.getWhitespace().contains("\n")) {
239238
return s.withPrefix(prefix
240239
// Copy suffix to prefix
241240
.withWhitespace(prefix.getComments().get(0).getSuffix())
@@ -254,7 +253,7 @@ public J visitClassDeclaration(J.ClassDeclaration c, ExecutionContext ctx) {
254253
if (statement == null && c == classDeclaration) {
255254
Space end = c.getBody().getEnd();
256255
// If we have at least one comment and there is no newline
257-
if (end.getComments().size() > 0 && !end.getWhitespace().contains("\n")) {
256+
if (!end.getComments().isEmpty() && !end.getWhitespace().contains("\n")) {
258257
return c.withBody(c.getBody().withEnd(end
259258
.withWhitespace(end.getComments().get(0).getSuffix())
260259
.withComments(end.getComments().subList(1, end.getComments().size()))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) {
8787
} while (combined != b);
8888

8989
if (b != block) {
90-
b = (J.Block) new UnnecessaryParenthesesVisitor()
90+
b = (J.Block) new UnnecessaryParenthesesVisitor<>()
9191
.visitNonNull(b, ctx, getCursor().getParentOrThrow());
9292
}
9393

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public String getDescription() {
4848
@Override
4949
public TreeVisitor<?, ExecutionContext> getVisitor() {
5050
return Preconditions.check(new UsesMethod<>(COLLECTORS_TO_SET_METHOD_MATCHER), new JavaIsoVisitor<ExecutionContext>() {
51-
private JavaTemplate template = JavaTemplate.builder("Collectors.toCollection(LinkedHashSet::new)")
51+
private final JavaTemplate template = JavaTemplate.builder("Collectors.toCollection(LinkedHashSet::new)")
5252
.imports("java.util.stream.Collectors", "java.util.LinkedHashSet")
5353
.build();
5454

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private J.MethodInvocation asEqualsMethodInvocation(J.Binary binary) {
9595
JavaType.Primitive.Boolean,
9696
singletonList("o"),
9797
singletonList(JavaType.buildType("java.lang.Object")),
98-
null, null, null
98+
null, null, null, null
9999
)
100100
);
101101
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ private J.Case toDefault(final J.Ternary ternary) {
261261
randomId(),
262262
Space.EMPTY,
263263
Markers.EMPTY,
264+
Collections.emptyList(),
264265
"default",
265266
null,
266267
null

0 commit comments

Comments
 (0)