Search in sources :

Example 1 with GrInstanceOfExpression

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

Nullable (org.jetbrains.annotations.Nullable)1 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)1 GrBinaryExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)1 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)1 GrInstanceOfExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrInstanceOfExpression)1 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)1 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)1