Skip to content

Commit

Permalink
refactor: EqualsChecker#setNotEqual can be used to debug non-equality (
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky authored and monperrus committed May 18, 2018
1 parent c79078a commit 0b12afe
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions src/main/java/spoon/support/visitor/equals/EqualsChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ public class EqualsChecker extends CtInheritanceScanner {

public void setOther(CtElement other) {
this.other = other;
isNotEqual = false;
}

public boolean isNotEqual() {
return isNotEqual;
}

private void setNotEqual() {
isNotEqual = true;
}

@Override
public void scanCtNamedElement(CtNamedElement e) {
final CtNamedElement peek = (CtNamedElement) this.other;
if (!e.getSimpleName().equals(peek.getSimpleName())) {
isNotEqual = true;
setNotEqual();
return;
}
super.scanCtNamedElement(e);
Expand All @@ -61,7 +66,7 @@ public void scanCtNamedElement(CtNamedElement e) {
public void scanCtReference(CtReference reference) {
final CtReference peek = (CtReference) this.other;
if (!reference.getSimpleName().equals(peek.getSimpleName())) {
isNotEqual = true;
setNotEqual();
return;
}
super.scanCtReference(reference);
Expand All @@ -77,7 +82,7 @@ public void scanCtStatement(CtStatement s) {
return;
}
if (leftLabel == null || !leftLabel.equals(rightLabel)) {
isNotEqual = true;
setNotEqual();
return;
}
super.scanCtStatement(s);
Expand All @@ -88,22 +93,22 @@ public void scanCtModifiable(CtModifiable m) {
final CtModifiable peek = (CtModifiable) this.other;
if (m.getVisibility() == null) {
if (peek.getVisibility() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getVisibility() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!m.getVisibility().equals(peek.getVisibility())) {
isNotEqual = true;
setNotEqual();
return;
}
if (m.getModifiers().size() != peek.getModifiers().size()) {
isNotEqual = true;
setNotEqual();
return;
}
if (!m.getModifiers().containsAll(peek.getModifiers())) {
isNotEqual = true;
setNotEqual();
return;
}
super.scanCtModifiable(m);
Expand All @@ -112,7 +117,7 @@ public void scanCtModifiable(CtModifiable m) {
@Override
public <T, A extends T> void visitCtAssignment(CtAssignment<T, A> assignment) {
if (!(assignment instanceof CtOperatorAssignment) && this.other instanceof CtOperatorAssignment) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtAssignment(assignment);
Expand All @@ -123,14 +128,14 @@ public <T, A extends T> void visitCtOperatorAssignment(CtOperatorAssignment<T, A
final CtOperatorAssignment peek = (CtOperatorAssignment) this.other;
if (assignment.getKind() == null) {
if (peek.getKind() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getKind() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!assignment.getKind().equals(peek.getKind())) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtOperatorAssignment(assignment);
Expand All @@ -141,14 +146,14 @@ public <T> void visitCtBinaryOperator(CtBinaryOperator<T> e) {
final CtBinaryOperator peek = (CtBinaryOperator) this.other;
if (e.getKind() == null) {
if (peek.getKind() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getKind() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!e.getKind().equals(peek.getKind())) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtBinaryOperator(e);
Expand All @@ -159,14 +164,14 @@ public <T> void visitCtUnaryOperator(CtUnaryOperator<T> e) {
final CtUnaryOperator peek = (CtUnaryOperator) this.other;
if (e.getKind() == null) {
if (peek.getKind() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getKind() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!e.getKind().equals(peek.getKind())) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtUnaryOperator(e);
Expand All @@ -176,7 +181,7 @@ public <T> void visitCtUnaryOperator(CtUnaryOperator<T> e) {
public <T> void visitCtArrayTypeReference(CtArrayTypeReference<T> e) {
final CtArrayTypeReference peek = (CtArrayTypeReference) this.other;
if (e.getDimensionCount() != peek.getDimensionCount()) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtArrayTypeReference(e);
Expand All @@ -187,14 +192,14 @@ public void visitCtBreak(CtBreak e) {
final CtBreak peek = (CtBreak) this.other;
if (e.getTargetLabel() == null) {
if (peek.getTargetLabel() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getTargetLabel() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!e.getTargetLabel().equals(peek.getTargetLabel())) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtBreak(e);
Expand All @@ -205,14 +210,14 @@ public void visitCtContinue(CtContinue e) {
final CtContinue peek = (CtContinue) this.other;
if (e.getTargetLabel() == null) {
if (peek.getTargetLabel() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getTargetLabel() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!e.getTargetLabel().equals(peek.getTargetLabel())) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtContinue(e);
Expand All @@ -222,7 +227,7 @@ public void visitCtContinue(CtContinue e) {
public <T> void visitCtExecutableReference(CtExecutableReference<T> e) {
final CtExecutableReference peek = (CtExecutableReference) this.other;
if (e.isConstructor() != peek.isConstructor()) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtExecutableReference(e);
Expand All @@ -232,7 +237,7 @@ public <T> void visitCtExecutableReference(CtExecutableReference<T> e) {
public <T> void visitCtMethod(CtMethod<T> e) {
final CtMethod peek = (CtMethod) this.other;
if (e.isDefaultMethod() != peek.isDefaultMethod()) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtMethod(e);
Expand All @@ -242,7 +247,7 @@ public <T> void visitCtMethod(CtMethod<T> e) {
public <T> void visitCtParameter(CtParameter<T> e) {
final CtParameter peek = (CtParameter) this.other;
if (e.isVarArgs() != peek.isVarArgs()) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtParameter(e);
Expand All @@ -253,14 +258,14 @@ public <T> void visitCtLiteral(CtLiteral<T> e) {
final CtLiteral peek = (CtLiteral) this.other;
if (e.getValue() == null) {
if (peek.getValue() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getValue() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!e.getValue().equals(peek.getValue())) {
isNotEqual = true;
setNotEqual();
return;
}
super.visitCtLiteral(e);
Expand All @@ -272,14 +277,14 @@ public void visitCtImport(CtImport ctImport) {

if (ctImport.getImportKind() == null) {
if (peek.getImportKind() != null) {
isNotEqual = true;
setNotEqual();
return;
}
} else if (peek.getImportKind() == null) {
isNotEqual = true;
setNotEqual();
return;
} else if (!ctImport.getImportKind().equals(peek.getImportKind())) {
isNotEqual = true;
setNotEqual();
return;
}

Expand Down

0 comments on commit 0b12afe

Please sign in to comment.