mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dfa: annotation inference suppression is different from honoring package-level defaults, so split them
This commit is contained in:
+2
-6
@@ -82,24 +82,20 @@ public class InferredAnnotationsManagerImpl extends InferredAnnotationsManager {
|
||||
if (owner instanceof PsiMethod && PsiUtil.canBeOverriden((PsiMethod)owner)) {
|
||||
return true;
|
||||
}
|
||||
if (ORG_JETBRAINS_ANNOTATIONS_CONTRACT.equals(annotationFQN) && hasHardcodedContracts(owner)) {
|
||||
if (ORG_JETBRAINS_ANNOTATIONS_CONTRACT.equals(annotationFQN) && HardcodedContracts.hasHardcodedContracts(owner)) {
|
||||
return true;
|
||||
}
|
||||
if (AnnotationUtil.NOT_NULL.equals(annotationFQN) && owner instanceof PsiParameter && owner.getParent() != null) {
|
||||
if (AnnotationUtil.isAnnotated(owner, NullableNotNullManager.getInstance(owner.getProject()).getNullables(), false, false)) {
|
||||
return true;
|
||||
}
|
||||
if (hasHardcodedContracts(owner.getParent().getParent())) {
|
||||
if (HardcodedContracts.hasHardcodedContracts(owner)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean hasHardcodedContracts(PsiElement owner) {
|
||||
return owner instanceof PsiMethod && !HardcodedContracts.getHardcodedContracts((PsiMethod)owner, null).isEmpty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiAnnotation getInferredContractAnnotation(PsiMethod method) {
|
||||
if (method.getModifierList().findAnnotation(ORG_JETBRAINS_ANNOTATIONS_CONTRACT) != null) {
|
||||
|
||||
+12
@@ -164,4 +164,16 @@ public class HardcodedContracts {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean hasHardcodedContracts(@Nullable PsiElement element) {
|
||||
if (element instanceof PsiMethod) {
|
||||
return !getHardcodedContracts((PsiMethod)element, null).isEmpty();
|
||||
}
|
||||
|
||||
if (element instanceof PsiParameter) {
|
||||
return hasHardcodedContracts(element.getParent().getParent());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -15,13 +15,19 @@
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInspection.dataFlow.HardcodedContracts;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
@State(
|
||||
name = "NullableNotNullManager",
|
||||
storages = {@Storage(file = StoragePathMacros.PROJECT_FILE)}
|
||||
)
|
||||
public class NullableNotNullManagerImpl extends NullableNotNullManager {
|
||||
protected boolean hasHardcodedContracts(PsiElement element) {
|
||||
return HardcodedContracts.hasHardcodedContracts(element);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,9 +53,6 @@ public abstract class InferredAnnotationsManager {
|
||||
*
|
||||
* {@link Contract} and {@link NotNull} annotations on methods are not necessarily applicable to the overridden implementations, so they're ignored, too.<p/>
|
||||
*
|
||||
* In addition, package-default annotations like @ParametersAreNonnullByDefault are not honored for parameters where
|
||||
* {@link NotNull} inference is ignored.
|
||||
*
|
||||
* @return whether inference is to be suppressed the given annotation on the given method or parameter
|
||||
*/
|
||||
public abstract boolean ignoreInference(@NotNull PsiModifierListOwner owner, @Nullable String annotationFQN);
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.*;
|
||||
* User: anna
|
||||
* Date: 1/25/11
|
||||
*/
|
||||
public class NullableNotNullManager implements PersistentStateComponent<Element> {
|
||||
public abstract class NullableNotNullManager implements PersistentStateComponent<Element> {
|
||||
private static final Logger LOG = Logger.getInstance("#" + NullableNotNullManager.class.getName());
|
||||
|
||||
public String myDefaultNullable = AnnotationUtil.NULLABLE;
|
||||
@@ -184,14 +184,16 @@ public class NullableNotNullManager implements PersistentStateComponent<Element>
|
||||
if (AnnotationUtil.isAnnotated(owner, nullable ? Arrays.asList(DEFAULT_NOT_NULLS) : Arrays.asList(DEFAULT_NULLABLES), checkBases, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!nullable && InferredAnnotationsManager.getInstance(owner.getProject()).ignoreInference(owner, AnnotationUtil.NOT_NULL)) {
|
||||
|
||||
if (!nullable && hasHardcodedContracts(owner)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return findNullabilityDefaultInHierarchy(owner, nullable);
|
||||
}
|
||||
|
||||
protected abstract boolean hasHardcodedContracts(PsiElement element);
|
||||
|
||||
@Nullable
|
||||
private static PsiType getOwnerType(PsiModifierListOwner owner) {
|
||||
if (owner instanceof PsiVariable) return ((PsiVariable)owner).getType();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import foo.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Some {
|
||||
void foo(@NotNull String s) {
|
||||
@@ -18,6 +19,16 @@ class Some {
|
||||
@bar.MethodsAreNotNullByDefault
|
||||
class NotNullClass {
|
||||
static native Object foo(String s);
|
||||
|
||||
public Object foo() {
|
||||
return <warning descr="'null' is returned by the method declared as @NotNull">null</warning>;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object foo2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
class NullableClass {
|
||||
|
||||
Reference in New Issue
Block a user