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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations