Search in sources :

Example 86 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.

the class CompleteReferencesWithSameQualifier method addVariantsWithSameQualifier.

private void addVariantsWithSameQualifier(@NotNull PsiElement element, @NotNull Set<String> result) {
    if (element instanceof GrReferenceExpression && element != myRefExpr && !PsiUtil.isLValue((GroovyPsiElement) element)) {
        final GrReferenceExpression refExpr = (GrReferenceExpression) element;
        final String refName = refExpr.getReferenceName();
        if (refName != null && !result.contains(refName) && myMatcher.prefixMatches(refName)) {
            final GrExpression hisQualifier = refExpr.getQualifierExpression();
            if (hisQualifier != null && myQualifier != null) {
                if (PsiEquivalenceUtil.areElementsEquivalent(hisQualifier, myQualifier)) {
                    if (refExpr.resolve() == null) {
                        result.add(refName);
                    }
                }
            } else if (hisQualifier == null && myQualifier == null) {
                if (refExpr.resolve() == null) {
                    result.add(refName);
                }
            }
        }
    }
    for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
        addVariantsWithSameQualifier(child, result);
    }
}
Also used : GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 87 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement 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 88 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.

the class ApplicationStatementUtil method convertAppInternal.

private static GrMethodCallExpression convertAppInternal(GroovyPsiElementFactory factory, GrApplicationStatement app) {
    final GrCommandArgumentList list = app.getArgumentList();
    final GrMethodCallExpression prototype = (GrMethodCallExpression) factory.createExpressionFromText("foo()");
    prototype.getInvokedExpression().replace(app.getInvokedExpression());
    final GrArgumentList pList = prototype.getArgumentList();
    final PsiElement anchor = pList.getRightParen();
    for (GroovyPsiElement arg : list.getAllArguments()) {
        pList.addBefore(arg, anchor);
    }
    return prototype;
}
Also used : GrCommandArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 89 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.

the class ControlFlowBuilder method collectCorrespondingPendingEdges.

@NotNull
private List<Pair<InstructionImpl, GroovyPsiElement>> collectCorrespondingPendingEdges(@Nullable PsiElement currentScope) {
    if (currentScope == null) {
        List<Pair<InstructionImpl, GroovyPsiElement>> result = myPending;
        myPending = ContainerUtil.newArrayList();
        return result;
    } else {
        ArrayList<Pair<InstructionImpl, GroovyPsiElement>> targets = ContainerUtil.newArrayList();
        for (int i = myPending.size() - 1; i >= 0; i--) {
            final Pair<InstructionImpl, GroovyPsiElement> pair = myPending.get(i);
            final PsiElement scopeWhenToAdd = pair.getSecond();
            if (scopeWhenToAdd == null)
                continue;
            if (!PsiTreeUtil.isAncestor(scopeWhenToAdd, currentScope, false)) {
                targets.add(pair);
                myPending.remove(i);
            } else {
                break;
            }
        }
        return targets;
    }
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project intellij-community by JetBrains.

the class ControlFlowBuilder method collectAndRemoveAllPendingNegations.

private List<GotoInstruction> collectAndRemoveAllPendingNegations(GroovyPsiElement currentScope) {
    List<GotoInstruction> negations = new ArrayList<>();
    for (Iterator<Pair<InstructionImpl, GroovyPsiElement>> iterator = myPending.iterator(); iterator.hasNext(); ) {
        Pair<InstructionImpl, GroovyPsiElement> pair = iterator.next();
        InstructionImpl instruction = pair.first;
        GroovyPsiElement scope = pair.second;
        if (!PsiTreeUtil.isAncestor(scope, currentScope, true) && instruction instanceof GotoInstruction) {
            negations.add((GotoInstruction) instruction);
            iterator.remove();
        }
    }
    return negations;
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) Pair(com.intellij.openapi.util.Pair)

Aggregations

GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)98 PsiElement (com.intellij.psi.PsiElement)34 Nullable (org.jetbrains.annotations.Nullable)17 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)17 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)16 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)13 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)12 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)11 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)9 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)8 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)8 GrApplicationStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement)8 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)8 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)8 Project (com.intellij.openapi.project.Project)7 TextRange (com.intellij.openapi.util.TextRange)7 NotNull (org.jetbrains.annotations.NotNull)7 GroovyRecursiveElementVisitor (org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor)7 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)7 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)6