v4: @Override annotations, update equals to check parameter type

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9447]
This commit is contained in:
sharwell 2011-11-23 06:41:45 -08:00
parent ed7377dfd4
commit 89ebd369f9
1 changed files with 11 additions and 6 deletions

View File

@ -125,6 +125,7 @@ public class RuleContext implements ParseTree.RuleNode {
}
}
@Override
public int hashCode() {
// int h = 0;
// RuleContext p = this;
@ -188,15 +189,18 @@ public class RuleContext implements ParseTree.RuleNode {
* The hashCode is cheap as it's computed once upon each context
* push on the stack. Using it to make equals() more efficient.
*/
@Override
public boolean equals(Object o) {
RuleContext other = ((RuleContext)o);
// if ( this.cachedHashCode != other.cachedHashCode ) {
// return false; // can't be same if hash is different
// }
if ( this.hashCode() != ((RuleContext)other).hashCode() ) {
if (this == o) {
return true;
} else if (!(o instanceof RuleContext)) {
return false;
}
RuleContext other = (RuleContext)o;
if ( this.hashCode() != other.hashCode() ) {
return false; // can't be same if hash is different
}
if ( this==other ) return true;
// System.out.println("comparing "+this+" with "+other);
RuleContext sp = this;
@ -336,6 +340,7 @@ public class RuleContext implements ParseTree.RuleNode {
@Override
public String toStringTree() { return toStringTree(null); }
@Override
public String toString() {
return toString(null);
}