@Override public void visitIfStatement(@NotNull GrIfStatement statement) { super.visitIfStatement(statement); final GrStatement thenBranch = statement.getThenBranch(); final GrStatement elseBranch = statement.getElseBranch(); if (thenBranch == null || elseBranch == null) { return; } if (EquivalenceChecker.statementsAreEquivalent(thenBranch, elseBranch)) { registerStatementError(statement); } }
@Override public void visitSwitchStatement(GrSwitchStatement grSwitchStatement) { super.visitSwitchStatement(grSwitchStatement); final Set<GrExpression> duplicateExpressions = new HashSet<GrExpression>(); final GrCaseLabel[] labels = collectCaseLabels(grSwitchStatement); for (int i = 0; i < labels.length; i++) { final GrCaseLabel label1 = labels[i]; final GrExpression expression1 = getExpressionForCaseLabel(label1); for (int j = i + 1; j < labels.length; j++) { final GrCaseLabel label2 = labels[j]; final GrExpression expression2 = getExpressionForCaseLabel(label2); if (EquivalenceChecker.expressionsAreEquivalent(expression1, expression2)) { duplicateExpressions.add(expression1); duplicateExpressions.add(expression2); } } } for (GrExpression duplicateExpression : duplicateExpressions) { registerError(duplicateExpression); } }
public void visitAssignmentExpression(@NotNull GrAssignmentExpression assignment) { super.visitAssignmentExpression(assignment); final IElementType sign = assignment.getOperationTokenType(); if (!sign.equals(GroovyTokenTypes.mASSIGN)) { return; } final GrExpression lhs = assignment.getLValue(); final GrExpression rhs = assignment.getRValue(); if (rhs == null) { return; } if (!(rhs instanceof GrReferenceExpression) || !(lhs instanceof GrReferenceExpression)) { return; } final GrReferenceExpression rhsReference = (GrReferenceExpression) rhs; final GrReferenceExpression lhsReference = (GrReferenceExpression) lhs; final GrExpression rhsQualifier = rhsReference.getQualifierExpression(); final GrExpression lhsQualifier = lhsReference.getQualifierExpression(); if (rhsQualifier != null || lhsQualifier != null) { if (!EquivalenceChecker.expressionsAreEquivalent(rhsQualifier, lhsQualifier)) { return; } } final String rhsName = rhsReference.getReferenceName(); final String lhsName = lhsReference.getReferenceName(); if (rhsName == null || lhsName == null) { return; } if (!rhsName.equals(lhsName)) { return; } final PsiElement rhsReferent = rhsReference.resolve(); final PsiElement lhsReferent = lhsReference.resolve(); if (rhsReferent == null || lhsReferent == null || !rhsReferent.equals(lhsReferent)) { return; } registerError(assignment); }