Search in sources :

Example 1 with PsiAnnotationStub

use of com.intellij.psi.impl.java.stubs.PsiAnnotationStub in project intellij-community by JetBrains.

the class TypeInfo method applyAnnotations.

@NotNull
public TypeInfo applyAnnotations(@NotNull StubBase<?> owner) {
    PsiModifierListStub modifierList = (PsiModifierListStub) owner.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
    if (modifierList == null)
        return this;
    List<PsiAnnotationStub> annotationStubs = null;
    for (StubElement child : modifierList.getChildrenStubs()) {
        if (!(child instanceof PsiAnnotationStub))
            continue;
        PsiAnnotationStub annotationStub = (PsiAnnotationStub) child;
        if (PsiImplUtil.isTypeAnnotation(annotationStub.getPsiElement())) {
            if (annotationStubs == null)
                annotationStubs = new SmartList<>();
            annotationStubs.add(annotationStub);
        }
    }
    PsiAnnotationStub[] stubArray = PsiAnnotationStub.EMPTY_ARRAY;
    if (annotationStubs != null)
        stubArray = annotationStubs.toArray(new PsiAnnotationStub[annotationStubs.size()]);
    return new TypeInfo(text, arrayCount, isEllipsis, stubArray);
}
Also used : PsiAnnotationStub(com.intellij.psi.impl.java.stubs.PsiAnnotationStub) PsiModifierListStub(com.intellij.psi.impl.java.stubs.PsiModifierListStub) StubElement(com.intellij.psi.stubs.StubElement) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PsiAnnotationStub

use of com.intellij.psi.impl.java.stubs.PsiAnnotationStub in project intellij-community by JetBrains.

the class TypeInfo method createTypeText.

@Nullable
public static String createTypeText(@NotNull TypeInfo typeInfo) {
    if (typeInfo == NULL || typeInfo.text == null) {
        return null;
    }
    if (typeInfo.arrayCount == 0 && typeInfo.myAnnotationStubs.length == 0) {
        return typeInfo.text;
    }
    StringBuilder buf = new StringBuilder();
    for (PsiAnnotationStub stub : typeInfo.myAnnotationStubs) {
        buf.append(stub.getText()).append(' ');
    }
    buf.append(typeInfo.text);
    int arrayCount = typeInfo.isEllipsis ? typeInfo.arrayCount - 1 : typeInfo.arrayCount;
    for (int i = 0; i < arrayCount; i++) {
        buf.append("[]");
    }
    if (typeInfo.isEllipsis) {
        buf.append("...");
    }
    return internFrequentType(buf.toString());
}
Also used : PsiAnnotationStub(com.intellij.psi.impl.java.stubs.PsiAnnotationStub) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiAnnotationStub (com.intellij.psi.impl.java.stubs.PsiAnnotationStub)2 PsiModifierListStub (com.intellij.psi.impl.java.stubs.PsiModifierListStub)1 StubElement (com.intellij.psi.stubs.StubElement)1 SmartList (com.intellij.util.SmartList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1