[java] IDEA-379795 Add hasAnnotations() to PsiAnnotationOwner, PsiModifierListOwner and TypeAnnotationProvider

GitOrigin-RevId: dbe2d9508f45fb5bbbff26c1ba81792f5120c690
This commit is contained in:
Tagir Valeev
2025-09-26 11:09:02 +00:00
committed by intellij-monorepo-bot
parent ecfabbcaed
commit ac74ac484e
33 changed files with 105 additions and 41 deletions
@@ -112,7 +112,7 @@ public final class JavaClassSupersImpl extends JavaClassSupers {
PsiType targetType;
if (paramCandidate instanceof PsiTypeParameter && paramCandidate != parameter) {
targetType = outer.substituteWithBoundsPromotion((PsiTypeParameter)paramCandidate);
if (targetType != null && innerType.getAnnotations().length > 0) {
if (targetType != null && innerType.hasAnnotations()) {
PsiAnnotation[] typeAnnotations = targetType.getAnnotations();
targetType = targetType.annotate(() -> ArrayUtil.mergeArrays(innerType.getAnnotations(), typeAnnotations));
}
@@ -52,6 +52,11 @@ public class ClsModifierListImpl extends ClsRepositoryPsiElement<PsiModifierList
public PsiAnnotation @NotNull [] getAnnotations() {
return getStub().getChildrenByType(JavaStubElementTypes.ANNOTATION, PsiAnnotation.ARRAY_FACTORY);
}
@Override
public boolean hasAnnotations() {
return getStub().findChildStubByElementType(JavaStubElementTypes.ANNOTATION) != null;
}
@Override
public PsiAnnotation @NotNull [] getApplicableAnnotations() {
@@ -86,6 +86,20 @@ public class PsiClassReferenceType extends PsiClassType.Stub {
return getAnnotations(true);
}
@Override
public boolean hasAnnotations() {
if (super.hasAnnotations()) return true;
PsiJavaCodeReferenceElement reference = myReference.retrieveReference();
if (reference != null && reference.isValid() && reference.isQualified()) {
for (PsiElement child = reference.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof PsiAnnotation) {
return true;
}
}
}
return false;
}
private PsiAnnotation[] getAnnotations(boolean merge) {
PsiAnnotation[] annotations = super.getAnnotations();
@@ -306,6 +306,12 @@ public class PsiModifierListImpl extends JavaStubPsiElement<PsiModifierListStub>
List<PsiAnnotation> ext = PsiAugmentProvider.collectAugments(this, PsiAnnotation.class, null);
return ArrayUtil.mergeArrayAndCollection(own, ext, PsiAnnotation.ARRAY_FACTORY);
}
@Override
public boolean hasAnnotations() {
return getStubOrPsiChild(JavaStubElementTypes.ANNOTATION) != null ||
!PsiAugmentProvider.collectAugments(this, PsiAnnotation.class, null).isEmpty();
}
@Override
public PsiAnnotation @NotNull [] getApplicableAnnotations() {
@@ -404,6 +404,11 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl
return getType().getAnnotations();
}
@Override
public boolean hasAnnotations() {
return getType().hasAnnotations();
}
@Override
public PsiAnnotation @NotNull [] getApplicableAnnotations() {
return getAnnotations();