Search in sources :

Example 1 with GrParenthesizedExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression in project intellij-community by JetBrains.

the class InvertIfIntention method stripParenthesis.

@NotNull
private static GrExpression stripParenthesis(GrExpression operand) {
    while (operand instanceof GrParenthesizedExpression) {
        GrExpression innerExpression = ((GrParenthesizedExpression) operand).getOperand();
        if (innerExpression == null) {
            break;
        }
        operand = innerExpression;
    }
    return operand;
}
Also used : GrParenthesizedExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GrParenthesizedExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression in project intellij-community by JetBrains.

the class TypeCastSurrounder method surroundExpression.

@Override
protected TextRange surroundExpression(@NotNull GrExpression expression, PsiElement context) {
    GrParenthesizedExpression parenthesized = (GrParenthesizedExpression) GroovyPsiElementFactory.getInstance(expression.getProject()).createExpressionFromText("((Type)a)", context);
    GrTypeCastExpression typeCast = (GrTypeCastExpression) parenthesized.getOperand();
    replaceToOldExpression(typeCast.getOperand(), expression);
    GrTypeElement typeElement = typeCast.getCastTypeElement();
    int endOffset = typeElement.getTextRange().getStartOffset() + expression.getTextRange().getStartOffset();
    parenthesized = (GrParenthesizedExpression) expression.replaceWithExpression(parenthesized, false);
    final GrTypeCastExpression newTypeCast = (GrTypeCastExpression) parenthesized.getOperand();
    final GrTypeElement newTypeElement = newTypeCast.getCastTypeElement();
    newTypeElement.delete();
    return new TextRange(endOffset, endOffset);
}
Also used : GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) GrParenthesizedExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression) GrTypeCastExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTypeCastExpression) TextRange(com.intellij.openapi.util.TextRange)

Example 3 with GrParenthesizedExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression in project intellij-community by JetBrains.

the class GrArgumentLabelImpl method getLabelType.

@Override
public PsiType getLabelType() {
    PsiElement el = getNameElement();
    if (el instanceof GrParenthesizedExpression) {
        return ((GrParenthesizedExpression) el).getType();
    }
    final ASTNode node = el.getNode();
    if (node == null) {
        return null;
    }
    PsiType nodeType = TypesUtil.getPsiType(el, node.getElementType());
    if (nodeType != null) {
        return nodeType;
    }
    return TypesUtil.createType(CommonClassNames.JAVA_LANG_STRING, this);
}
Also used : GrParenthesizedExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression) ASTNode(com.intellij.lang.ASTNode) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 4 with GrParenthesizedExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression in project intellij-community by JetBrains.

the class BoolUtils method isNegated.

public static boolean isNegated(GrExpression exp) {
    GrExpression ancestor = exp;
    while (ancestor.getParent() instanceof GrParenthesizedExpression) {
        ancestor = (GrExpression) ancestor.getParent();
    }
    if (ancestor.getParent() instanceof GrUnaryExpression) {
        final GrUnaryExpression prefixAncestor = (GrUnaryExpression) ancestor.getParent();
        final IElementType sign = prefixAncestor.getOperationTokenType();
        if (GroovyTokenTypes.mLNOT.equals(sign)) {
            return true;
        }
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrParenthesizedExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression) GrUnaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)

Example 5 with GrParenthesizedExpression

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression in project intellij-community by JetBrains.

the class BoolUtils method findNegation.

@Nullable
public static GrExpression findNegation(GrExpression exp) {
    GrExpression ancestor = exp;
    while (ancestor.getParent() instanceof GrParenthesizedExpression) {
        ancestor = (GrExpression) ancestor.getParent();
    }
    if (ancestor.getParent() instanceof GrUnaryExpression) {
        final GrUnaryExpression prefixAncestor = (GrUnaryExpression) ancestor.getParent();
        final IElementType sign = prefixAncestor.getOperationTokenType();
        if (GroovyTokenTypes.mLNOT.equals(sign)) {
            return prefixAncestor;
        }
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) GrParenthesizedExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression) GrUnaryExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GrParenthesizedExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)4 IElementType (com.intellij.psi.tree.IElementType)3 TextRange (com.intellij.openapi.util.TextRange)2 GrUnaryExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrUnaryExpression)2 ASTNode (com.intellij.lang.ASTNode)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 GrBinaryExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression)1 GrTypeCastExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrTypeCastExpression)1 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)1