Search in sources :

Example 36 with GrModifierList

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.

the class GrStubUtils method isGroovyStaticMemberStub.

public static boolean isGroovyStaticMemberStub(StubElement<?> stub) {
    StubElement<?> modifierOwner = stub instanceof GrMethodStub ? stub : stub.getParentStub();
    StubElement<GrModifierList> type = modifierOwner.findChildStubByType(GroovyElementTypes.MODIFIERS);
    if (!(type instanceof GrModifierListStub)) {
        return false;
    }
    int mask = ((GrModifierListStub) type).getModifiersFlags();
    if (hasMaskModifier(mask, PsiModifier.PRIVATE)) {
        return false;
    }
    if (hasMaskModifier(mask, PsiModifier.STATIC)) {
        return true;
    }
    StubElement parent = modifierOwner.getParentStub();
    StubElement classStub = parent == null ? null : parent.getParentStub();
    if (classStub instanceof GrTypeDefinitionStub && (((GrTypeDefinitionStub) classStub).isAnnotationType() || ((GrTypeDefinitionStub) classStub).isInterface())) {
        return true;
    }
    return false;
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) StubElement(com.intellij.psi.stubs.StubElement)

Example 37 with GrModifierList

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.

the class GrAnnotationCollector method collectAliasedAnnotationsFromAnnotationCollectorAnnotations.

private static void collectAliasedAnnotationsFromAnnotationCollectorAnnotations(@NotNull PsiModifierList modifierList, @NotNull Map<String, Map<String, PsiNameValuePair>> annotations) {
    PsiElement parent = modifierList.getParent();
    if (parent instanceof PsiClass && GroovyCommonClassNames.GROOVY_TRANSFORM_COMPILE_DYNAMIC.equals(((PsiClass) parent).getQualifiedName())) {
        Map<String, PsiNameValuePair> params = ContainerUtil.newLinkedHashMap();
        annotations.put(GroovyCommonClassNames.GROOVY_TRANSFORM_COMPILE_STATIC, params);
        GrAnnotation annotation = GroovyPsiElementFactory.getInstance(modifierList.getProject()).createAnnotationFromText("@CompileStatic(TypeCheckingMode.SKIP)");
        params.put("value", annotation.getParameterList().getAttributes()[0]);
        return;
    }
    PsiAnnotation[] rawAnnotations = modifierList instanceof GrModifierList ? ((GrModifierList) modifierList).getRawAnnotations() : modifierList.getAnnotations();
    for (PsiAnnotation annotation : rawAnnotations) {
        final String qname = annotation.getQualifiedName();
        if (qname == null || qname.equals(GroovyCommonClassNames.GROOVY_TRANSFORM_ANNOTATION_COLLECTOR))
            continue;
        final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
        for (PsiNameValuePair pair : attributes) {
            Map<String, PsiNameValuePair> map = annotations.get(qname);
            if (map == null) {
                map = ContainerUtil.newLinkedHashMap();
                annotations.put(qname, map);
            }
            map.put(pair.getName() != null ? pair.getName() : "value", pair);
        }
        if (attributes.length == 0 && !annotations.containsKey(qname)) {
            annotations.put(qname, ContainerUtil.<String, PsiNameValuePair>newLinkedHashMap());
        }
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)

Example 38 with GrModifierList

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.

the class GroovyTreeGenerator method generateTreeFor.

@Override
public TreeElement generateTreeFor(@NotNull PsiElement original, @NotNull CharTable table, @NotNull PsiManager manager) {
    if (original instanceof GrModifierList) {
        final String text = original.getText();
        assert text != null : "Text is null for " + original + "; " + original.getClass();
        final GrModifierList modifierList = GroovyPsiElementFactory.getInstance(manager.getProject()).createModifierList(text);
        return (TreeElement) modifierList.getNode();
    }
    return null;
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 39 with GrModifierList

use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList in project intellij-community by JetBrains.

the class ModifierListGenerator method writeModifiers.

public static boolean writeModifiers(StringBuilder builder, PsiModifierList modifierList, String[] modifiers, boolean writeAnnotations) {
    boolean wasAddedModifiers = false;
    if (writeAnnotations && modifierList instanceof GrModifierList) {
        GrAnnotation[] annotations = ((GrModifierList) modifierList).getAnnotations();
        AnnotationGenerator annotationGenerator = new AnnotationGenerator(builder, new ExpressionContext(modifierList.getProject(), GroovyFile.EMPTY_ARRAY));
        wasAddedModifiers = annotations.length > 0;
        for (GrAnnotation annotation : annotations) {
            annotation.accept(annotationGenerator);
            builder.append(' ');
        }
    }
    for (String modifierType : modifiers) {
        if (modifierList.hasModifierProperty(modifierType)) {
            builder.append(modifierType);
            builder.append(' ');
            wasAddedModifiers = true;
        }
    }
    return wasAddedModifiers;
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)

Aggregations

GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)39 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)9 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)5 Annotation (com.intellij.lang.annotation.Annotation)4 PsiElement (com.intellij.psi.PsiElement)4 TextRange (com.intellij.openapi.util.TextRange)3 NotNull (org.jetbrains.annotations.NotNull)3 GrModifierFix (org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix)3 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)3 CandidateInfo (com.intellij.psi.infos.CandidateInfo)2 Matcher (java.util.regex.Matcher)2 Nullable (org.jetbrains.annotations.Nullable)2 GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)2 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)2 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)2 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)2 GrVariableDeclaration (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration)2 GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)2 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1