mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
IDEA-151717 Ignore equals method for @ParametersAreNonnullByDefault
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.Processors;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
@@ -252,22 +253,35 @@ public class AnnotationUtil {
|
||||
return map.get(annotationNames);
|
||||
}
|
||||
|
||||
private static void collectSuperParameters(@NotNull Set<PsiModifierListOwner> result, @NotNull PsiParameter parameter) {
|
||||
PsiElement scope = parameter.getDeclarationScope();
|
||||
if (!(scope instanceof PsiMethod)) {
|
||||
return;
|
||||
}
|
||||
PsiMethod method = (PsiMethod)scope;
|
||||
|
||||
private static void collectSuperParameters(@NotNull final Set<PsiModifierListOwner> result, @NotNull PsiParameter parameter) {
|
||||
PsiElement parent = parameter.getParent();
|
||||
if (!(parent instanceof PsiParameterList)) {
|
||||
return;
|
||||
}
|
||||
int index = ((PsiParameterList)parent).getParameterIndex(parameter);
|
||||
for (PsiMethod superMethod : getSuperAnnotationOwners(method)) {
|
||||
PsiParameter[] superParameters = superMethod.getParameterList().getParameters();
|
||||
if (index < superParameters.length) {
|
||||
result.add(superParameters[index]);
|
||||
final int index = ((PsiParameterList)parent).getParameterIndex(parameter);
|
||||
Consumer<PsiMethod> forEachSuperMethod = new Consumer<PsiMethod>() {
|
||||
@Override
|
||||
public void consume(PsiMethod method) {
|
||||
PsiParameter[] superParameters = method.getParameterList().getParameters();
|
||||
if (index < superParameters.length) {
|
||||
result.add(superParameters[index]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PsiElement scope = parent.getParent();
|
||||
if (scope instanceof PsiLambdaExpression) {
|
||||
PsiMethod method = LambdaUtil.getFunctionalInterfaceMethod(((PsiLambdaExpression)scope).getFunctionalInterfaceType());
|
||||
if (method != null) {
|
||||
forEachSuperMethod.consume(method);
|
||||
for (PsiMethod superMethod : getSuperAnnotationOwners(method)) {
|
||||
forEachSuperMethod.consume(superMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (scope instanceof PsiMethod) {
|
||||
for (PsiMethod superMethod : getSuperAnnotationOwners((PsiMethod)scope)) {
|
||||
forEachSuperMethod.consume(superMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ 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;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMExternalizableStringList;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -215,17 +212,37 @@ public abstract class NullableNotNullManager implements PersistentStateComponent
|
||||
if (type == null || TypeConversionUtil.isPrimitiveAndNotNull(type)) return null;
|
||||
|
||||
// even if javax.annotation.Nullable is not configured, it should still take precedence over ByDefault annotations
|
||||
if (AnnotationUtil.isAnnotated(owner, nullable ? Arrays.asList(DEFAULT_NOT_NULLS) : Arrays.asList(DEFAULT_NULLABLES), checkBases, false)) {
|
||||
if (AnnotationUtil.isAnnotated(owner, Arrays.asList(nullable ? DEFAULT_NOT_NULLS : DEFAULT_NULLABLES), checkBases, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!nullable && hasHardcodedContracts(owner)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (owner instanceof PsiParameter && !nullable && checkBases) {
|
||||
List<PsiParameter> superParameters = AnnotationUtil.getSuperAnnotationOwners((PsiParameter)owner);
|
||||
if (!superParameters.isEmpty()) {
|
||||
return takeAnnotationFromSuperParameters((PsiParameter)owner, superParameters);
|
||||
}
|
||||
}
|
||||
|
||||
return findNullabilityDefaultInHierarchy(owner, nullable);
|
||||
}
|
||||
|
||||
private PsiAnnotation takeAnnotationFromSuperParameters(@NotNull PsiParameter owner, final List<PsiParameter> superOwners) {
|
||||
return RecursionManager.doPreventingRecursion(owner, true, new Computable<PsiAnnotation>() {
|
||||
@Override
|
||||
public PsiAnnotation compute() {
|
||||
for (PsiParameter superOwner : superOwners) {
|
||||
PsiAnnotation anno = findNullabilityAnnotationWithDefault(superOwner, false, false);
|
||||
if (anno != null) return anno;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PsiAnnotation findPlainNullabilityAnnotation(@NotNull PsiModifierListOwner owner, boolean checkBases) {
|
||||
Set<String> qNames = ContainerUtil.newHashSet(getNullables());
|
||||
qNames.addAll(getNotNulls());
|
||||
|
||||
Reference in New Issue
Block a user