mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
InferredAnnotationsManagerImpl: hardcoded not-nullness of collection factory methods
(there are too many overloads, so adding them into annotations.xml is impractical)
This commit is contained in:
+31
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -58,15 +58,19 @@ public class InferredAnnotationsManagerImpl extends InferredAnnotationsManager {
|
||||
return fromBytecode;
|
||||
}
|
||||
|
||||
if (listOwner instanceof PsiMethodImpl) {
|
||||
if (ORG_JETBRAINS_ANNOTATIONS_CONTRACT.equals(annotationFQN)) {
|
||||
return getInferredContractAnnotation((PsiMethodImpl)listOwner);
|
||||
if ((AnnotationUtil.NOT_NULL.equals(annotationFQN) || AnnotationUtil.NULLABLE.equals(annotationFQN))) {
|
||||
PsiAnnotation anno = null;
|
||||
if (listOwner instanceof PsiMethodImpl) {
|
||||
anno = getInferredNullityAnnotation((PsiMethodImpl)listOwner);
|
||||
}
|
||||
if (listOwner instanceof PsiParameter) {
|
||||
anno = getInferredNullityAnnotation((PsiParameter)listOwner);
|
||||
}
|
||||
return anno == null ? null : annotationFQN.equals(anno.getQualifiedName()) ? anno : null;
|
||||
}
|
||||
|
||||
if ((AnnotationUtil.NOT_NULL.equals(annotationFQN) || AnnotationUtil.NULLABLE.equals(annotationFQN))) {
|
||||
PsiAnnotation anno = getInferredNullityAnnotation((PsiMethodImpl)listOwner);
|
||||
return anno == null ? null : annotationFQN.equals(anno.getQualifiedName()) ? anno : null;
|
||||
}
|
||||
if (listOwner instanceof PsiMethodImpl && ORG_JETBRAINS_ANNOTATIONS_CONTRACT.equals(annotationFQN)) {
|
||||
return getInferredContractAnnotation((PsiMethodImpl)listOwner);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -128,6 +132,25 @@ public class InferredAnnotationsManagerImpl extends InferredAnnotationsManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
private PsiAnnotation getInferredNullityAnnotation(PsiParameter parameter) {
|
||||
PsiElement scope = parameter.getDeclarationScope();
|
||||
if (scope instanceof PsiMethod) {
|
||||
PsiMethod method = (PsiMethod)scope;
|
||||
if (method.getName().equals("of")) {
|
||||
PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
String className = containingClass.getQualifiedName();
|
||||
if (CommonClassNames.JAVA_UTIL_LIST.equals(className) ||
|
||||
CommonClassNames.JAVA_UTIL_SET.equals(className) ||
|
||||
CommonClassNames.JAVA_UTIL_MAP.equals(className)) {
|
||||
return ProjectBytecodeAnalysis.getInstance(myProject).getNotNullAnnotation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiAnnotation createContractAnnotation(List<MethodContract> contracts, boolean pure) {
|
||||
return createContractAnnotation(myProject, pure, StringUtil.join(contracts, "; "));
|
||||
|
||||
Reference in New Issue
Block a user