Search in sources :

Example 11 with GroovyResolveResult

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

the class GrIntroduceHandlerBase method expressionIsIncorrect.

public static boolean expressionIsIncorrect(@Nullable GrExpression expression, boolean acceptVoidCalls) {
    if (expression instanceof GrParenthesizedExpression)
        return true;
    if (PsiUtil.isSuperReference(expression))
        return true;
    if (expression instanceof GrAssignmentExpression)
        return true;
    if (expression instanceof GrReferenceExpression && expression.getParent() instanceof GrCall) {
        final GroovyResolveResult resolveResult = ((GrReferenceExpression) expression).advancedResolve();
        final PsiElement resolved = resolveResult.getElement();
        return resolved instanceof PsiMethod && !resolveResult.isInvokedOnProperty() || resolved instanceof PsiClass;
    }
    if (expression instanceof GrReferenceExpression && expression.getParent() instanceof GrReferenceExpression) {
        return !PsiUtil.isThisReference(expression) && ((GrReferenceExpression) expression).resolve() instanceof PsiClass;
    }
    if (expression instanceof GrClosableBlock && expression.getParent() instanceof GrStringInjection)
        return true;
    if (!acceptVoidCalls && expression instanceof GrMethodCall && PsiType.VOID.equals(expression.getType()))
        return true;
    return false;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrStringInjection(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 12 with GroovyResolveResult

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

the class GroovyInlineMethodUtil method replaceParametersWithArguments.

/**
   * Inline method call's arguments as its parameters
   *
   * @param call   method call
   * @param method given method
   */
public static void replaceParametersWithArguments(GrCallExpression call, GrMethod method) throws IncorrectOperationException {
    GrParameter[] parameters = method.getParameters();
    if (parameters.length == 0)
        return;
    GrArgumentList argumentList = call.getArgumentList();
    if (argumentList == null) {
        setDefaultValuesToParameters(method, null, call);
        return;
    }
    Project project = call.getProject();
    final GroovyResolveResult resolveResult = call.advancedResolve();
    GrClosureSignature signature = GrClosureSignatureUtil.createSignature(method, resolveResult.getSubstitutor());
    if (signature == null) {
        return;
    }
    GrClosureSignatureUtil.ArgInfo<PsiElement>[] infos = GrClosureSignatureUtil.mapParametersToArguments(signature, call.getNamedArguments(), call.getExpressionArguments(), call.getClosureArguments(), call, true, false);
    if (infos == null)
        return;
    for (int i = 0; i < infos.length; i++) {
        GrClosureSignatureUtil.ArgInfo<PsiElement> argInfo = infos[i];
        GrParameter parameter = parameters[i];
        final GrExpression arg = inferArg(signature, parameters, parameter, argInfo, project);
        if (arg != null) {
            replaceAllOccurrencesWithExpression(method, call, arg, parameter);
        }
    }
}
Also used : GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) GrClosureSignatureUtil(org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil) Project(com.intellij.openapi.project.Project) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)

Example 13 with GroovyResolveResult

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

the class StubGenerator method resolveChainingConstructor.

@Nullable
private static GroovyResolveResult resolveChainingConstructor(GrMethod constructor) {
    LOG.assertTrue(constructor.isConstructor());
    final GrConstructorInvocation constructorInvocation = PsiImplUtil.getChainingConstructorInvocation(constructor);
    if (constructorInvocation == null) {
        return null;
    }
    GroovyResolveResult resolveResult = constructorInvocation.advancedResolve();
    if (resolveResult.getElement() != null) {
        return resolveResult;
    }
    final GroovyResolveResult[] results = constructorInvocation.multiResolve(false);
    if (results.length > 0) {
        int i = 0;
        while (results.length > i + 1) {
            final PsiMethod candidate = (PsiMethod) results[i].getElement();
            final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(constructor.getProject()).getResolveHelper();
            if (candidate != null && candidate != constructor && resolveHelper.isAccessible(candidate, constructorInvocation, null)) {
                break;
            }
            i++;
        }
        return results[i];
    }
    return null;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrConstructorInvocation(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation) MethodSignatureBackedByPsiMethod(com.intellij.psi.util.MethodSignatureBackedByPsiMethod) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with GroovyResolveResult

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

the class GroovyDocumentationProvider method getMethodCandidateInfo.

private static String getMethodCandidateInfo(GrReferenceExpression expr) {
    final GroovyResolveResult[] candidates = expr.multiResolve(false);
    final String text = expr.getText();
    if (candidates.length > 0) {
        @NonNls final StringBuilder sb = new StringBuilder();
        for (final GroovyResolveResult candidate : candidates) {
            final PsiElement element = candidate.getElement();
            if (!(element instanceof PsiMethod)) {
                continue;
            }
            final String str = PsiFormatUtil.formatMethod((PsiMethod) element, candidate.getSubstitutor(), PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_TYPE | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
            createElementLink(sb, element, str);
        }
        return CodeInsightBundle.message("javadoc.candidates", text, sb);
    }
    return CodeInsightBundle.message("javadoc.candidates.not.found", text);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)

Example 15 with GroovyResolveResult

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

the class GroovyRefactoringSupportProvider method isMemberInplaceRenameAvailable.

@Override
public boolean isMemberInplaceRenameAvailable(@NotNull PsiElement element, @Nullable PsiElement context) {
    if (context == null || context.getContainingFile() instanceof GroovyFile)
        return false;
    PsiElement parent = context.getParent();
    //don't try to inplace rename aliased imported references
    if (parent instanceof GrReferenceElement) {
        GroovyResolveResult result = ((GrReferenceElement) parent).advancedResolve();
        PsiElement fileResolveContext = result.getCurrentFileResolveContext();
        if (fileResolveContext instanceof GrImportStatement && ((GrImportStatement) fileResolveContext).isAliasedImport()) {
            return false;
        }
    }
    return element instanceof GrMember;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrMember(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement) GrReferenceElement(org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)

Aggregations

GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)132 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)33 Nullable (org.jetbrains.annotations.Nullable)29 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)29 NotNull (org.jetbrains.annotations.NotNull)25 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)23 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)17 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)14 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)13 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)12 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)11 PsiElement (com.intellij.psi.PsiElement)10 ArrayList (java.util.ArrayList)8 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)8 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)8 IElementType (com.intellij.psi.tree.IElementType)7 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)7 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)7 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)7 Project (com.intellij.openapi.project.Project)6