use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression in project intellij-community by JetBrains.
the class ParenthesisExprSurrounder method surroundExpression.
@Override
protected TextRange surroundExpression(@NotNull GrExpression expression, PsiElement context) {
GrParenthesizedExpression result = (GrParenthesizedExpression) GroovyPsiElementFactory.getInstance(expression.getProject()).createExpressionFromText("(a)", context);
replaceToOldExpression(result.getOperand(), expression);
result = (GrParenthesizedExpression) expression.replaceWithExpression(result, true);
return new TextRange(result.getTextRange().getEndOffset(), result.getTextRange().getEndOffset());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression in project intellij-community by JetBrains.
the class BoolUtils method getNegatedExpressionText.
public static String getNegatedExpressionText(@NotNull GrExpression condition) {
if (condition instanceof GrParenthesizedExpression) {
final GrExpression contentExpression = ((GrParenthesizedExpression) condition).getOperand();
if (contentExpression == null)
return "()";
return '(' + getNegatedExpressionText(contentExpression) + ')';
} else if (isNegation(condition)) {
final GrExpression negated = getNegated(condition);
return negated.getText();
} else if (ComparisonUtils.isComparison(condition)) {
final GrBinaryExpression binaryExpression = (GrBinaryExpression) condition;
final IElementType sign = binaryExpression.getOperationTokenType();
final String negatedComparison = ComparisonUtils.getNegatedComparison(sign);
final GrExpression lhs = binaryExpression.getLeftOperand();
final GrExpression rhs = binaryExpression.getRightOperand();
assert rhs != null;
return lhs.getText() + negatedComparison + rhs.getText();
} else if (ParenthesesUtils.getPrecedence(condition) > ParenthesesUtils.PREFIX_PRECEDENCE) {
return "!(" + condition.getText() + ')';
} else {
return '!' + condition.getText();
}
}
Aggregations