use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyTrivialIfInspection method isSimplifiableImplicitAssignment.
public static boolean isSimplifiableImplicitAssignment(GrIfStatement ifStatement) {
if (ifStatement.getElseBranch() != null) {
return false;
}
GrStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ConditionalUtils.stripBraces(thenBranch);
final PsiElement nextStatement = PsiTreeUtil.skipSiblingsBackward(ifStatement, PsiWhiteSpace.class);
if (!(nextStatement instanceof GrStatement)) {
return false;
}
GrStatement elseBranch = (GrStatement) nextStatement;
elseBranch = ConditionalUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, "true") && ConditionalUtils.isAssignment(elseBranch, "false")) {
final GrAssignmentExpression thenExpression = (GrAssignmentExpression) thenBranch;
final GrAssignmentExpression elseExpression = (GrAssignmentExpression) elseBranch;
final IElementType thenSign = thenExpression.getOperationTokenType();
final IElementType elseSign = elseExpression.getOperationTokenType();
if (!thenSign.equals(elseSign)) {
return false;
}
final GrExpression thenLhs = thenExpression.getLValue();
final GrExpression elseLhs = elseExpression.getLValue();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs, elseLhs);
} else {
return false;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyTrivialIfInspection method isSimplifiableImplicitReturnNegated.
public static boolean isSimplifiableImplicitReturnNegated(GrIfStatement ifStatement) {
if (ifStatement.getElseBranch() != null) {
return false;
}
GrStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ConditionalUtils.stripBraces(thenBranch);
final PsiElement nextStatement = PsiTreeUtil.skipSiblingsForward(ifStatement, PsiWhiteSpace.class);
if (!(nextStatement instanceof GrStatement)) {
return false;
}
final GrStatement elseBranch = (GrStatement) nextStatement;
return ConditionalUtils.isReturn(thenBranch, "false") && ConditionalUtils.isReturn(elseBranch, "true");
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyTrivialIfInspection method isSimplifiableReturn.
public static boolean isSimplifiableReturn(GrIfStatement ifStatement) {
GrStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ConditionalUtils.stripBraces(thenBranch);
GrStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ConditionalUtils.stripBraces(elseBranch);
return ConditionalUtils.isReturn(thenBranch, "true") && ConditionalUtils.isReturn(elseBranch, "false");
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyTrivialIfInspection method isSimplifiableAssignment.
public static boolean isSimplifiableAssignment(GrIfStatement ifStatement) {
GrStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ConditionalUtils.stripBraces(thenBranch);
GrStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ConditionalUtils.stripBraces(elseBranch);
if (ConditionalUtils.isAssignment(thenBranch, "true") && ConditionalUtils.isAssignment(elseBranch, "false")) {
final GrAssignmentExpression thenExpression = (GrAssignmentExpression) thenBranch;
final GrAssignmentExpression elseExpression = (GrAssignmentExpression) elseBranch;
final IElementType thenSign = thenExpression.getOperationTokenType();
final IElementType elseSign = elseExpression.getOperationTokenType();
if (!thenSign.equals(elseSign)) {
return false;
}
final GrExpression thenLhs = thenExpression.getLValue();
final GrExpression elseLhs = elseExpression.getLValue();
return EquivalenceChecker.expressionsAreEquivalent(thenLhs, elseLhs);
} else {
return false;
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement in project intellij-community by JetBrains.
the class GroovyTrivialIfInspection method isSimplifiableReturnNegated.
public static boolean isSimplifiableReturnNegated(GrIfStatement ifStatement) {
GrStatement thenBranch = ifStatement.getThenBranch();
thenBranch = ConditionalUtils.stripBraces(thenBranch);
GrStatement elseBranch = ifStatement.getElseBranch();
elseBranch = ConditionalUtils.stripBraces(elseBranch);
return ConditionalUtils.isReturn(thenBranch, "false") && ConditionalUtils.isReturn(elseBranch, "true");
}
Aggregations