parameter nullity annotation should have higher-priority than package-level ones

This commit is contained in:
peter
2014-02-10 18:34:10 +01:00
parent 4757fc901f
commit 750013c064
3 changed files with 33 additions and 7 deletions
@@ -15,7 +15,8 @@
*/
package com.intellij.codeInsight;
import com.intellij.openapi.components.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
@@ -28,10 +29,7 @@ import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;
/**
* User: anna
@@ -130,7 +128,9 @@ public class NullableNotNullManager implements PersistentStateComponent<Element>
return true;
}
return owner instanceof PsiParameter && isContainerAnnotated(owner, "javax.annotation.ParametersAreNullableByDefault");
return owner instanceof PsiParameter &&
!AnnotationUtil.isAnnotated(owner, Arrays.asList(DEFAULT_NOT_NULLS), checkBases, false) && //honor annotation even if it's not configured
isContainerAnnotated(owner, "javax.annotation.ParametersAreNullableByDefault");
}
public boolean isNotNull(PsiModifierListOwner owner, boolean checkBases) {
@@ -138,7 +138,9 @@ public class NullableNotNullManager implements PersistentStateComponent<Element>
return true;
}
return owner instanceof PsiParameter && isContainerAnnotated(owner, "javax.annotation.ParametersAreNonnullByDefault");
return owner instanceof PsiParameter &&
!AnnotationUtil.isAnnotated(owner, Arrays.asList(DEFAULT_NULLABLES), checkBases, false) && //honor annotation even if it's not configured
isContainerAnnotated(owner, "javax.annotation.ParametersAreNonnullByDefault");
}
private static boolean isContainerAnnotated(PsiModifierListOwner owner, String annotationFQN) {
@@ -0,0 +1,12 @@
import foo.*;
class B {
{
new NullableFunction() {
public void fun(Object o) {}
};
new AnyFunction() {
public void fun(Object <warning descr="Not annotated parameter overrides @NotNull parameter">o</warning>) {}
};
}
}
@@ -37,4 +37,16 @@ public class NullableStuffInspectionTest extends LightCodeInsightFixtureTestCase
doTest();
}
public void testParametersAreNonnullByDefault() {
myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}");
myFixture.addClass("package javax.annotation; public @interface Nullable {}");
myFixture.addFileToProject("foo/package-info.java", "@javax.annotation.ParametersAreNonnullByDefault package foo;");
myFixture.addClass("import javax.annotation.*; package foo; public interface NullableFunction { void fun(@Nullable Object o); }");
myFixture.addClass("package foo; public interface AnyFunction { void fun(Object o); }");
myInspection.REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS = true;
doTest();
}
}