Search in sources :

Example 51 with GrCodeReferenceElement

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

the class GrNewExpressionImpl method getCallVariants.

@Override
@NotNull
public GroovyResolveResult[] getCallVariants(@Nullable GrExpression upToArgument) {
    final GrCodeReferenceElement referenceElement = getReferenceElement();
    if (referenceElement == null)
        return GroovyResolveResult.EMPTY_ARRAY;
    List<GroovyResolveResult> result = new ArrayList<>();
    for (GroovyResolveResult classResult : referenceElement.multiResolve(false)) {
        final PsiElement element = classResult.getElement();
        if (element instanceof PsiClass) {
            ContainerUtil.addAll(result, ResolveUtil.getAllClassConstructors((PsiClass) element, classResult.getSubstitutor(), null, this));
        }
    }
    return result.toArray(new GroovyResolveResult[result.size()]);
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with GrCodeReferenceElement

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

the class GrTypeParameterParameterExtendsListImpl method getReferencedTypes.

@Override
@NotNull
public PsiClassType[] getReferencedTypes() {
    final GrCodeReferenceElement[] refs = findChildrenByClass(GrCodeReferenceElement.class);
    PsiClassType[] result = new PsiClassType[refs.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = new GrClassReferenceType(refs[i]);
    }
    return result;
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) PsiClassType(com.intellij.psi.PsiClassType) GrClassReferenceType(org.jetbrains.plugins.groovy.lang.psi.impl.GrClassReferenceType) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with GrCodeReferenceElement

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

the class GrImportStatementImpl method getImportedName.

@Override
@Nullable
public String getImportedName() {
    if (isOnDemand())
        return null;
    GrImportStatementStub stub = getStub();
    if (stub != null) {
        String name = stub.getAliasName();
        if (name != null) {
            return name;
        }
        String referenceText = stub.getReferenceText();
        if (referenceText == null)
            return null;
        return StringUtil.getShortName(referenceText);
    }
    PsiElement aliasNameElement = getAliasNameElement();
    if (aliasNameElement != null) {
        return aliasNameElement.getText();
    }
    GrCodeReferenceElement ref = getImportReference();
    return ref == null ? null : ref.getReferenceName();
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrImportStatementStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrImportStatementStub) Nullable(org.jetbrains.annotations.Nullable)

Example 54 with GrCodeReferenceElement

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

the class GrPackageDefinitionImpl method getPackageName.

@Override
public String getPackageName() {
    final GrPackageDefinitionStub stub = getStub();
    if (stub != null) {
        return stub.getPackageName();
    }
    GrCodeReferenceElement ref = getPackageReference();
    if (ref == null)
        return "";
    return PsiUtil.getQualifiedReferenceText(ref);
}
Also used : GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrPackageDefinitionStub(org.jetbrains.plugins.groovy.lang.psi.stubs.GrPackageDefinitionStub)

Example 55 with GrCodeReferenceElement

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

the class GroovyTargetElementEvaluator method getElementByReference.

@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
    PsiElement sourceElement = ref.getElement();
    if (sourceElement instanceof GrCodeReferenceElement) {
        GrNewExpression newExpr;
        if (sourceElement.getParent() instanceof GrNewExpression) {
            newExpr = (GrNewExpression) sourceElement.getParent();
        } else if (sourceElement.getParent().getParent() instanceof GrNewExpression) {
            //anonymous class declaration
            newExpr = (GrNewExpression) sourceElement.getParent().getParent();
        } else {
            return null;
        }
        final PsiMethod constructor = newExpr.resolveMethod();
        final GrArgumentList argumentList = newExpr.getArgumentList();
        if (constructor != null && argumentList != null && PsiImplUtil.hasNamedArguments(argumentList) && !PsiImplUtil.hasExpressionArguments(argumentList)) {
            if (constructor.getParameterList().getParametersCount() == 0)
                return constructor.getContainingClass();
        }
        return constructor;
    }
    if (sourceElement instanceof GrReferenceExpression) {
        PsiElement resolved = ((GrReferenceExpression) sourceElement).resolve();
        if (resolved instanceof GrGdkMethod || !(resolved instanceof GrRenameableLightElement)) {
            return correctSearchTargets(resolved);
        }
        return resolved;
    }
    return null;
}
Also used : GrNewExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExpression) GrCodeReferenceElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement) GrGdkMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod) PsiMethod(com.intellij.psi.PsiMethod) GrArgumentList(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList) GrRenameableLightElement(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrRenameableLightElement) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

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