Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jaxb
diff options
context:
space:
mode:
authorkmoore2010-10-18 13:13:59 -0400
committerkmoore2010-10-18 13:13:59 -0400
commit5c9a0d92e5afbdff331ffa209c5546d78ed9da08 (patch)
tree2e29b3f02824e0f0c2f763822dc8bc7b549c2a80 /jaxb
parent381e6d1edfb79dafd818af95463083a3dc9c458e (diff)
downloadwebtools.dali-5c9a0d92e5afbdff331ffa209c5546d78ed9da08.tar.gz
webtools.dali-5c9a0d92e5afbdff331ffa209c5546d78ed9da08.tar.xz
webtools.dali-5c9a0d92e5afbdff331ffa209c5546d78ed9da08.zip
327914 - JAXB java resource model and tests for XmlSeeAlsoAnnotation
Diffstat (limited to 'jaxb')
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java2
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlSeeAlsoAnnotationDefinition.java62
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSeeAlsoAnnotation.java97
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlSeeAlsoAnnotation.java137
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java3
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSeeAlsoAnnotation.java75
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java1
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSeeAlsoAnnotationTests.java159
8 files changed, 536 insertions, 0 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java
index 3b2af5e07b..a3d7ce2278 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java
@@ -20,6 +20,7 @@ import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlInlineBinaryDataAnnot
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlJavaTypeAdapterAnnotationDefinition;
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlJavaTypeAdaptersAnnotationDefinition;
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlRootElementAnnotationDefinition;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlSeeAlsoAnnotationDefinition;
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlTransientAnnotationDefinition;
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlTypeAnnotationDefinition;
@@ -67,6 +68,7 @@ public class GenericJaxbJpaAnnotationDefinitionProvider
definitions.add(XmlJavaTypeAdapterAnnotationDefinition.instance());
definitions.add(XmlJavaTypeAdaptersAnnotationDefinition.instance());
definitions.add(XmlRootElementAnnotationDefinition.instance());
+ definitions.add(XmlSeeAlsoAnnotationDefinition.instance());
definitions.add(XmlTransientAnnotationDefinition.instance());
definitions.add(XmlTypeAnnotationDefinition.instance());
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlSeeAlsoAnnotationDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlSeeAlsoAnnotationDefinition.java
new file mode 100644
index 0000000000..115a05eb87
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlSeeAlsoAnnotationDefinition.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal.resource.java;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.core.utility.jdt.Type;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.binary.BinaryXmlSeeAlsoAnnotation;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourceXmlSeeAlsoAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation;
+
+/**
+ * javax.xml.bind.annotation.XmlSeeAlso
+ */
+public final class XmlSeeAlsoAnnotationDefinition
+ implements AnnotationDefinition
+{
+ // singleton
+ private static final AnnotationDefinition INSTANCE = new XmlSeeAlsoAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private XmlSeeAlsoAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) {
+ return new SourceXmlSeeAlsoAnnotation((JavaResourcePersistentType) parent, (Type) annotatedElement);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
+ return new BinaryXmlSeeAlsoAnnotation((JavaResourcePersistentType) parent, jdtAnnotation);
+ }
+
+ public String getAnnotationName() {
+ return XmlSeeAlsoAnnotation.ANNOTATION_NAME;
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSeeAlsoAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSeeAlsoAnnotation.java
new file mode 100644
index 0000000000..23a18ebaa1
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlSeeAlsoAnnotation.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal.resource.java.binary;
+
+import java.util.Vector;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.utility.internal.iterables.LiveCloneListIterable;
+
+/**
+ * javax.xml.bind.annotation.XmlSeeAlso
+ */
+public final class BinaryXmlSeeAlsoAnnotation
+ extends BinaryAnnotation
+ implements XmlSeeAlsoAnnotation
+{
+ private final Vector<String> classes;
+
+
+ public BinaryXmlSeeAlsoAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) {
+ super(parent, jdtAnnotation);
+ this.classes = this.buildClasses();
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ this.updateClasses();
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.classes);
+ }
+
+
+ // ********** XmlSeeAlsoAnnotation implementation **********
+
+ // ***** value
+ public ListIterable<String> getClasses() {
+ return new LiveCloneListIterable<String>(this.classes);
+ }
+
+ public int getClassesSize() {
+ return this.classes.size();
+ }
+
+ private Vector<String> buildClasses() {
+ Object[] jdtClasses = this.getJdtMemberValues(JAXB.XML_SEE_ALSO__VALUE);
+ Vector<String> result = new Vector<String>(jdtClasses.length);
+ for (Object jdtClass : jdtClasses) {
+ result.add((String) jdtClass);
+ }
+ return result;
+ }
+
+ public void addClass(String clazz) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addClass(int index, String clazz) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void moveClass(int targetIndex, int sourceIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeClass(String clazz) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeClass(int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ // TODO
+ private void updateClasses() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlSeeAlsoAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlSeeAlsoAnnotation.java
new file mode 100644
index 0000000000..002ba690f5
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlSeeAlsoAnnotation.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.internal.resource.java.source;
+
+import java.util.Arrays;
+import java.util.Vector;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.ExpressionConverter;
+import org.eclipse.jpt.core.utility.jdt.Type;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+import org.eclipse.jpt.utility.internal.iterables.LiveCloneListIterable;
+
+/**
+ * javax.xml.bind.annotation.XmlSeeAlso
+ */
+public final class SourceXmlSeeAlsoAnnotation
+ extends SourceAnnotation<Type>
+ implements XmlSeeAlsoAnnotation
+{
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final DeclarationAnnotationElementAdapter<String[]> valueDeclarationAdapter;
+ private final AnnotationElementAdapter<String[]> valueAdapter;
+ private final Vector<String> classes = new Vector<String>();
+
+ public SourceXmlSeeAlsoAnnotation(JavaResourcePersistentType parent, Type type) {
+ super(parent, type, DECLARATION_ANNOTATION_ADAPTER);
+ this.valueDeclarationAdapter = buildArrayAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JAXB.XML_SEE_ALSO__VALUE);
+ this.valueAdapter = this.buildArrayAnnotationElementAdapter(this.valueDeclarationAdapter);
+ }
+
+ private AnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String[]> daea) {
+ return new AnnotatedElementAnnotationElementAdapter<String[]>(this.annotatedElement, daea);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.initializeClasses(astRoot);
+ }
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ this.syncClasses(astRoot);
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.classes);
+ }
+
+
+ // ********** XmlSeeAlsoAnnotation implementation **********
+
+ // ***** classes
+ public ListIterable<String> getClasses() {
+ return new LiveCloneListIterable<String>(this.classes);
+ }
+
+ public int getClassesSize() {
+ return this.classes.size();
+ }
+
+ public void addClass(String clazz) {
+ this.addClass(this.classes.size(), clazz);
+ }
+
+ public void addClass(int index, String clazz) {
+ this.classes.add(index, clazz);
+ this.writeClasses();
+ }
+
+ public void moveClass(int targetIndex, int sourceIndex) {
+ CollectionTools.move(this.classes, targetIndex, sourceIndex);
+ this.writeClasses();
+ }
+
+ public void removeClass(String prop) {
+ this.classes.remove(prop);
+ this.writeClasses();
+ }
+
+ public void removeClass(int index) {
+ this.classes.remove(index);
+ this.writeClasses();
+ }
+
+ private void writeClasses() {
+ this.valueAdapter.setValue(this.classes.toArray(new String[this.classes.size()]));
+ }
+
+ private void initializeClasses(CompilationUnit astRoot) {
+ String[] astClasses = this.valueAdapter.getValue(astRoot);
+ for (int i = 0; i < astClasses.length; i++) {
+ this.classes.add(astClasses[i]);
+ }
+ }
+
+ private void syncClasses(CompilationUnit astRoot) {
+ String[] astClasses = this.valueAdapter.getValue(astRoot);
+ this.synchronizeList(Arrays.asList(astClasses), this.classes, CLASSES_LIST);
+ }
+
+
+ //*********** static methods ****************
+
+
+ private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) {
+ return buildArrayAnnotationElementAdapter(annotationAdapter, elementName, AnnotationStringArrayExpressionConverter.forTypes());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String[]> buildArrayAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String[]> converter) {
+ return new ConversionDeclarationAnnotationElementAdapter<String[]>(annotationAdapter, elementName, false, converter);
+ }
+
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java
index f02c1f49ed..5686281b52 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java
@@ -49,6 +49,9 @@ public interface JAXB {
String XML_ROOT_ELEMENT__NAME = "name";
String XML_ROOT_ELEMENT__NAMESPACE = "namespace";
+ String XML_SEE_ALSO = PACKAGE_ + "XmlSeeAlso";
+ String XML_SEE_ALSO__VALUE = "value";
+
String XML_TYPE = PACKAGE_ + "XmlType";
String XML_TYPE__FACTORY_CLASS = "factoryClass";
String XML_TYPE__FACTORY_METHOD = "factoryMethod";
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSeeAlsoAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSeeAlsoAnnotation.java
new file mode 100644
index 0000000000..d64b416261
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlSeeAlsoAnnotation.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.resource.java;
+
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.utility.internal.iterables.ListIterable;
+
+/**
+ * Corresponds to the JAXB annotation
+ * javax.xml.bind.annotation.XmlSeeAlso
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 3.0
+ * @since 3.0
+ */
+public interface XmlSeeAlsoAnnotation
+ extends Annotation
+{
+ String ANNOTATION_NAME = JAXB.XML_SEE_ALSO;
+
+ /**
+ * Corresponds to the 'value' element of the XmlSeeAlso annotation.
+ * Return an empty iterator if the element does not exist in Java.
+ * Return the portion of the value preceding ".class".
+ * <pre>
+ * &#64;XmlSeeAlso({Foo.class, Bar.class})
+ * </pre>
+ * will return and iterable containing: "Foo", "Bar"
+ */
+ ListIterable<String> getClasses();
+ String CLASSES_LIST = "classes"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'value' element of the XmlSeeAlso annotation.
+ */
+ int getClassesSize();
+
+ /**
+ * Corresponds to the 'value' element of the XmlSeeAlso annotation.
+ */
+ void addClass(String clazz);
+
+ /**
+ * Corresponds to the 'value' element of the XmlSeeAlso annotation.
+ */
+ void addClass(int index, String clazz);
+
+ /**
+ * Corresponds to the 'value' element of the XmlSeeAlso annotation.
+ */
+ void moveClass(int targetIndex, int sourceIndex);
+
+ /**
+ * Corresponds to the 'value' element of the XmlSeeAlso annotation.
+ */
+ void removeClass(String clazz);
+
+ /**
+ * Corresponds to the 'value' element of the XmlSeeAlso annotation.
+ */
+ void removeClass(int index);
+
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java
index 8fad7c93d7..6dd0aed85c 100644
--- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java
@@ -22,6 +22,7 @@ public class JaxbJavaResourceModelTests {
suite.addTestSuite(XmlInlineBinaryDataAnnotationTests.class);
suite.addTestSuite(XmlJavaTypeAdapterAnnotationTests.class);
suite.addTestSuite(XmlRootElementAnnotationTests.class);
+ suite.addTestSuite(XmlSeeAlsoAnnotationTests.class);
suite.addTestSuite(XmlTransientAnnotationTests.class);
suite.addTestSuite(XmlTypeAnnotationTests.class);
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSeeAlsoAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSeeAlsoAnnotationTests.java
new file mode 100644
index 0000000000..145aa283d9
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSeeAlsoAnnotationTests.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.resource.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+@SuppressWarnings("nls")
+public class XmlSeeAlsoAnnotationTests extends JaxbJavaResourceModelTestCase {
+
+
+ public XmlSeeAlsoAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestXmlSeeAlso() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_SEE_ALSO);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlSeeAlso");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlSeeAlsoWithValue() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_SEE_ALSO);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlSeeAlso(value = {Foo.class, Bar.class})");
+ }
+ });
+ }
+
+
+ public void testGetNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlso();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+ assertEquals(0, xmlSeeAlsoAnnotation.getClassesSize());
+ }
+
+ public void testGetClasses() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+ ListIterator<String> classes = xmlSeeAlsoAnnotation.getClasses().iterator();
+ assertEquals("Foo", classes.next());
+ assertEquals("Bar", classes.next());
+ }
+
+ public void testGetClassesSize() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+ assertEquals(2, xmlSeeAlsoAnnotation.getClassesSize());
+ }
+
+ public void testAddClass() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlso();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+
+ xmlSeeAlsoAnnotation.addClass("Fooo");
+ xmlSeeAlsoAnnotation.addClass("Barrr");
+
+ assertSourceContains("@XmlSeeAlso({ Fooo.class, Barrr.class })", cu);
+ }
+
+ public void testAddClassIndex() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlso();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+
+ xmlSeeAlsoAnnotation.addClass(0, "Fooo");
+ xmlSeeAlsoAnnotation.addClass(0, "Barr");
+ xmlSeeAlsoAnnotation.addClass(1, "Blah");
+
+ assertSourceContains("@XmlSeeAlso({ Barr.class, Blah.class, Fooo.class })", cu);
+ }
+
+ public void testRemoveClass() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+
+ xmlSeeAlsoAnnotation.removeClass("Foo");
+ assertSourceContains("@XmlSeeAlso(value = Bar.class)", cu);
+
+ xmlSeeAlsoAnnotation.removeClass("Bar");
+ assertSourceContains("@XmlSeeAlso", cu);
+ assertSourceDoesNotContain("value", cu);
+ }
+
+ public void testRemoveClassIndex() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+
+ xmlSeeAlsoAnnotation.removeClass(0);
+ assertSourceContains("@XmlSeeAlso(value = Bar.class)", cu);
+
+ xmlSeeAlsoAnnotation.removeClass(0);
+ assertSourceContains("@XmlSeeAlso", cu);
+ assertSourceDoesNotContain("value", cu);
+ }
+
+ public void testMoveClass() throws Exception {
+ ICompilationUnit cu = this.createTestXmlSeeAlso();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) typeResource.getAnnotation(JAXB.XML_SEE_ALSO);
+ assertTrue(xmlSeeAlsoAnnotation != null);
+
+ xmlSeeAlsoAnnotation.addClass("Fooo");
+ xmlSeeAlsoAnnotation.addClass("Barr");
+ xmlSeeAlsoAnnotation.addClass("Blah");
+ assertSourceContains("@XmlSeeAlso({ Fooo.class, Barr.class, Blah.class })", cu);
+
+ xmlSeeAlsoAnnotation.moveClass(0, 1);
+ assertSourceContains("@XmlSeeAlso({ Barr.class, Fooo.class, Blah.class })", cu);
+
+ xmlSeeAlsoAnnotation.moveClass(2, 1);
+ assertSourceContains("@XmlSeeAlso({ Barr.class, Blah.class, Fooo.class })", cu);
+ }
+}

Back to the top