Search in sources :

Example 16 with GrMember

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

the class GrPullUpHandler method invokeImpl.

private void invokeImpl(Project project, DataContext dataContext, GrTypeDefinition aClass, PsiElement aMember) {
    final Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null;
    if (aClass == null) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", REFACTORING_NAME));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
        return;
    }
    ArrayList<PsiClass> bases = RefactoringHierarchyUtil.createBasesList(aClass, false, true);
    if (bases.isEmpty()) {
        final GrTypeDefinition containingClass = DefaultGroovyMethods.asType(aClass.getContainingClass(), GrTypeDefinition.class);
        if (containingClass != null) {
            invokeImpl(project, dataContext, containingClass, aClass);
            return;
        }
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("class.does.not.have.base.classes.interfaces.in.current.project", aClass.getQualifiedName()));
        CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
        return;
    }
    mySubclass = aClass;
    GrMemberInfoStorage memberInfoStorage = new GrMemberInfoStorage((GrTypeDefinition) mySubclass, new MemberInfoBase.Filter<GrMember>() {

        @Override
        public boolean includeMember(GrMember element) {
            return true;
        }
    });
    List<GrMemberInfo> members = memberInfoStorage.getClassMemberInfos(mySubclass);
    PsiManager manager = mySubclass.getManager();
    for (GrMemberInfo member : members) {
        if (manager.areElementsEquivalent(member.getMember(), aMember)) {
            member.setChecked(true);
            break;
        }
    }
    final GrPullUpDialog dialog = new GrPullUpDialog(project, aClass, bases, memberInfoStorage, this);
    dialog.show();
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrMemberInfo(org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfo) MemberInfoBase(com.intellij.refactoring.classMembers.MemberInfoBase) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GrMemberInfoStorage(org.jetbrains.plugins.groovy.refactoring.classMembers.GrMemberInfoStorage) Editor(com.intellij.openapi.editor.Editor)

Example 17 with GrMember

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

the class ReachingDefinitionsCollector method filterNonlocals.

private static VariableInfo[] filterNonlocals(Map<String, VariableInfo> infos, GrStatement place) {
    List<VariableInfo> result = new ArrayList<>();
    for (Iterator<VariableInfo> iterator = infos.values().iterator(); iterator.hasNext(); ) {
        VariableInfo info = iterator.next();
        String name = info.getName();
        GroovyPsiElement property = ResolveUtil.resolveProperty(place, name);
        if (property instanceof GrVariable) {
            iterator.remove();
        } else if (property instanceof GrReferenceExpression) {
            GrMember member = PsiTreeUtil.getParentOfType(property, GrMember.class);
            if (member == null) {
                continue;
            } else if (!member.hasModifierProperty(PsiModifier.STATIC)) {
                if (member.getContainingClass() instanceof GroovyScriptClass) {
                    //binding variable
                    continue;
                }
            }
        }
        if (ResolveUtil.resolveClass(place, name) == null) {
            result.add(info);
        }
    }
    return result.toArray(new VariableInfo[result.size()]);
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 18 with GrMember

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

the class GrDocCommentUtil method findDocOwner.

@Nullable
public static GrDocCommentOwner findDocOwner(GroovyDocPsiElement docElement) {
    PsiElement element = docElement;
    while (element != null && element.getParent() instanceof GroovyDocPsiElement) element = element.getParent();
    if (element == null)
        return null;
    element = skipWhiteSpacesAndStopOnDoc(element, true);
    if (element instanceof GrDocCommentOwner)
        return (GrDocCommentOwner) element;
    if (element instanceof GrMembersDeclaration) {
        GrMember[] members = ((GrMembersDeclaration) element).getMembers();
        if (members.length > 0 && members[0] instanceof GrDocCommentOwner) {
            return (GrDocCommentOwner) members[0];
        }
    }
    return null;
}
Also used : GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrMembersDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration) GrDocCommentOwner(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner) PsiElement(com.intellij.psi.PsiElement) GroovyDocPsiElement(org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GroovyDocPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 19 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 processCategoryMembers.

public static boolean processCategoryMembers(@NotNull PsiElement place, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
    boolean inCodeBlock = true;
    PsiElement run = place;
    PsiElement lastParent = null;
    while (run != null) {
        ProgressManager.checkCanceled();
        if (run instanceof GrMember) {
            inCodeBlock = false;
        }
        if (run instanceof GrClosableBlock) {
            if (inCodeBlock) {
                if (!GdkMethodUtil.categoryIteration((GrClosableBlock) run, processor, state))
                    return false;
            }
            PsiClass superClass = getLiteralSuperClass((GrClosableBlock) run);
            if (superClass != null && !GdkMethodUtil.processCategoryMethods(run, processor, state, superClass))
                return false;
        }
        if (run instanceof GrStatementOwner) {
            if (!GdkMethodUtil.processMixinToMetaclass((GrStatementOwner) run, processor, state, lastParent, place))
                return false;
        }
        lastParent = run;
        run = run.getContext();
    }
    return true;
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 20 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 resolveLabelTargets.

@NotNull
public static Pair<GrStatement, GrLabeledStatement> resolveLabelTargets(@Nullable String labelName, @Nullable PsiElement element, boolean isBreak) {
    if (element == null)
        return new Pair<>(null, null);
    if (labelName == null) {
        do {
            element = element.getContext();
            if (element == null || element instanceof GrClosableBlock || element instanceof GrMember || element instanceof GroovyFile) {
                return new Pair<>(null, null);
            }
        } while (!(element instanceof GrLoopStatement) && !(isBreak && element instanceof GrSwitchStatement));
        return new Pair<>(((GrStatement) element), null);
    }
    GrStatement statement = null;
    do {
        PsiElement last = element;
        element = element.getContext();
        if (element == null || element instanceof GrMember || element instanceof GroovyFile)
            break;
        if (element instanceof GrStatement && !(element instanceof GrClosableBlock)) {
            statement = (GrStatement) element;
        }
        PsiElement sibling = element;
        while (sibling != null) {
            final GrLabeledStatement labelStatement = findLabelStatementIn(sibling, last, labelName);
            if (labelStatement != null) {
                return Pair.create(statement, labelStatement);
            }
            sibling = sibling.getPrevSibling();
        }
        if (element instanceof GrClosableBlock)
            break;
    } while (true);
    return new Pair<>(null, null);
}
Also used : GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

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