IJ-CR-188329 [java-inspections] IDEA-377682 JSpecify. Nullable incompatibilities. Calls with generics

- delete unused filters
- simplify switch expression

GitOrigin-RevId: 994435ac31851461cbb2b51144b734dd7a0b2c34
This commit is contained in:
Mikhail Pyltsin
2026-01-19 17:27:06 +00:00
committed by intellij-monorepo-bot
parent 6c34dc653c
commit ccc1e2f2d7
2 changed files with 8 additions and 60 deletions
@@ -557,16 +557,14 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
context = JavaTypeNullabilityUtil.getNullabilityConflictInAssignment(expectedType, actualType,
REPORT_NOT_NULL_TO_NULLABLE_CONFLICTS_IN_ASSIGNMENTS);
JavaTypeNullabilityUtil.NullabilityConflict conflict = context.nullabilityConflict();
String messageKey;
switch (conflict) {
case UNKNOWN -> {
return false;
}
case NOT_NULL_TO_NULL -> messageKey = problem.notNullToNullProblem();
case NULL_TO_NOT_NULL -> messageKey = problem.nullToNotNullProblem();
case COMPLEX -> messageKey = problem.complexProblem();
default -> throw new IllegalStateException("Unexpected value: " + conflict);
}
String messageKey = switch (conflict) {
case UNKNOWN -> null;
case NOT_NULL_TO_NULL -> problem.notNullToNullProblem();
case NULL_TO_NOT_NULL -> problem.nullToNotNullProblem();
case COMPLEX -> problem.complexProblem();
};
if (messageKey == null) return false;
reportProblem(holder, errorElement, LocalQuickFix.EMPTY_ARRAY,
messageKey, new Object[]{""},
@@ -392,56 +392,6 @@ public class JSpecifyFilteredAnnotationTest extends LightJavaCodeInsightFixtureT
}
}
private static class CallWithParameterWithNestedGenericsFilter implements ErrorFilter {
@Override
public boolean filterActual(@NotNull PsiFile file,
@NotNull String strippedText,
int lineNumber,
int startLineOffset,
@NotNull String errorMessage) {
if (!errorMessage.contains("jspecify_nullness_mismatch")) return false;
PsiElement element = findElement(file, strippedText, lineNumber, startLineOffset);
PsiExpressionStatement statement = PsiTreeUtil.getParentOfType(element, PsiExpressionStatement.class, true);
if (statement == null) return false;
PsiExpression expression = statement.getExpression();
if (!(expression instanceof PsiCallExpression callExpression)) return false;
PsiMethod method = callExpression.resolveMethod();
if (method == null) return false;
return ContainerUtil.exists(method.getParameterList().getParameters(),
parameter -> parameter.getType() instanceof PsiClassType classType && classType.hasParameters());
}
@Override
public boolean filterExpected(@NotNull PsiElement psiElement, @NotNull String errorMessage) {
//filter only actual file
return false;
}
}
private static class VariableWithNestedGenericsFilter implements ErrorFilter {
@Override
public boolean filterActual(@NotNull PsiFile file,
@NotNull String strippedText,
int lineNumber,
int startLineOffset,
@NotNull String errorMessage) {
if (!errorMessage.contains("jspecify_nullness_mismatch")) return false;
PsiElement element = findElement(file, strippedText, lineNumber, startLineOffset);
PsiVariable variable = PsiTreeUtil.getParentOfType(element, PsiVariable.class, true);
if (variable == null) return false;
return variable.getType() instanceof PsiClassType classType && classType.hasParameters();
}
@Override
public boolean filterExpected(@NotNull PsiElement psiElement, @NotNull String errorMessage) {
//filter only actual file
return false;
}
}
private static class SkipIndividuallyFilter implements ErrorFilter {
private final Set<Pair<String, Integer>> places;
private final Set<Pair<String, Integer>> unusedPlaces;