use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class SimpleBinaryTransformation method apply.
@Override
public void apply(@NotNull GrBinaryExpression expression) {
GrExpression lhsParenthesized = addParenthesesIfNeeded(getLhs(expression));
replaceExpression(expression, format("%s.%s(%s)", lhsParenthesized.getText(), myMethod, getRhs(expression).getText()));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GroovyPointlessBooleanInspection method calculateSimplifiedBinaryExpression.
@Nullable
private static String calculateSimplifiedBinaryExpression(GrBinaryExpression expression) {
final IElementType sign = expression.getOperationTokenType();
final GrExpression lhs = expression.getLeftOperand();
final GrExpression rhs = expression.getRightOperand();
if (rhs == null) {
return null;
}
final String rhsText = rhs.getText();
final String lhsText = lhs.getText();
assert sign != null;
if (sign.equals(GroovyTokenTypes.mLAND)) {
if (isTrue(lhs)) {
return rhsText;
} else {
return lhsText;
}
} else if (sign.equals(GroovyTokenTypes.mLOR)) {
if (isFalse(lhs)) {
return rhsText;
} else {
return lhsText;
}
} else if (sign.equals(GroovyTokenTypes.mBXOR) || sign.equals(GroovyTokenTypes.mNOT_EQUAL)) {
if (isFalse(lhs)) {
return rhsText;
} else if (isFalse(rhs)) {
return lhsText;
} else if (isTrue(lhs)) {
return createStringForNegatedExpression(rhs);
} else {
return createStringForNegatedExpression(lhs);
}
} else if (sign.equals(GroovyTokenTypes.mEQUAL)) {
if (isTrue(lhs)) {
return rhsText;
} else if (isTrue(rhs)) {
return lhsText;
} else if (isFalse(lhs)) {
return createStringForNegatedExpression(rhs);
} else {
return createStringForNegatedExpression(lhs);
}
} else {
return "";
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class ConditionalUtils method isReturn.
public static boolean isReturn(GrStatement statement, String value) {
if (statement == null) {
return false;
}
if (!(statement instanceof GrReturnStatement)) {
return false;
}
final GrReturnStatement returnStatement = (GrReturnStatement) statement;
final GrExpression returnValue = returnStatement.getReturnValue();
if (returnValue == null) {
return false;
}
final String returnValueText = returnValue.getText();
return value.equals(returnValueText);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class GroovyTrivialConditionalInspection method calculateReplacementExpression.
private static String calculateReplacementExpression(GrConditionalExpression exp) {
final GrExpression thenExpression = exp.getThenBranch();
final GrExpression elseExpression = exp.getElseBranch();
final GrExpression condition = exp.getCondition();
if (isFalse(thenExpression) && isTrue(elseExpression)) {
return BoolUtils.getNegatedExpressionText(condition);
} else {
return condition.getText();
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression in project intellij-community by JetBrains.
the class UnaryTransformation method apply.
@Override
public void apply(@NotNull GrUnaryExpression expression) {
GrExpression operand = addParenthesesIfNeeded(requireNonNull(getOperand(expression)));
GrInspectionUtil.replaceExpression(expression, format("%s.%s()", operand.getText(), myMethod));
}
Aggregations