Java: Unused Declaration - recognize operator assignment as read access (IDEA-330149)

GitOrigin-RevId: 5561bd503c9f7bfe0fc5e6eca209d0f272ed50ec
This commit is contained in:
Bas Leijdekkers
2023-11-10 14:43:25 +01:00
committed by intellij-monorepo-bot
parent 9ca17ef673
commit 6631881072
4 changed files with 33 additions and 15 deletions

View File

@@ -645,19 +645,14 @@ public class RefJavaUtilImpl extends RefJavaUtil {
return Integer.compare(getAccessNumber(a1), getAccessNumber(a2));
}
private static int getAccessNumber(String a) {
if (PsiModifier.PRIVATE.equals(a)) {
return 0;
}
if (PsiModifier.PACKAGE_LOCAL.equals(a)) {
return 1;
}
if (PsiModifier.PROTECTED.equals(a)) {
return 2;
}
if (PsiModifier.PUBLIC.equals(a)) return 3;
return -1;
private static int getAccessNumber(String modifier) {
return switch (modifier) {
case PsiModifier.PRIVATE -> 0;
case PsiModifier.PACKAGE_LOCAL -> 1;
case PsiModifier.PROTECTED -> 2;
case PsiModifier.PUBLIC -> 3;
default -> -1;
};
}
@Override
@@ -723,7 +718,7 @@ public class RefJavaUtilImpl extends RefJavaUtil {
private static boolean isAccessedForReading(@NotNull UElement expression) {
UElement parent = skipParentheses(expression);
return !(parent instanceof UBinaryExpression binaryExpression) ||
!(binaryExpression.getOperator() instanceof UastBinaryOperator.AssignOperator) ||
binaryExpression.getOperator() != UastBinaryOperator.ASSIGN ||
UastUtils.isUastChildOf(binaryExpression.getRightOperand(), expression, false);
}