Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GROOVY-10463: Add equals() and hashCode() methods to ImportNode
- Loading branch information
1 parent
da55697
commit 3bbb165
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ public class ImportNode extends AnnotatedNode { | |
private final String packageName; | ||
private final boolean isStar; | ||
private final boolean isStatic; | ||
private int hashCode; | ||
|
||
/** | ||
* An import of a single type, i.e. {@code import pack.Type} or {@code import pack.Type as Alias} | ||
|
@@ -147,6 +148,53 @@ public void setType(final ClassNode type) { | |
this.type = type; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if (!(o instanceof ImportNode)) | ||
return false; | ||
ImportNode imp = (ImportNode) o; | ||
if ((type == null) != (imp.type == null)) | ||
return false; | ||
if (type != null && !type.equals(imp.type)) | ||
return false; | ||
if ((alias == null) != (imp.alias == null)) | ||
return false; | ||
if (alias != null && !alias.equals(imp.alias)) | ||
return false; | ||
if ((fieldName == null) != (imp.fieldName == null)) | ||
return false; | ||
if (fieldName != null && !fieldName.equals(imp.fieldName)) | ||
return false; | ||
if ((packageName == null) != (imp.packageName == null)) | ||
return false; | ||
if (packageName != null && !packageName.equals(imp.packageName)) | ||
return false; | ||
if (isStar != imp.isStar) | ||
return false; | ||
if (isStatic != imp.isStatic) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = hashCode; | ||
This comment has been minimized.
Sorry, something went wrong.
eric-milles
Member
|
||
if (result == 0) { | ||
if (type != null) | ||
result = 31 * result + type.hashCode(); | ||
if (alias != null) | ||
result = 31 * result + alias.hashCode(); | ||
if (fieldName != null) | ||
result = 31 * result + fieldName.hashCode(); | ||
if (packageName != null) | ||
result = 31 * result + packageName.hashCode(); | ||
result = 31 * result +Boolean.hashCode(isStar); | ||
result = 31 * result +Boolean.hashCode(isStatic); | ||
hashCode = result; | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void visit(final GroovyCodeVisitor visitor) { | ||
} | ||
|
Could you just compare the toString() value? That would include alias and star and whatnot.