Search in sources :

Example 1 with LightVariableBuilder

use of com.intellij.psi.impl.light.LightVariableBuilder in project intellij-community by JetBrains.

the class GantMemberContributor method processDynamicElements.

@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
    if (aClass != null && ClassUtil.getSuperClassesWithCache(aClass).containsKey("groovy.util.AntBuilder")) {
        processAntTasks(processor, place, state);
        return;
    }
    if (!(place instanceof GrReferenceExpression) || ((GrReferenceExpression) place).isQualified()) {
        return;
    }
    GrClosableBlock closure = PsiTreeUtil.getContextOfType(place, GrClosableBlock.class, true);
    boolean antTasksProcessed = false;
    while (closure != null) {
        final PsiElement parent = closure.getParent();
        if (parent instanceof GrMethodCall) {
            final PsiMethod method = ((GrMethodCall) parent).resolveMethod();
            if (method instanceof AntBuilderMethod) {
                antTasksProcessed = true;
                if (!processAntTasks(processor, place, state)) {
                    return;
                }
                if (!((AntBuilderMethod) method).processNestedElements(processor)) {
                    return;
                }
                break;
            }
        }
        closure = PsiTreeUtil.getContextOfType(closure, GrClosableBlock.class, true);
    }
    // ------- gant-specific
    PsiFile file = place.getContainingFile();
    if (file == null || !GroovyScriptUtil.isSpecificScriptFile(file, GantScriptType.INSTANCE)) {
        return;
    }
    if (aClass instanceof GroovyScriptClass) {
        for (GrArgumentLabel label : GantUtils.getScriptTargets((GroovyFile) file)) {
            final String targetName = label.getName();
            if (targetName != null) {
                final PsiNamedElement variable = new LightVariableBuilder(targetName, GroovyCommonClassNames.GROOVY_LANG_CLOSURE, label).setBaseIcon(JetgroovyIcons.Groovy.Gant_target);
                if (!ResolveUtil.processElement(processor, variable, state)) {
                    return;
                }
            }
        }
    }
    if (!antTasksProcessed) {
        processAntTasks(processor, place, state);
    }
}
Also used : GrMethodCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall) GrArgumentLabel(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) LightVariableBuilder(com.intellij.psi.impl.light.LightVariableBuilder) GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)

Aggregations

LightVariableBuilder (com.intellij.psi.impl.light.LightVariableBuilder)1 GrArgumentLabel (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel)1 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)1 GrMethodCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)1