Search in sources :

Example 6 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.

the class ConvertJunitAssertionToAssertStatementIntention method satisfiedBy.

@Override
public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof GrMethodCall))
        return false;
    GrMethodCall methodCall = (GrMethodCall) element;
    PsiMethod method = methodCall.resolveMethod();
    if (method == null)
        return false;
    return getReplacementStatement(method, methodCall) != null;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) PsiMethod(com.intellij.psi.PsiMethod)

Example 7 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.

the class MyPredicate method getParameterByArgument.

@Nullable
private static GrParameter getParameterByArgument(GrExpression arg) {
    PsiElement parent = PsiUtil.skipParentheses(arg.getParent(), true);
    if (!(parent instanceof GrArgumentList))
        return null;
    final GrArgumentList argList = (GrArgumentList) parent;
    parent = parent.getParent();
    if (!(parent instanceof GrMethodCall))
        return null;
    final GrMethodCall methodCall = (GrMethodCall) parent;
    final GrExpression expression = methodCall.getInvokedExpression();
    if (!(expression instanceof GrReferenceExpression))
        return null;
    final GroovyResolveResult resolveResult = ((GrReferenceExpression) expression).advancedResolve();
    if (resolveResult == null)
        return null;
    GrClosableBlock[] closures = methodCall.getClosureArguments();
    final Map<GrExpression, Pair<PsiParameter, PsiType>> mapToParams = GrClosureSignatureUtil.mapArgumentsToParameters(resolveResult, arg, false, false, argList.getNamedArguments(), argList.getExpressionArguments(), closures);
    if (mapToParams == null)
        return null;
    final Pair<PsiParameter, PsiType> parameterPair = mapToParams.get(arg);
    final PsiParameter parameter = parameterPair == null ? null : parameterPair.getFirst();
    return parameter instanceof GrParameter ? ((GrParameter) parameter) : null;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.

the class MavenGroovyPomUtil method getGroovyMethodCalls.

@NotNull
public static List<String> getGroovyMethodCalls(PsiElement psiElement) {
    LinkedList<String> methodCallInfo = ContainerUtilRt.newLinkedList();
    for (GrMethodCall current = PsiTreeUtil.getParentOfType(psiElement, GrMethodCall.class); current != null; current = PsiTreeUtil.getParentOfType(current, GrMethodCall.class)) {
        GrExpression expression = current.getInvokedExpression();
        String text = expression.getText();
        if (text != null) {
            methodCallInfo.addFirst(text);
        }
    }
    return methodCallInfo;
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.

the class GantMemberContributor method processDynamicElements.

@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
    if (aClass != null && ClassUtil.getSuperClassesWithCache(aClass).containsKey("groovy.util.AntBuilder")) {
        processAntTasks(processor, place, state);
        return;
    }
    if (!(place instanceof GrReferenceExpression) || ((GrReferenceExpression) place).isQualified()) {
        return;
    }
    GrClosableBlock closure = PsiTreeUtil.getContextOfType(place, GrClosableBlock.class, true);
    boolean antTasksProcessed = false;
    while (closure != null) {
        final PsiElement parent = closure.getParent();
        if (parent instanceof GrMethodCall) {
            final PsiMethod method = ((GrMethodCall) parent).resolveMethod();
            if (method instanceof AntBuilderMethod) {
                antTasksProcessed = true;
                if (!processAntTasks(processor, place, state)) {
                    return;
                }
                if (!((AntBuilderMethod) method).processNestedElements(processor)) {
                    return;
                }
                break;
            }
        }
        closure = PsiTreeUtil.getContextOfType(closure, GrClosableBlock.class, true);
    }
    // ------- gant-specific
    PsiFile file = place.getContainingFile();
    if (file == null || !GroovyScriptUtil.isSpecificScriptFile(file, GantScriptType.INSTANCE)) {
        return;
    }
    if (aClass instanceof GroovyScriptClass) {
        for (GrArgumentLabel label : GantUtils.getScriptTargets((GroovyFile) file)) {
            final String targetName = label.getName();
            if (targetName != null) {
                final PsiNamedElement variable = new LightVariableBuilder(targetName, GroovyCommonClassNames.GROOVY_LANG_CLOSURE, label).setBaseIcon(JetgroovyIcons.Groovy.Gant_target);
                if (!ResolveUtil.processElement(processor, variable, state)) {
                    return;
                }
            }
        }
    }
    if (!antTasksProcessed) {
        processAntTasks(processor, place, state);
    }
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrArgumentLabel(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) LightVariableBuilder(com.intellij.psi.impl.light.LightVariableBuilder) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)

Example 10 with GrMethodCall

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall in project intellij-community by JetBrains.

the class MapKeysCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    GrReferenceExpression expression = (GrReferenceExpression) element.getParent();
    GrExpression qualifierExpression = expression.getQualifierExpression();
    if (qualifierExpression == null)
        return;
    PsiType mapType = qualifierExpression.getType();
    if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
        return;
    }
    PsiElement resolve = null;
    if (qualifierExpression instanceof GrMethodCall) {
        resolve = ((GrMethodCall) qualifierExpression).resolveMethod();
    } else if (qualifierExpression instanceof GrReferenceExpression) {
        resolve = ((GrReferenceExpression) qualifierExpression).resolve();
    }
    for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
        GroovyMapCompletionUtil.addKeyVariants(provider, qualifierExpression, resolve, result);
    }
    if (mapType instanceof GrMapType) {
        for (String key : ((GrMapType) mapType).getStringKeys()) {
            LookupElement lookup = LookupElementBuilder.create(key);
            lookup = PrioritizedLookupElement.withPriority(lookup, 1);
            result.addElement(lookup);
        }
    }
}
Also used : GrMapType(org.jetbrains.plugins.groovy.lang.psi.impl.GrMapType) GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyMapContentProvider(org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiType(com.intellij.psi.PsiType)

Aggregations

GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)51 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)23 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)22 Nullable (org.jetbrains.annotations.Nullable)18 PsiElement (com.intellij.psi.PsiElement)17 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)13 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)9 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 NotNull (org.jetbrains.annotations.NotNull)7 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 PsiMethod (com.intellij.psi.PsiMethod)3 PsiType (com.intellij.psi.PsiType)3 ArrayList (java.util.ArrayList)3 GroovyMapContentProvider (org.jetbrains.plugins.groovy.extensions.GroovyMapContentProvider)3 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)3 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)3