Search in sources :

Example 31 with GrCodeReferenceElement

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

the class GrReferenceListImpl method getReferencedTypes.

@NotNull
@Override
public PsiClassType[] getReferencedTypes() {
    if (myCachedTypes == null || !isValid()) {
        final ArrayList<PsiClassType> types = new ArrayList<>();
        for (GrCodeReferenceElement ref : getReferenceElementsGroovy()) {
            types.add(new GrClassReferenceType(ref));
        }
        myCachedTypes = types.toArray(new PsiClassType[types.size()]);
    }
    return myCachedTypes;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrClassReferenceType(org.jetbrains.plugins.groovy.lang.psi.impl.GrClassReferenceType) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with GrCodeReferenceElement

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

the class GrImportStatementImpl method processSingleStaticImport.

private boolean processSingleStaticImport(@NotNull final PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull String importedName, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    final GrCodeReferenceElement ref = getImportReference();
    if (ref == null)
        return true;
    PsiClass clazz = resolveQualifier();
    if (clazz == null)
        return true;
    state = state.put(ClassHint.RESOLVE_CONTEXT, this);
    final String refName = ref.getReferenceName();
    for (PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
        if (!doProcessSingleStaticImport(each, state, importedName, lastParent, place, clazz, refName))
            return false;
    }
    return true;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor)

Example 33 with GrCodeReferenceElement

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

the class GrImportStatementImpl method processDeclarationsForMultipleElements.

private boolean processDeclarationsForMultipleElements(@NotNull final PsiScopeProcessor processor, @Nullable PsiElement lastParent, @NotNull PsiElement place, @NotNull ResolveState state) {
    GrCodeReferenceElement ref = getImportReference();
    if (ref == null)
        return true;
    if (isStatic()) {
        final PsiElement resolved = ref.resolve();
        if (resolved instanceof PsiClass) {
            state = state.put(ClassHint.RESOLVE_CONTEXT, this);
            final PsiClass clazz = (PsiClass) resolved;
            for (final PsiScopeProcessor each : GroovyResolverProcessor.allProcessors(processor)) {
                if (!clazz.processDeclarations(new DelegatingScopeProcessor(each) {

                    @Override
                    public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
                        if (element instanceof PsiMember && ((PsiMember) element).hasModifierProperty(PsiModifier.STATIC)) {
                            return super.execute(element, state);
                        }
                        return true;
                    }
                }, state, lastParent, place))
                    return false;
            }
        }
    } else {
        if (ResolveUtil.shouldProcessClasses(processor.getHint(ElementClassHint.KEY))) {
            String qName = PsiUtil.getQualifiedReferenceText(ref);
            if (qName != null) {
                PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage(qName);
                if (aPackage != null && !((GroovyFile) getContainingFile()).getPackageName().equals(aPackage.getQualifiedName())) {
                    state = state.put(ClassHint.RESOLVE_CONTEXT, this);
                    if (!aPackage.processDeclarations(processor, state, lastParent, place))
                        return false;
                }
            }
        }
    }
    return true;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) DelegatingScopeProcessor(com.intellij.psi.scope.DelegatingScopeProcessor) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with GrCodeReferenceElement

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

the class GrImportStatementImpl method resolveQualifier.

@Nullable
private PsiClass resolveQualifier() {
    return CachedValuesManager.getCachedValue(this, () -> {
        GrCodeReferenceElement reference = getImportReference();
        GrCodeReferenceElement qualifier = reference == null ? null : reference.getQualifier();
        PsiElement target = qualifier == null ? null : qualifier.resolve();
        PsiClass clazz = target instanceof PsiClass ? (PsiClass) target : null;
        return CachedValueProvider.Result.create(clazz, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT, this);
    });
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with GrCodeReferenceElement

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

the class GrImportStatementImpl method resolveTargetClass.

@Nullable
@Override
public PsiClass resolveTargetClass() {
    final GrCodeReferenceElement ref = getImportReference();
    if (ref == null)
        return null;
    final PsiElement resolved;
    if (!isStatic() || isOnDemand()) {
        resolved = ref.resolve();
    } else {
        resolved = resolveQualifier();
    }
    return resolved instanceof PsiClass ? (PsiClass) resolved : null;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)71 NotNull (org.jetbrains.annotations.NotNull)14 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)13 PsiElement (com.intellij.psi.PsiElement)12 Nullable (org.jetbrains.annotations.Nullable)12 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)11 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)10 GrNewExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression)8 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)7 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)7 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)6 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)5 GrAnonymousClassDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition)5 PsiClass (com.intellij.psi.PsiClass)4 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)4 GrTypeArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeArgumentList)4 Editor (com.intellij.openapi.editor.Editor)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 GrAnnotation (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation)3 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)3