mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-psi] Check not-nullity in TypeAnnotationProvider.Static.create
Should supersede EA-636157 - NPE: PsiImmediateClassType.isValid GitOrigin-RevId: a8fa43d196712d62c89ea72eda7725f61106034f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7e0483c0c7
commit
a7b011c256
@@ -3,6 +3,8 @@ package com.intellij.psi;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* An object that returns annotations for {@link PsiType}. Since computing type annotations might be computationally expensive sometimes,
|
||||
* this object is used to delay the calculation until annotations are really needed,
|
||||
@@ -41,7 +43,11 @@ public interface TypeAnnotationProvider {
|
||||
|
||||
@NotNull
|
||||
public static TypeAnnotationProvider create(PsiAnnotation @NotNull [] annotations) {
|
||||
return annotations.length == 0 ? EMPTY : new Static(annotations);
|
||||
if (annotations.length == 0) return EMPTY;
|
||||
for (PsiAnnotation annotation : annotations) {
|
||||
Objects.requireNonNull(annotation);
|
||||
}
|
||||
return new Static(annotations);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,12 +118,7 @@ public final class JavaClassSupersImpl extends JavaClassSupers {
|
||||
targetType = outer.substituteWithBoundsPromotion((PsiTypeParameter)paramCandidate);
|
||||
if (targetType != null && innerType.getAnnotations().length > 0) {
|
||||
PsiAnnotation[] typeAnnotations = targetType.getAnnotations();
|
||||
targetType = targetType.annotate(new TypeAnnotationProvider() {
|
||||
@Override
|
||||
public PsiAnnotation @NotNull [] getAnnotations() {
|
||||
return ArrayUtil.mergeArrays(innerType.getAnnotations(), typeAnnotations);
|
||||
}
|
||||
});
|
||||
targetType = targetType.annotate(() -> ArrayUtil.mergeArrays(innerType.getAnnotations(), typeAnnotations));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+8
-11
@@ -94,19 +94,16 @@ public class TypeAnnotationContainer {
|
||||
*/
|
||||
public TypeAnnotationProvider getProvider(PsiElement parent) {
|
||||
if (isEmpty()) return TypeAnnotationProvider.EMPTY;
|
||||
return new TypeAnnotationProvider() {
|
||||
@Override
|
||||
public PsiAnnotation @NotNull [] getAnnotations() {
|
||||
List<PsiAnnotation> result = new ArrayList<>();
|
||||
for (TypeAnnotationEntry entry : myList) {
|
||||
if (entry.myPath.length == 0) {
|
||||
PsiAnnotation anno = parent instanceof PsiCompiledElement ? new ClsTypeAnnotationImpl(parent, entry.myText) :
|
||||
JavaPsiFacade.getElementFactory(parent.getProject()).createAnnotationFromText(entry.myText, parent);
|
||||
result.add(anno);
|
||||
}
|
||||
return () -> {
|
||||
List<PsiAnnotation> result = new ArrayList<>();
|
||||
for (TypeAnnotationEntry entry : myList) {
|
||||
if (entry.myPath.length == 0) {
|
||||
PsiAnnotation anno = parent instanceof PsiCompiledElement ? new ClsTypeAnnotationImpl(parent, entry.myText) :
|
||||
JavaPsiFacade.getElementFactory(parent.getProject()).createAnnotationFromText(entry.myText, parent);
|
||||
result.add(anno);
|
||||
}
|
||||
return result.toArray(PsiAnnotation.EMPTY_ARRAY);
|
||||
}
|
||||
return result.toArray(PsiAnnotation.EMPTY_ARRAY);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user