mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
dfa: inspect enum constant methods (IDEA-142299)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package foo;
|
||||
|
||||
import javax.annotation.*;
|
||||
|
||||
enum TestNonnull {
|
||||
TEST {
|
||||
@Nonnull
|
||||
@Override
|
||||
public Object testWithAnnotation(@Nonnull Object aObject) {
|
||||
if (<warning descr="Condition 'aObject == null' is always 'false'">aObject == null</warning>) {
|
||||
return new Object();
|
||||
}
|
||||
return <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object testWithoutAnnotation(Object aObject) {
|
||||
return <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
|
||||
}
|
||||
};
|
||||
|
||||
public boolean testParameter(TestNonnull aTest) {
|
||||
if (<warning descr="Condition 'aTest == null' is always 'false'">aTest == null</warning>) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object testReturn() {
|
||||
return <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public abstract Object testWithAnnotation(@Nonnull Object aObject);
|
||||
|
||||
public abstract Object testWithoutAnnotation(Object aObject);
|
||||
}
|
||||
@@ -336,6 +336,21 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testCustomDefaultInEnums() {
|
||||
DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture);
|
||||
myFixture.addClass("package foo;" +
|
||||
"import static java.lang.annotation.ElementType.*;" +
|
||||
"@javax.annotation.meta.TypeQualifierDefault({PARAMETER, FIELD, METHOD, LOCAL_VARIABLE}) " +
|
||||
"@javax.annotation.Nonnull " +
|
||||
"public @interface NonnullByDefault {}");
|
||||
|
||||
myFixture.addFileToProject("foo/package-info.java", "@NonnullByDefault package foo;");
|
||||
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + ".java", "foo/Classes.java"));
|
||||
myFixture.enableInspections(new DataFlowInspection());
|
||||
myFixture.checkHighlighting(true, false, true);
|
||||
}
|
||||
|
||||
public void testTrueOrEqualsSomething() {
|
||||
doTest();
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Remove redundant assignment"));
|
||||
|
||||
Reference in New Issue
Block a user