Search in sources :

Example 1 with DelegatesToInfo

use of org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DelegatesToInfo in project intellij-community by JetBrains.

the class GrClosureDelegateTypeCalculator method calculateType.

@Nullable
protected PsiType calculateType(@NotNull GrExpression expression, @NotNull PsiMethod method) {
    if (!"getDelegate".equals(method.getName()) || method.getParameterList().getParametersCount() != 0)
        return null;
    final GrClosableBlock closure = PsiTreeUtil.getParentOfType(expression, GrClosableBlock.class);
    if (closure == null)
        return null;
    final PsiClass closureClass = JavaPsiFacade.getInstance(expression.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, expression.getResolveScope());
    if (closureClass == null || !closureClass.equals(method.getContainingClass()))
        return null;
    final DelegatesToInfo info = GrDelegatesToUtilKt.getDelegatesToInfo(closure);
    if (info == null)
        return null;
    return info.getTypeToDelegate();
}
Also used : GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) DelegatesToInfo(org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DelegatesToInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 DelegatesToInfo (org.jetbrains.plugins.groovy.lang.resolve.delegatesTo.DelegatesToInfo)1