Search in sources :

Example 1 with NonCodeMembersHolder

use of org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder in project intellij-community by JetBrains.

the class GroovyDslDefaultMembers method add.

/**
   * Add a member to a context's ctype
   */
public PsiMember add(PsiMember member, GdslMembersHolderConsumer consumer) {
    final NonCodeMembersHolder holder = new NonCodeMembersHolder();
    holder.addDeclaration(member);
    consumer.addMemberHolder(holder);
    return member;
}
Also used : NonCodeMembersHolder(org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder)

Example 2 with NonCodeMembersHolder

use of org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder 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)

Aggregations

NonCodeMembersHolder (org.jetbrains.plugins.groovy.dsl.holders.NonCodeMembersHolder)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)1 ResolverProcessor (org.jetbrains.plugins.groovy.lang.resolve.processors.ResolverProcessor)1