Search in sources :

Example 11 with GrMember

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.

the class PsiImplUtil method getQualifierType.

@Nullable
public static PsiType getQualifierType(@NotNull GrReferenceExpression ref) {
    final GrExpression rtQualifier = getRuntimeQualifier(ref);
    if (rtQualifier != null) {
        return rtQualifier.getType();
    }
    PsiClass containingClass = null;
    final GrMember member = PsiTreeUtil.getParentOfType(ref, GrMember.class);
    if (member == null) {
        final PsiFile file = ref.getContainingFile();
        if (file instanceof GroovyFileBase && ((GroovyFileBase) file).isScript()) {
            containingClass = ((GroovyFileBase) file).getScriptClass();
        } else {
            return null;
        }
    } else if (member instanceof GrMethod) {
        if (!member.hasModifierProperty(PsiModifier.STATIC)) {
            containingClass = member.getContainingClass();
        }
    }
    if (containingClass != null) {
        final PsiClassType categoryType = GdkMethodUtil.getCategoryType(containingClass);
        if (categoryType != null) {
            return categoryType;
        }
        return JavaPsiFacade.getElementFactory(ref.getProject()).createType(containingClass);
    }
    return null;
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with GrMember

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember 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)

Example 13 with GrMember

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.

the class GrRefactoringConflictsUtil method analyzeAccessibilityConflicts.

public static void analyzeAccessibilityConflicts(@NotNull Set<GrMember> membersToMove, @Nullable PsiClass targetClass, @NotNull MultiMap<PsiElement, String> conflicts, @Nullable String newVisibility, @NotNull PsiElement context, @Nullable Set<PsiMethod> abstractMethods) {
    if (VisibilityUtil.ESCALATE_VISIBILITY.equals(newVisibility)) {
        //Still need to check for access object
        newVisibility = PsiModifier.PUBLIC;
    }
    for (GrMember member : membersToMove) {
        checkUsedElements(member, member, membersToMove, abstractMethods, targetClass, context, conflicts);
        RefactoringConflictsUtil.checkAccessibilityConflicts(member, newVisibility, targetClass, membersToMove, conflicts);
    }
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)

Example 14 with GrMember

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.

the class GrPullUpConflictsUtil method checkSuperclassMembers.

private static void checkSuperclassMembers(PsiClass superClass, MemberInfoBase<? extends GrMember>[] infos, MultiMap<PsiElement, String> conflictsList) {
    for (MemberInfoBase<? extends GrMember> info : infos) {
        GrMember member = info.getMember();
        boolean isConflict = false;
        if (member instanceof PsiField) {
            String name = member.getName();
            isConflict = superClass.findFieldByName(name, false) != null;
        } else if (member instanceof PsiMethod) {
            PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, member.getContainingClass(), PsiSubstitutor.EMPTY);
            MethodSignature signature = ((PsiMethod) member).getSignature(superSubstitutor);
            final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(superClass, signature, false);
            isConflict = superClassMethod != null;
        }
        if (isConflict) {
            String message = RefactoringBundle.message("0.already.contains.a.1", RefactoringUIUtil.getDescription(superClass, false), RefactoringUIUtil.getDescription(member, false));
            message = CommonRefactoringUtil.capitalize(message);
            conflictsList.putValue(superClass, message);
        }
        if (member instanceof PsiMethod) {
            final PsiMethod method = (PsiMethod) member;
            final PsiModifierList modifierList = method.getModifierList();
            if (!modifierList.hasModifierProperty(PsiModifier.PRIVATE)) {
                for (PsiClass subClass : ClassInheritorsSearch.search(superClass)) {
                    if (method.getContainingClass() != subClass) {
                        MethodSignature signature = ((PsiMethod) member).getSignature(TypeConversionUtil.getSuperClassSubstitutor(superClass, subClass, PsiSubstitutor.EMPTY));
                        final PsiMethod wouldBeOverriden = MethodSignatureUtil.findMethodBySignature(subClass, signature, false);
                        if (wouldBeOverriden != null && VisibilityUtil.compare(VisibilityUtil.getVisibilityModifier(wouldBeOverriden.getModifierList()), VisibilityUtil.getVisibilityModifier(modifierList)) > 0) {
                            conflictsList.putValue(wouldBeOverriden, CommonRefactoringUtil.capitalize(RefactoringUIUtil.getDescription(method, true) + " in super class would clash with local method from " + RefactoringUIUtil.getDescription(subClass, true)));
                        }
                    }
                }
            }
        }
    }
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)

Example 15 with GrMember

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.

the class GrPullUpConflictsUtil method checkInterfaceTarget.

private static void checkInterfaceTarget(MemberInfoBase<? extends GrMember>[] infos, MultiMap<PsiElement, String> conflictsList) {
    for (MemberInfoBase<? extends GrMember> info : infos) {
        GrMember member = info.getMember();
        if (member instanceof PsiField || member instanceof PsiClass) {
            if (!member.hasModifierProperty(PsiModifier.STATIC) && !(member instanceof PsiClass && ((PsiClass) member).isInterface())) {
                String message = RefactoringBundle.message("0.is.not.static.it.cannot.be.moved.to.the.interface", RefactoringUIUtil.getDescription(member, false));
                message = CommonRefactoringUtil.capitalize(message);
                conflictsList.putValue(member, message);
            }
        }
        if (member instanceof PsiField && ((PsiField) member).getInitializer() == null) {
            String message = RefactoringBundle.message("0.is.not.initialized.in.declaration.such.fields.are.not.allowed.in.interfaces", RefactoringUIUtil.getDescription(member, false));
            conflictsList.putValue(member, CommonRefactoringUtil.capitalize(message));
        }
    }
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)

Aggregations

GrMember (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember)23 PsiElement (com.intellij.psi.PsiElement)7 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)6 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)5 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 Nullable (org.jetbrains.annotations.Nullable)4 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)4 NotNull (org.jetbrains.annotations.NotNull)3 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)3 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)3 Editor (com.intellij.openapi.editor.Editor)2 GrDocCommentOwner (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner)2 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)2 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)2 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)2 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)2 TargetElementUtil (com.intellij.codeInsight.TargetElementUtil)1 Language (com.intellij.lang.Language)1 InlineActionHandler (com.intellij.lang.refactoring.InlineActionHandler)1 AccessToken (com.intellij.openapi.application.AccessToken)1