Search in sources :

Example 66 with GroovyResolveResult

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

the class GroovyPropertyUtils method findPropertySetter.

@Nullable
public static PsiMethod findPropertySetter(@Nullable PsiType type, String propertyName, @NotNull GroovyPsiElement context) {
    final String setterName = getSetterName(propertyName);
    if (type == null) {
        final GrExpression fromText = GroovyPsiElementFactory.getInstance(context.getProject()).createExpressionFromText("this", context);
        return findPropertySetter(fromText.getType(), propertyName, context);
    }
    final AccessorResolverProcessor processor = new AccessorResolverProcessor(setterName, propertyName, context, false);
    ResolveUtil.processAllDeclarations(type, processor, ResolveState.initial(), context);
    final GroovyResolveResult[] setterCandidates = processor.getCandidates();
    return PsiImplUtil.extractUniqueElement(setterCandidates);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) AccessorResolverProcessor(org.jetbrains.plugins.groovy.lang.resolve.processors.AccessorResolverProcessor) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with GroovyResolveResult

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

the class PsiUtil method isRawMethodCall.

public static boolean isRawMethodCall(GrMethodCallExpression call) {
    final GroovyResolveResult result = call.advancedResolve();
    final PsiElement element = result.getElement();
    if (element == null)
        return false;
    if (element instanceof PsiMethod) {
        PsiType returnType = getSmartReturnType((PsiMethod) element);
        final GrExpression expression = call.getInvokedExpression();
        if (expression instanceof GrReferenceExpression && result.isInvokedOnProperty()) {
            if (returnType instanceof GrClosureType) {
                return isRawClosureCall(call, result, (GrClosureType) returnType);
            }
        } else {
            return isRawType(returnType, result.getSubstitutor());
        }
    }
    if (element instanceof PsiVariable) {
        GrExpression expression = call.getInvokedExpression();
        final PsiType type = expression.getType();
        if (type instanceof GrClosureType) {
            return isRawClosureCall(call, result, (GrClosureType) type);
        }
    }
    return false;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)

Example 68 with GroovyResolveResult

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

the class ClosureParameterEnhancer method findTypeFromIteratorMethod.

@Nullable
private static PsiType findTypeFromIteratorMethod(@Nullable PsiType type, PsiElement context) {
    if (!(type instanceof PsiClassType))
        return null;
    final GroovyResolveResult[] candidates = ResolveUtil.getMethodCandidates(type, "iterator", context, PsiType.EMPTY_ARRAY);
    final GroovyResolveResult candidate = PsiImplUtil.extractUniqueResult(candidates);
    final PsiElement element = candidate.getElement();
    if (!(element instanceof PsiMethod))
        return null;
    final PsiType returnType = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType((PsiMethod) element);
    final PsiType iteratorType = candidate.getSubstitutor().substitute(returnType);
    return PsiUtil.substituteTypeParameter(iteratorType, JAVA_UTIL_ITERATOR, 0, false);
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with GroovyResolveResult

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

the class GrLightAnnotation method getNameReferenceElement.

@Override
public PsiJavaCodeReferenceElement getNameReferenceElement() {
    final GroovyResolveResult resolveResult = myRef.advancedResolve();
    final PsiElement resolved = resolveResult.getElement();
    if (resolved instanceof PsiClass) {
        return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass) resolved, resolveResult.getSubstitutor());
    } else {
        return null;
    }
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) LightClassReference(com.intellij.psi.impl.light.LightClassReference)

Example 70 with GroovyResolveResult

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

the class PsiUtil method isVoidMethodCall.

public static boolean isVoidMethodCall(@Nullable GrExpression expression) {
    if (expression instanceof GrMethodCall && PsiType.NULL.equals(expression.getType())) {
        final GroovyResolveResult resolveResult = ((GrMethodCall) expression).advancedResolve();
        final PsiType[] args = getArgumentTypes(((GrMethodCall) expression).getInvokedExpression(), true);
        return PsiType.VOID.equals(ResolveUtil.extractReturnTypeFromCandidate(resolveResult, expression, args));
    }
    return false;
}
Also used : GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)

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