Search in sources :

Example 16 with GrModifierList

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

the class GrParameterImpl method setType.

@Override
public void setType(@Nullable PsiType type) {
    final GrTypeElement typeElement = getTypeElementGroovy();
    if (type == null) {
        if (typeElement != null)
            typeElement.delete();
        return;
    }
    GrTypeElement newTypeElement;
    try {
        newTypeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(type);
    } catch (IncorrectOperationException e) {
        LOG.error(e);
        return;
    }
    if (typeElement == null) {
        final GrModifierList modifierList = getModifierList();
        newTypeElement = (GrTypeElement) addAfter(newTypeElement, modifierList);
    } else {
        newTypeElement = (GrTypeElement) typeElement.replace(newTypeElement);
    }
    JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(newTypeElement);
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 17 with GrModifierList

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

the class GrTypeParameterListImpl method appendParenthesesIfNeeded.

private void appendParenthesesIfNeeded() {
    PsiElement first = getFirstChild();
    if (first == null) {
        getNode().addLeaf(GroovyTokenTypes.mLT, "<", null);
    }
    PsiElement last = getLastChild();
    if (last.getNode().getElementType() != GroovyTokenTypes.mGT) {
        getNode().addLeaf(GroovyTokenTypes.mGT, ">", null);
    }
    PsiElement parent = getParent();
    if (parent instanceof GrMethod) {
        GrModifierList list = ((GrMethod) parent).getModifierList();
        PsiElement[] modifiers = list.getModifiers();
        if (modifiers.length == 0) {
            list.setModifierProperty(GrModifier.DEF, true);
        }
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) StubBasedPsiElement(com.intellij.psi.StubBasedPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 18 with GrModifierList

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

the class GrStubUtils method getAnnotationNames.

public static String[] getAnnotationNames(PsiModifierListOwner psi) {
    List<String> annoNames = ContainerUtil.newArrayList();
    final PsiModifierList modifierList = psi.getModifierList();
    if (modifierList instanceof GrModifierList) {
        for (GrAnnotation annotation : ((GrModifierList) modifierList).getRawAnnotations()) {
            final String name = annotation.getShortName();
            if (StringUtil.isNotEmpty(name)) {
                annoNames.add(name);
            }
        }
    }
    return ArrayUtil.toStringArray(annoNames);
}
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 19 with GrModifierList

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

the class CollectClassMembersUtil method processClass.

private static void processClass(@NotNull PsiClass aClass, @NotNull Map<String, CandidateInfo> allFields, @NotNull Map<String, List<CandidateInfo>> allMethods, @NotNull Map<String, CandidateInfo> allInnerClasses, @NotNull Set<PsiClass> visitedClasses, @NotNull PsiSubstitutor substitutor, boolean includeSynthetic) {
    PsiUtilCore.ensureValid(aClass);
    if (!visitedClasses.add(aClass))
        return;
    if (visitedClasses.size() == 1 || !GrTraitUtil.isTrait(aClass)) {
        for (PsiField field : getFields(aClass, includeSynthetic)) {
            String name = field.getName();
            if (!allFields.containsKey(name)) {
                allFields.put(name, new CandidateInfo(field, substitutor));
            } else if (hasExplicitVisibilityModifiers(field)) {
                final CandidateInfo candidateInfo = allFields.get(name);
                final PsiElement element = candidateInfo.getElement();
                if (element instanceof GrField) {
                    final GrModifierList modifierList = ((GrField) element).getModifierList();
                    if ((modifierList == null || !modifierList.hasExplicitVisibilityModifiers()) && aClass == ((GrField) element).getContainingClass()) {
                        //replace property-field with field with explicit visibilityModifier
                        allFields.put(name, new CandidateInfo(field, substitutor));
                    }
                }
            }
        }
    }
    for (PsiMethod method : getMethods(aClass, includeSynthetic)) {
        addMethod(allMethods, method, substitutor);
    }
    for (final PsiClass inner : getInnerClasses(aClass, includeSynthetic)) {
        final String name = inner.getName();
        if (name != null && !allInnerClasses.containsKey(name)) {
            allInnerClasses.put(name, new CandidateInfo(inner, substitutor));
        }
    }
    for (PsiClass superClass : getSupers(aClass, includeSynthetic)) {
        final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, substitutor);
        processClass(superClass, allFields, allMethods, allInnerClasses, visitedClasses, superSubstitutor, includeSynthetic);
    }
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) CandidateInfo(com.intellij.psi.infos.CandidateInfo)

Example 20 with GrModifierList

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

the class ResolveUtil method isScriptField.

public static boolean isScriptField(GrVariable var) {
    GrModifierList list = var.getModifierList();
    if (list == null)
        return false;
    PsiFile containingFile = var.getContainingFile();
    if (!(containingFile instanceof GroovyFile) || !((GroovyFile) containingFile).isScript())
        return false;
    GrMember member = PsiTreeUtil.getParentOfType(var, GrTypeDefinition.class, GrMethod.class);
    if (member != null)
        return false;
    for (GrAnnotation annotation : list.getAnnotations()) {
        String qualifiedName = annotation.getQualifiedName();
        if (qualifiedName == null)
            continue;
        if (qualifiedName.equals(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD))
            return true;
    }
    return false;
}
Also used : GrModifierList(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList) GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

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