Search in sources :

Example 1 with GrSignatureVisitor

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

the class GdkMethodUtil method getClosureMixins.

private static Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>> getClosureMixins(final GrStatement statement) {
    if (!(statement instanceof GrAssignmentExpression))
        return null;
    final GrAssignmentExpression assignment = (GrAssignmentExpression) statement;
    return CachedValuesManager.getCachedValue(statement, new CachedValueProvider<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>>() {

        @Nullable
        @Override
        public Result<Trinity<PsiClassType, GrReferenceExpression, List<GrMethod>>> compute() {
            Pair<PsiClassType, GrReferenceExpression> original = getTypeToMixIn(assignment);
            if (original == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            final Pair<GrSignature, String> signatures = getTypeToMix(assignment);
            if (signatures == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            final String name = signatures.second;
            final List<GrMethod> methods = ContainerUtil.newArrayList();
            final PsiClass closure = JavaPsiFacade.getInstance(statement.getProject()).findClass(GroovyCommonClassNames.GROOVY_LANG_CLOSURE, statement.getResolveScope());
            if (closure == null)
                return Result.create(null, PsiModificationTracker.MODIFICATION_COUNT);
            signatures.first.accept(new GrSignatureVisitor() {

                @Override
                public void visitClosureSignature(GrClosureSignature signature) {
                    super.visitClosureSignature(signature);
                    GrMethod method = createMethod(signature, name, assignment, closure);
                    methods.add(method);
                }
            });
            return Result.create(Trinity.create(original.first, original.second, methods), PsiModificationTracker.MODIFICATION_COUNT);
        }
    });
}
Also used : Trinity(com.intellij.openapi.util.Trinity) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) GrAssignmentExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) List(java.util.List) Nullable(org.jetbrains.annotations.Nullable) Pair(com.intellij.openapi.util.Pair)

Aggregations

Pair (com.intellij.openapi.util.Pair)1 Trinity (com.intellij.openapi.util.Trinity)1 List (java.util.List)1 Nullable (org.jetbrains.annotations.Nullable)1 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)1 GrSignatureVisitor (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignatureVisitor)1 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)1 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)1