Search in sources :

Example 26 with GrCodeReferenceElement

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

the class GrThrowsClauseImpl method add.

@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
    if (element instanceof GrCodeReferenceElement || element instanceof PsiJavaCodeReferenceElement) {
        if (findChildByClass(GrCodeReferenceElement.class) == null) {
            getNode().addLeaf(GroovyTokenTypes.kTHROWS, "throws", null);
        } else {
            PsiElement lastChild = getLastChild();
            lastChild = PsiUtil.skipWhitespacesAndComments(lastChild, false);
            if (!lastChild.getNode().getElementType().equals(GroovyTokenTypes.mCOMMA)) {
                getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", null);
            }
        }
        if (element instanceof PsiJavaCodeReferenceElement) {
            element = GroovyPsiElementFactory.getInstance(getProject()).createCodeReferenceElementFromText(element.getText());
        }
    }
    return super.add(element);
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) PsiElement(com.intellij.psi.PsiElement)

Example 27 with GrCodeReferenceElement

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

the class GrAnnotationNameValuePairImpl method multiResolve.

@NotNull
@Override
public GroovyResolveResult[] multiResolve(boolean incompleteCode) {
    GrAnnotation annotation = PsiImplUtil.getAnnotation(this);
    if (annotation != null) {
        GrCodeReferenceElement ref = annotation.getClassReference();
        PsiElement resolved = ref.resolve();
        String declaredName = getName();
        String name = declaredName == null ? PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME : declaredName;
        if (resolved instanceof PsiClass) {
            final PsiAnnotation collector = GrAnnotationCollector.findAnnotationCollector((PsiClass) resolved);
            if (collector != null) {
                return multiResolveFromAlias(annotation, name, collector);
            }
            if (((PsiClass) resolved).isAnnotationType()) {
                return multiResolveFromAnnotationType((PsiClass) resolved, name);
            }
        }
    }
    return GroovyResolveResult.EMPTY_ARRAY;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrAnnotation(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with GrCodeReferenceElement

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

the class GrAnnotationCollector method findAnnotationCollector.

@Nullable
public static PsiAnnotation findAnnotationCollector(@NotNull GrAnnotation annotation) {
    final GrCodeReferenceElement ref = annotation.getClassReference();
    final PsiElement resolved = ref.resolve();
    if (resolved instanceof PsiClass) {
        return findAnnotationCollector((PsiClass) resolved);
    } else {
        return null;
    }
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) Nullable(org.jetbrains.annotations.Nullable)

Example 29 with GrCodeReferenceElement

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

the class GrNewExpressionImpl method resolveImpl.

private GroovyResolveResult[] resolveImpl(boolean incompleteCode) {
    GrCodeReferenceElement ref = getReferenceElement();
    if (ref == null)
        return GroovyResolveResult.EMPTY_ARRAY;
    GroovyResolveResult classCandidate = inferClassCandidate(ref);
    if (classCandidate == null)
        return GroovyResolveResult.EMPTY_ARRAY;
    assert classCandidate.getElement() instanceof PsiClass;
    if (incompleteCode) {
        return PsiUtil.getConstructorCandidates(ref, classCandidate, null);
    }
    final GrArgumentList argumentList = getArgumentList();
    if (argumentList == null)
        return GroovyResolveResult.EMPTY_ARRAY;
    if (argumentList.getNamedArguments().length > 0 && argumentList.getExpressionArguments().length == 0) {
        PsiType mapType = GrMapType.createFromNamedArgs(argumentList, getNamedArguments());
        //one Map parameter, actually
        GroovyResolveResult[] constructorResults = PsiUtil.getConstructorCandidates(ref, classCandidate, new PsiType[] { mapType });
        for (GroovyResolveResult result : constructorResults) {
            final PsiElement resolved = result.getElement();
            if (resolved instanceof PsiMethod) {
                PsiMethod constructor = (PsiMethod) resolved;
                final PsiParameter[] parameters = constructor.getParameterList().getParameters();
                if (parameters.length == 1 && InheritanceUtil.isInheritor(parameters[0].getType(), CommonClassNames.JAVA_UTIL_MAP)) {
                    return constructorResults;
                }
            }
        }
        final GroovyResolveResult[] emptyConstructors = PsiUtil.getConstructorCandidates(ref, classCandidate, PsiType.EMPTY_ARRAY);
        if (emptyConstructors.length > 0) {
            return emptyConstructors;
        }
    }
    PsiType[] types = PsiUtil.getArgumentTypes(ref, true);
    if (types != null) {
        types = GrInnerClassConstructorUtil.addEnclosingArgIfNeeded(types, this, (PsiClass) classCandidate.getElement());
    }
    return PsiUtil.getConstructorCandidates(ref, classCandidate, types);
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)

Example 30 with GrCodeReferenceElement

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

the class GrReferenceListImpl method getReferenceElementsGroovy.

@Override
@NotNull
public GrCodeReferenceElement[] getReferenceElementsGroovy() {
    final GrReferenceListStub stub = getStub();
    if (stub != null) {
        final String[] baseClasses = stub.getBaseClasses();
        final GrCodeReferenceElement[] result = new GrCodeReferenceElement[baseClasses.length];
        for (int i = 0; i < baseClasses.length; i++) {
            result[i] = GroovyPsiElementFactory.getInstance(getProject()).createReferenceElementFromText(baseClasses[i], this);
        }
        return result;
    }
    return findChildrenByClass(GrCodeReferenceElement.class);
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrReferenceListStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrReferenceListStub) NotNull(org.jetbrains.annotations.NotNull)

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