Bug 522488 - Enhancements in default equals/hashCode for elements
diff --git a/org.eclipse.handly.examples.basic.ui/src/org/eclipse/handly/internal/examples/basic/ui/model/FooDef.java b/org.eclipse.handly.examples.basic.ui/src/org/eclipse/handly/internal/examples/basic/ui/model/FooDef.java
index 4384fb3..ea07494 100644
--- a/org.eclipse.handly.examples.basic.ui/src/org/eclipse/handly/internal/examples/basic/ui/model/FooDef.java
+++ b/org.eclipse.handly.examples.basic.ui/src/org/eclipse/handly/internal/examples/basic/ui/model/FooDef.java
@@ -57,7 +57,7 @@
{
if (!(obj instanceof FooDef))
return false;
- return super.equals(obj) && arity == ((FooDef)obj).arity;
+ return arity == ((FooDef)obj).arity && super.equals(obj);
}
@Override
diff --git a/org.eclipse.handly/src/org/eclipse/handly/model/impl/IElementImplSupport.java b/org.eclipse.handly/src/org/eclipse/handly/model/impl/IElementImplSupport.java
index 3c39fd8..da931c2 100644
--- a/org.eclipse.handly/src/org/eclipse/handly/model/impl/IElementImplSupport.java
+++ b/org.eclipse.handly/src/org/eclipse/handly/model/impl/IElementImplSupport.java
@@ -23,6 +23,7 @@
import java.text.MessageFormat;
import java.util.Map;
+import java.util.Objects;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -71,13 +72,7 @@
*/
default int defaultHashCode_()
{
- final int prime = 31;
- int result = 1;
- IElement parent = getParent_();
- String name = getName_();
- result = prime * result + (parent == null ? 0 : parent.hashCode());
- result = prime * result + (name == null ? 0 : name.hashCode());
- return result;
+ return Objects.hash(getName_(), getParent_());
}
/**
@@ -102,30 +97,13 @@
{
if (this == obj)
return true;
- if (obj == null)
- return false;
if (!(obj instanceof IElementImplSupport))
return false;
IElementImplSupport other = (IElementImplSupport)obj;
if (!other.canEqual_(this))
return false;
- IElement parent = getParent_();
- if (parent == null)
- {
- if (other.getParent_() != null)
- return false;
- }
- else if (!parent.equals(other.getParent_()))
- return false;
- String name = getName_();
- if (name == null)
- {
- if (other.getName_() != null)
- return false;
- }
- else if (!name.equals(other.getName_()))
- return false;
- return true;
+ return Objects.equals(getName_(), other.getName_()) && Objects.equals(
+ getParent_(), other.getParent_());
}
/**
diff --git a/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceConstructImplSupport.java b/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceConstructImplSupport.java
index 125f0b5..83953fa 100644
--- a/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceConstructImplSupport.java
+++ b/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceConstructImplSupport.java
@@ -41,8 +41,8 @@
{
if (!(obj instanceof ISourceConstructImplSupport))
return false;
- return ISourceElementImplSupport.super.defaultEquals_(obj)
- && getOccurrenceCount_() == ((ISourceConstructImplSupport)obj).getOccurrenceCount_();
+ return getOccurrenceCount_() == ((ISourceConstructImplSupport)obj).getOccurrenceCount_()
+ && ISourceElementImplSupport.super.defaultEquals_(obj);
}
@Override
diff --git a/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceFileImplSupport.java b/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceFileImplSupport.java
index 8425e54..7a9d1af 100644
--- a/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceFileImplSupport.java
+++ b/org.eclipse.handly/src/org/eclipse/handly/model/impl/ISourceFileImplSupport.java
@@ -82,9 +82,9 @@
if (!(obj instanceof ISourceFileImplSupport))
return false;
IFile file = getFile_();
- return ISourceElementImplSupport.super.defaultEquals_(obj)
- && (file == null || file.equals(
- ((ISourceFileImplSupport)obj).getFile_()));
+ return (file == null || file.equals(
+ ((ISourceFileImplSupport)obj).getFile_()))
+ && ISourceElementImplSupport.super.defaultEquals_(obj);
}
/**