538804: add method for copying attributes
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=538804
Change-Id: Iec35b74b42ea387766dd865d7de12b167edb6180
diff --git a/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/Attributes.java b/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/Attributes.java
index c7b5b38..0d0662e 100644
--- a/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/Attributes.java
+++ b/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/Attributes.java
@@ -13,6 +13,8 @@
package org.eclipse.mylyn.wikitext.parser;
+import static com.google.common.base.Preconditions.checkNotNull;
+
/**
* Attributes for a markup element. Note that though there are many specialized subclasses of this class, they are
* optional.
@@ -112,6 +114,20 @@
}
/**
+ * Copies the value of these attributes into the other attributes.
+ *
+ * @since 3.0.26
+ */
+ public void copyInto(Attributes other) {
+ checkNotNull(other);
+ other.setId(getId());
+ other.setCssClass(getCssClass());
+ other.setCssStyle(getCssStyle());
+ other.setLanguage(getLanguage());
+ other.setTitle(getTitle());
+ }
+
+ /**
*
*/
@Override
diff --git a/wikitext/core/org.eclipse.mylyn.wikitext/src/test/java/org/eclipse/mylyn/wikitext/parser/AttributesTest.java b/wikitext/core/org.eclipse.mylyn.wikitext/src/test/java/org/eclipse/mylyn/wikitext/parser/AttributesTest.java
index 426f23a..89045af 100644
--- a/wikitext/core/org.eclipse.mylyn.wikitext/src/test/java/org/eclipse/mylyn/wikitext/parser/AttributesTest.java
+++ b/wikitext/core/org.eclipse.mylyn.wikitext/src/test/java/org/eclipse/mylyn/wikitext/parser/AttributesTest.java
@@ -16,14 +16,13 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import org.eclipse.mylyn.wikitext.parser.Attributes;
import org.junit.Test;
public class AttributesTest {
@Test
public void testClone() {
- Attributes original = new Attributes("1", "class", "style", "lang");
+ Attributes original = createAttributesWithPopulatedValues();
Attributes copy = original.clone();
assertNotNull(copy);
assertEquals(original.getId(), copy.getId());
@@ -31,4 +30,24 @@
assertEquals(original.getCssStyle(), copy.getCssStyle());
assertEquals(original.getLanguage(), copy.getLanguage());
}
+
+ @Test
+ public void copyInto() {
+ Attributes original = createAttributesWithPopulatedValues();
+ Attributes other = new Attributes();
+ original.copyInto(other);
+ assertValuesEqual(original, other);
+ }
+
+ private void assertValuesEqual(Attributes original, Attributes other) {
+ assertEquals(original.getId(), other.getId());
+ assertEquals(original.getCssClass(), other.getCssClass());
+ assertEquals(original.getCssStyle(), other.getCssStyle());
+ assertEquals(original.getLanguage(), other.getLanguage());
+ assertEquals(original.getTitle(), other.getTitle());
+ }
+
+ private Attributes createAttributesWithPopulatedValues() {
+ return new Attributes("1", "class", "style", "lang");
+ }
}