Search in sources :

Example 51 with GrTypeElement

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

the class InstanceOfInstruction method getInstanceof.

@Nullable
private Pair<GrExpression, PsiType> getInstanceof() {
    final PsiElement element = getElement();
    if (element instanceof GrInstanceOfExpression) {
        GrExpression operand = ((GrInstanceOfExpression) element).getOperand();
        final GrTypeElement typeElement = ((GrInstanceOfExpression) element).getTypeElement();
        if (operand instanceof GrReferenceExpression && ((GrReferenceExpression) operand).getQualifier() == null && typeElement != null) {
            return Pair.create(((GrInstanceOfExpression) element).getOperand(), typeElement.getType());
        }
    } else if (element instanceof GrBinaryExpression && ControlFlowBuilderUtil.isInstanceOfBinary((GrBinaryExpression) element)) {
        GrExpression left = ((GrBinaryExpression) element).getLeftOperand();
        GrExpression right = ((GrBinaryExpression) element).getRightOperand();
        if (right == null)
            return null;
        GroovyResolveResult result = ((GrReferenceExpression) right).advancedResolve();
        final PsiElement resolved = result.getElement();
        if (resolved instanceof PsiClass) {
            PsiClassType type = JavaPsiFacade.getElementFactory(element.getProject()).createType((PsiClass) resolved, result.getSubstitutor());
            return new Pair<>(left, type);
        }
    }
    return null;
}
Also used : GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) GroovyResolveResult(org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrInstanceOfExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrInstanceOfExpression) GrBinaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 52 with GrTypeElement

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

the class GrVariableDeclarationStub method getTypeElement.

@Nullable
public GrTypeElement getTypeElement() {
    String typeString = getTypeString();
    if (typeString == null)
        return null;
    GrTypeElement typeElement = SoftReference.dereference(myTypeElement);
    if (typeElement == null) {
        typeElement = GroovyPsiElementFactory.getInstance(getProject()).createTypeElement(typeString, getPsi());
        myTypeElement = new SoftReference<>(typeElement);
    }
    return typeElement;
}
Also used : GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)52 Nullable (org.jetbrains.annotations.Nullable)12 PsiType (com.intellij.psi.PsiType)9 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)9 PsiElement (com.intellij.psi.PsiElement)7 GrVariableDeclaration (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration)7 IncorrectOperationException (com.intellij.util.IncorrectOperationException)6 NotNull (org.jetbrains.annotations.NotNull)6 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)6 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)6 TextRange (com.intellij.openapi.util.TextRange)5 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)5 GrModifierList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList)5 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)4 GrTypeCastExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTypeCastExpression)4 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)4 Document (com.intellij.openapi.editor.Document)3 GrSafeCastExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrSafeCastExpression)3 Template (com.intellij.codeInsight.template.Template)2 TemplateBuilderImpl (com.intellij.codeInsight.template.TemplateBuilderImpl)2