[java-inspections] Report TYPE_USE nullability annotation on classes

GitOrigin-RevId: f5c6113ccd1738d72b0f58fe13a8352a043431c9
This commit is contained in:
Tagir Valeev
2024-10-09 09:47:33 +02:00
committed by intellij-monorepo-bot
parent 8f2fe94325
commit 676c19bc1f
4 changed files with 13 additions and 0 deletions

View File

@@ -265,6 +265,7 @@ inspection.nullable.problems.primitive.type.annotation=Primitive type members ca
inspection.nullable.problems.receiver.annotation=Receiver parameter is inherently not-null
inspection.nullable.problems.applied.to.package=Annotation on fully-qualified name must be placed before the last component
inspection.nullable.problems.outer.type=Outer type is inherently not-null
inspection.nullable.problems.at.class=Nullability annotation is not applicable to classes
inspection.nullable.problems.at.constructor=Nullability annotation is not applicable to constructors
inspection.nullable.problems.at.enum.constant=Nullability annotation is not applicable to enum constants
inspection.nullable.problems.at.wildcard=Nullability annotation is not applicable to wildcard type

View File

@@ -215,6 +215,9 @@ public class NullableStuffInspectionBase extends AbstractBaseJavaLocalInspection
if (listOwner instanceof PsiMethod method && method.isConstructor()) {
reportIncorrectLocation(holder, annotation, listOwner, "inspection.nullable.problems.at.constructor");
}
if (listOwner instanceof PsiClass && AnnotationTargetUtil.findAnnotationTarget(annotation, PsiAnnotation.TargetType.TYPE) == null) {
reportIncorrectLocation(holder, annotation, listOwner, "inspection.nullable.problems.at.class");
}
if (listOwner instanceof PsiEnumConstant) {
reportIncorrectLocation(holder, annotation, listOwner, "inspection.nullable.problems.at.enum.constant");
}

View File

@@ -0,0 +1,5 @@
import org.jetbrains.annotations.NotNull;
<warning descr="Nullability annotation is not applicable to classes">@NotNull</warning>
public class DisableOnClass {
}

View File

@@ -422,6 +422,10 @@ public class NullableStuffInspectionTest extends LightJavaCodeInsightFixtureTest
doTest();
}
public void testDisableOnClass() {
doTest();
}
public void testParameterUnderDefaultNotNull() {
DataFlowInspectionTestCase.addJetBrainsNotNullByDefault(myFixture);
doTest();