Search in sources :

Example 26 with GrBinaryExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression 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)

Aggregations

GrBinaryExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)26 IElementType (com.intellij.psi.tree.IElementType)15 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)14 NotNull (org.jetbrains.annotations.NotNull)3 PsiElement (com.intellij.psi.PsiElement)2 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)2 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)2 GrAssignmentExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression)2 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)2 ASTNode (com.intellij.lang.ASTNode)1 PsiType (com.intellij.psi.PsiType)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 Nullable (org.jetbrains.annotations.Nullable)1 GrDocComment (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment)1 GrDocTag (org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag)1 GroovyFileBase (org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase)1 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrAnnotationArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArgumentList)1