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
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>
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/templates/persistence/TemplatePersistenceDataTest.java28
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java60
-rw-r--r--org.eclipse.text/src/org/eclipse/text/templates/TemplatePersistenceData.java45
3 files changed, 89 insertions, 44 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/templates/persistence/TemplatePersistenceDataTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/templates/persistence/TemplatePersistenceDataTest.java
index 07719d8c1..ff98b8038 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/templates/persistence/TemplatePersistenceDataTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/templates/persistence/TemplatePersistenceDataTest.java
@@ -28,19 +28,31 @@ public class TemplatePersistenceDataTest {
@Test
public void testEquals() throws Exception {
Template template= new Template();
+
org.eclipse.text.templates.TemplatePersistenceData persistenceData1= new org.eclipse.text.templates.TemplatePersistenceData(template, false);
org.eclipse.text.templates.TemplatePersistenceData persistenceData2= new org.eclipse.text.templates.TemplatePersistenceData(template, false);
- TemplatePersistenceData deprPersistenceDataWithRef1A= new TemplatePersistenceData(persistenceData1);
- TemplatePersistenceData deprPersistenceDataWithRef1B= new TemplatePersistenceData(persistenceData1);
-
- TemplatePersistenceData deprPersistenceDataWithRef2= new TemplatePersistenceData(persistenceData2);
-
+ TemplatePersistenceData deprPersistenceData1A= new TemplatePersistenceData(persistenceData1);
+ TemplatePersistenceData deprPersistenceData1B= new TemplatePersistenceData(persistenceData1);
+ TemplatePersistenceData deprPersistenceData1X= new TemplatePersistenceData(deprPersistenceData1A);
+ TemplatePersistenceData deprPersistenceData2= new TemplatePersistenceData(persistenceData2);
TemplatePersistenceData deprPersistenceData3= new TemplatePersistenceData(template, false);
- assertTrue(deprPersistenceDataWithRef1A.equals(deprPersistenceDataWithRef1B));
- assertFalse(deprPersistenceDataWithRef1A.equals(deprPersistenceDataWithRef2));
- assertFalse(deprPersistenceDataWithRef1A.equals(deprPersistenceData3));
+ // deprecated type <-> deprecated type
+ assertTrue(deprPersistenceData1A.equals(deprPersistenceData1B));
+ assertFalse(deprPersistenceData1A.equals(deprPersistenceData2));
+ assertFalse(deprPersistenceData1A.equals(deprPersistenceData3));
assertTrue(deprPersistenceData3.equals(deprPersistenceData3));
+ assertTrue(deprPersistenceData1X.equals(deprPersistenceData1A));
+
+ // super type <-> super type
+ assertTrue(persistenceData1.equals(persistenceData1));
+ assertFalse(persistenceData1.equals(persistenceData2));
+
+ // super type <-> deprecated type
+ assertTrue(persistenceData1.equals(deprPersistenceData1A));
+ assertTrue(deprPersistenceData1A.equals(persistenceData1));
+ assertFalse(persistenceData1.equals(deprPersistenceData2));
+ assertFalse(deprPersistenceData2.equals(persistenceData1));
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java
index a87ad110f..dcfeff12b 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java
@@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.jface.text.templates.persistence;
+import java.util.UUID;
+
import org.eclipse.jface.text.templates.Template;
@@ -33,7 +35,7 @@ import org.eclipse.jface.text.templates.Template;
@Deprecated
public class TemplatePersistenceData extends org.eclipse.text.templates.TemplatePersistenceData {
- org.eclipse.text.templates.TemplatePersistenceData ref;
+ private final org.eclipse.text.templates.TemplatePersistenceData ref;
/**
* In some cases, we must continue to respect the deprecated TemplatePresistenceData
@@ -45,99 +47,85 @@ public class TemplatePersistenceData extends org.eclipse.text.templates.Template
*/
public TemplatePersistenceData(org.eclipse.text.templates.TemplatePersistenceData data) {
super(data.getTemplate(), data.isEnabled(), data.getId()); // these are ignored
- this.ref= data;
+ this.ref= data instanceof TemplatePersistenceData ? ((TemplatePersistenceData) data).ref : data; // no double wrapping
}
public TemplatePersistenceData(Template template, boolean enabled) {
- super(template, enabled);
+ this(new org.eclipse.text.templates.TemplatePersistenceData(template, enabled));
}
public TemplatePersistenceData(Template template, boolean enabled, String id) {
- super(template, enabled, id);
+ this(new org.eclipse.text.templates.TemplatePersistenceData(template, enabled, id));
}
@Override
public String getId() {
- return (ref != null) ? ref.getId() : super.getId();
+ return ref.getId();
}
@Override
public boolean isDeleted() {
- return (ref != null) ? ref.isDeleted() : super.isDeleted();
+ return ref.isDeleted();
}
@Override
public void setDeleted(boolean isDeleted) {
- if (ref != null) {
- ref.setDeleted(isDeleted);
- } else {
- super.setDeleted(isDeleted);
- }
+ ref.setDeleted(isDeleted);
}
@Override
public Template getTemplate() {
- return (ref != null) ? ref.getTemplate() : super.getTemplate();
+ return ref.getTemplate();
}
@Override
public void setTemplate(Template template) {
- if (ref != null) {
- ref.setTemplate(template);
- } else {
- super.setTemplate(template);
- }
+ ref.setTemplate(template);
}
@Override
public boolean isCustom() {
- return (ref != null) ? ref.isCustom() : super.isCustom();
+ return ref.isCustom();
}
@Override
public boolean isModified() {
- return (ref != null) ? ref.isModified() : super.isModified();
+ return ref.isModified();
}
@Override
public boolean isUserAdded() {
- return (ref != null) ? ref.isUserAdded() : super.isUserAdded();
+ return ref.isUserAdded();
}
@Override
public void revert() {
- if (ref != null) {
- ref.revert();
- } else {
- super.revert();
- }
+ ref.revert();
}
@Override
public boolean isEnabled() {
- return (ref != null) ? ref.isEnabled() : super.isEnabled();
+ return ref.isEnabled();
}
@Override
public void setEnabled(boolean isEnabled) {
- if (ref != null) {
- ref.setEnabled(isEnabled);
- } else {
- super.setEnabled(isEnabled);
- }
+ ref.setEnabled(isEnabled);
}
@Override
public boolean equals(Object other) {
- if (ref != null && other instanceof TemplatePersistenceData && ((TemplatePersistenceData) other).ref != null) {
- return ref.equals(((TemplatePersistenceData) other).ref);
- }
- return super.equals(other);
+ return ref.equals(other);
}
@Override
public int hashCode() {
- return (ref != null) ? ref.hashCode() : super.hashCode();
+ return ref.hashCode();
+ }
+
+ @Override
+ protected UUID getUniqueIdForEquals() {
+ return getUniqueIdForEquals(ref);
}
}
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