Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Ratz2018-09-23 11:22:26 -0400
committerAndrey Loskutov2018-09-23 12:36:46 -0400
commit542f40e5776d928308fc6443fe6293463e2b5483 (patch)
tree211f3902148d42c72616b93cdc16325e8515a9c7 /org.eclipse.text
parentbb4abd131785dc66b2a4da321ded042fd4e37db1 (diff)
downloadeclipse.platform.text-542f40e5776d928308fc6443fe6293463e2b5483.tar.gz
eclipse.platform.text-542f40e5776d928308fc6443fe6293463e2b5483.tar.xz
eclipse.platform.text-542f40e5776d928308fc6443fe6293463e2b5483.zip
Bug 535964 - Move some non UI classes from jface.text to o.e.text.I20180923-1800
Another update to the #equals() implementation. bb4abd131785dc66b2a4da321ded042fd4e37db1 broke equals() in other scenarios. A = org.eclipse.text.templates.TemplatePersistenceData B = org.eclipse.jface.text.templates.persistence.TemplatePersistenceData Properly implement equals() in the super class (A) and in the deprecated subclass (B), such that the symmetric property of equals holds: A.equals(B) B.equals(A) This is ensured by always using B as a dummy and delegating via "ref". In the super type A introduce a new dummy UUID just for equals. This simulates the previous object identity semantics for equals (there can exist multiple *different* templates with identical values). Change-Id: Ia34e7019a54464b6f4d95521eddea8e682e87bf1 Signed-off-by: Sebastian Ratz <sebastian.ratz@sap.com>
Diffstat (limited to 'org.eclipse.text')
-rw-r--r--org.eclipse.text/src/org/eclipse/text/templates/TemplatePersistenceData.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/org.eclipse.text/src/org/eclipse/text/templates/TemplatePersistenceData.java b/org.eclipse.text/src/org/eclipse/text/templates/TemplatePersistenceData.java
index 68f92d68d..434fdd144 100644
--- a/org.eclipse.text/src/org/eclipse/text/templates/TemplatePersistenceData.java
+++ b/org.eclipse.text/src/org/eclipse/text/templates/TemplatePersistenceData.java
@@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.text.templates;
+import java.util.Objects;
+import java.util.UUID;
+
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.templates.Template;
@@ -40,6 +43,11 @@ public class TemplatePersistenceData {
private boolean fIsDeleted= false;
private boolean fCustomIsEnabled= true;
+ /*
+ * Required to support equals() with deprecated type org.eclipse.jface.text.templates.persistence.TemplatePersistenceData.
+ */
+ private final UUID uniqueIdForEquals = UUID.randomUUID();
+
/**
* Creates a new, user-added instance that is not linked to a contributed
* template.
@@ -180,4 +188,41 @@ public class TemplatePersistenceData {
public void setEnabled(boolean isEnabled) {
fCustomIsEnabled= isEnabled;
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(uniqueIdForEquals);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof TemplatePersistenceData)) {
+ return false;
+ }
+ TemplatePersistenceData other= (TemplatePersistenceData) obj;
+ return Objects.equals(uniqueIdForEquals, other.getUniqueIdForEquals());
+ }
+
+ /**
+ * Required to support equals() with deprecated type org.eclipse.jface.text.templates.persistence.TemplatePersistenceData.
+ * @return unique id to support {@link #equals(Object)}
+ * @since 3.8
+ */
+ protected UUID getUniqueIdForEquals() {
+ return uniqueIdForEquals;
+ }
+
+ /**
+ * Required to support equals() with deprecated type org.eclipse.jface.text.templates.persistence.TemplatePersistenceData.
+ * @param data non null
+ * @return unique id to support {@link #equals(Object)}
+ * @since 3.8
+ */
+ protected static final UUID getUniqueIdForEquals(TemplatePersistenceData data) {
+ return data.getUniqueIdForEquals();
+ }
+
}

Back to the top