Skip to content
Closed
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 @@ -99,12 +99,10 @@ private static boolean isLocalDateOrTime(Type type) {
private static ExpressionTree skipParenthesesAndCasts(ExpressionTree expression) {
ExpressionTree result = expression;
while (true) {
if (result instanceof ParenthesizedTree parenthesizedTree) {
result = parenthesizedTree.expression();
} else if (result instanceof TypeCastTree typeCastTree) {
result = typeCastTree.expression();
} else {
return result;
switch (result) {
case ParenthesizedTree parenthesizedTree -> result = parenthesizedTree.expression();
case TypeCastTree typeCastTree -> result = typeCastTree.expression();
default -> { return result; }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,20 @@ private JavaQuickFix computeQuickFix(List<Case> cases, IfStatementTree topLevelI
}

private void writeCase(Case caze, StringBuilder sb, int baseIndent, boolean canLiftReturn) {
if (caze instanceof PatternMatchCase patternMatchCase) {
sb.append("case ").append(QuickFixHelper.contentForTree(patternMatchCase.pattern, context));
if (!patternMatchCase.guards().isEmpty()) {
List<ExpressionTree> guards = patternMatchCase.guards();
sb.append(" when ");
join(guards, " && ", sb);
switch (caze) {
case PatternMatchCase patternMatchCase -> {
sb.append("case ").append(QuickFixHelper.contentForTree(patternMatchCase.pattern, context));
if (!patternMatchCase.guards().isEmpty()) {
List<ExpressionTree> guards = patternMatchCase.guards();
sb.append(" when ");
join(guards, " && ", sb);
}
}
} else if (caze instanceof EqualityCase equalityCase) {
sb.append("case ");
join(equalityCase.constants, ", ", sb);
} else {
sb.append("default");
case EqualityCase equalityCase -> {
sb.append("case ");
join(equalityCase.constants, ", ", sb);
}
case DefaultCase ignored -> sb.append("default");
}
sb.append(" -> ");
if (canLiftReturn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,13 @@ public void visitNode(Tree tree) {
}

private static boolean isNewAutocloseableOrBuilder(Tree tree, JavaFileScannerContext context) {
if (tree instanceof NewClassTree newClass) {
return newClass.symbolType().isSubtypeOf("java.lang.AutoCloseable");
} else if (tree instanceof MethodInvocationTree mit) {
return AUTOCLOSEABLE_FACTORY_MATCHER.matches(mit) ||
return switch (tree) {
case NewClassTree newClass -> newClass.symbolType().isSubtypeOf("java.lang.AutoCloseable");
case MethodInvocationTree mit -> AUTOCLOSEABLE_FACTORY_MATCHER.matches(mit) ||
(context.getJavaVersion().isJava21Compatible() && AUTOCLOSEABLE_JAVA21_MATCHER.matches(mit)) ||
(context.getJavaVersion().isJava26Compatible() && AUTOCLOSEABLE_JAVA26_MATCHER.matches(mit));
} else {
return false;
}
default -> false;
};
}

private static boolean isFollowedByTryWithFinally(Tree tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,11 @@ public static int countMatches(@Nullable String string, @Nullable String pattern
public static String[] flatten(Object ... args) {
List<String> result = new ArrayList<>();
for (Object arg : args) {
if (arg instanceof String s) {
result.add(s);
} else if (arg instanceof String[] arr) {
Collections.addAll(result, arr);
} else if (arg instanceof Collection<?> col) {
result.addAll((Collection<String>) col);
} else {
throw new IllegalArgumentException("Unsupported argument type: " + arg.getClass());
switch (arg) {
case String s -> result.add(s);
case String[] arr -> Collections.addAll(result, arr);
case Collection<?> col -> result.addAll((Collection<String>) col);
default -> throw new IllegalArgumentException("Unsupported argument type: " + arg.getClass());
}
}
return result.toArray(new String[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,12 @@ private static Symbol getEffectiveOwner(Symbol symbol, NullabilityLevel currentL
}

private static NullabilityLevel getLevel(Symbol symbol) {
if (symbol.isVariableSymbol()) {
return NullabilityLevel.VARIABLE;
} else if (symbol.isMethodSymbol()) {
return NullabilityLevel.METHOD;
} else if (symbol.isTypeSymbol()) {
return NullabilityLevel.CLASS;
} else if (symbol.isPackageSymbol()) {
return NullabilityLevel.PACKAGE;
}
return NullabilityLevel.UNKNOWN;
return switch (symbol) {
case Symbol.VariableSymbol v -> NullabilityLevel.VARIABLE;
case Symbol.MethodSymbol m -> NullabilityLevel.METHOD;
case Symbol.TypeSymbol t -> NullabilityLevel.CLASS;
default -> symbol.isPackageSymbol() ? NullabilityLevel.PACKAGE : NullabilityLevel.UNKNOWN;
};
}

@CheckForNull
Expand Down
Loading