Search in sources :

Example 41 with GroovyResolveResult

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

the class GroovyDslDefaultMembers method delegatesTo.

/**
   * **********************************************************************************
   * Methods and properties of the GroovyDSL language
   * **********************************************************************************
   */
public void delegatesTo(@Nullable PsiElement elem, GdslMembersHolderConsumer consumer) {
    if (elem instanceof PsiClass) {
        final PsiClass clazz = (PsiClass) elem;
        final NonCodeMembersHolder holder = new NonCodeMembersHolder();
        if (clazz instanceof GrTypeDefinition) {
            final PsiClassType type = JavaPsiFacade.getElementFactory(consumer.getProject()).createType(clazz);
            final ResolverProcessor processor = CompletionProcessor.createPropertyCompletionProcessor(clazz);
            final GroovyPsiElement context = (GroovyPsiElement) clazz;
            ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), context);
            for (GroovyResolveResult result : processor.getCandidates()) {
                final PsiElement element = result.getElement();
                if (element instanceof PsiMethod && !((PsiMethod) element).isConstructor() || element instanceof PsiField) {
                    holder.addDeclaration(element);
                }
            }
        } else {
            for (PsiMethod method : clazz.getAllMethods()) {
                if (!method.isConstructor())
                    holder.addDeclaration(method);
            }
            for (PsiField field : clazz.getAllFields()) {
                holder.addDeclaration(field);
            }
        }
        consumer.addMemberHolder(holder);
    } else if (elem instanceof GrExpression) {
        GrExpression expr = (GrExpression) elem;
        final PsiType type = expr.getType();
        if (type instanceof PsiClassType) {
            PsiClassType ctype = (PsiClassType) type;
            delegatesTo(ctype.resolve(), consumer);
        }
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) ResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor) NonCodeMembersHolder(org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 42 with GroovyResolveResult

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

the class GroovyTypeCheckVisitor method checkOperator.

private void checkOperator(@NotNull CallInfo<? extends GrBinaryExpression> info) {
    if (hasErrorElements(info.getCall()))
        return;
    if (isSpockTimesOperator(info.getCall()))
        return;
    GroovyResolveResult[] results = info.multiResolve();
    GroovyResolveResult resolveResult = info.advancedResolve();
    if (isOperatorWithSimpleTypes(info.getCall(), resolveResult))
        return;
    if (!checkCannotInferArgumentTypes(info))
        return;
    if (resolveResult.getElement() != null) {
        checkMethodApplicability(resolveResult, true, info);
    } else if (results.length > 0) {
        for (GroovyResolveResult result : results) {
            if (!checkMethodApplicability(result, false, info))
                return;
        }
        registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("method.call.is.ambiguous"));
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)

Example 43 with GroovyResolveResult

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

the class GroovyTypeCheckVisitor method checkIndexProperty.

private void checkIndexProperty(@NotNull CallInfo<? extends GrIndexProperty> info) {
    if (hasErrorElements(info.getArgumentList()))
        return;
    if (!checkCannotInferArgumentTypes(info))
        return;
    final PsiType type = info.getQualifierInstanceType();
    if (ResolveUtil.getClassReferenceFromExpression(info.getCall()) != null) {
        return;
    }
    final PsiType[] types = info.getArgumentTypes();
    if (checkSimpleArrayAccess(info, type, types))
        return;
    final GroovyResolveResult[] results = info.multiResolve();
    final GroovyResolveResult resolveResult = info.advancedResolve();
    if (resolveResult.getElement() != null) {
        PsiElement resolved = resolveResult.getElement();
        if (resolved instanceof PsiMethod && !resolveResult.isInvokedOnProperty()) {
            checkMethodApplicability(resolveResult, true, info);
        } else if (resolved instanceof GrField) {
            checkCallApplicability(((GrField) resolved).getTypeGroovy(), true, info);
        } else if (resolved instanceof PsiField) {
            checkCallApplicability(((PsiField) resolved).getType(), true, info);
        }
    } else if (results.length > 0) {
        for (GroovyResolveResult result : results) {
            PsiElement resolved = result.getElement();
            if (resolved instanceof PsiMethod && !result.isInvokedOnProperty()) {
                if (!checkMethodApplicability(result, false, info))
                    return;
            } else if (resolved instanceof GrField) {
                if (!checkCallApplicability(((GrField) resolved).getTypeGroovy(), false, info))
                    return;
            } else if (resolved instanceof PsiField) {
                if (!checkCallApplicability(((PsiField) resolved).getType(), false, info))
                    return;
            }
        }
        registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("method.call.is.ambiguous"));
    } else {
        final String typesString = buildArgTypesList(types);
        registerError(info.getElementToHighlight(), ProblemHighlightType.GENERIC_ERROR, GroovyBundle.message("cannot.find.operator.overload.method", typesString));
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 44 with GroovyResolveResult

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

the class GroovyChangeUtilSupport method encodeInformation.

@Override
public void encodeInformation(final TreeElement element, final ASTNode original, final Map<Object, Object> encodingState) {
    if (original instanceof CompositeElement) {
        if (original.getElementType() == GroovyElementTypes.REFERENCE_ELEMENT || original.getElementType() == GroovyElementTypes.REFERENCE_EXPRESSION) {
            PsiElement psi = original.getPsi();
            Project project = psi.getProject();
            if (!PsiUtil.isThisOrSuperRef(psi) && project.isInitialized() && !DumbService.isDumb(project)) {
                final GroovyResolveResult result = ((GrReferenceElement) psi).advancedResolve();
                if (result != null) {
                    final PsiElement target = result.getElement();
                    if (target instanceof PsiClass || (target instanceof PsiMethod || target instanceof PsiField) && ((PsiMember) target).hasModifierProperty(PsiModifier.STATIC) && result.getCurrentFileResolveContext() instanceof GrImportStatement) {
                        element.putCopyableUserData(REFERENCED_MEMBER_KEY, (PsiMember) target);
                    }
                }
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement) GrReferenceElement(org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)

Example 45 with GroovyResolveResult

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

the class GroovyConstructorNamedArgumentProvider method getNamedArguments.

@Override
public void getNamedArguments(@NotNull GrCall call, @NotNull GroovyResolveResult resolveResult, @Nullable String argumentName, boolean forCompletion, @NotNull Map<String, NamedArgumentDescriptor> result) {
    if (!(call instanceof GrNewExpression))
        return;
    PsiElement resolve = resolveResult.getElement();
    if (resolve != null) {
        if (!(resolve instanceof PsiMethod))
            return;
        PsiMethod method = (PsiMethod) resolve;
        if (!method.isConstructor())
            return;
    }
    GrNewExpression newCall = (GrNewExpression) call;
    GrArgumentList argumentList = newCall.getArgumentList();
    if (argumentList == null)
        return;
    GrExpression[] expressionArguments = argumentList.getExpressionArguments();
    if (expressionArguments.length > 1 || (expressionArguments.length == 1 && !(expressionArguments[0] instanceof GrReferenceExpression))) {
        return;
    }
    for (GroovyResolveResult newResult : newCall.multiResolveClass()) {
        PsiElement element = newResult.getElement();
        if (!(element instanceof PsiClass))
            continue;
        PsiClass aClass = (PsiClass) element;
        if (!isClassHasConstructorWithMap(aClass))
            continue;
        PsiClassType classType = JavaPsiFacade.getElementFactory(aClass.getProject()).createType(aClass);
        processClass(call, classType, argumentName, result);
    }
}
Also used : GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

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