Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-10-15 11:01:09 -0400
committerkmoore2010-10-15 11:01:09 -0400
commit592832b180b5477783c5ae2517aec4b18cd8d2f1 (patch)
tree6611553e56ddcb00115ad48f0e378caf60126d7d
parent2558013860b9d8e75413e3aca9e0fd26263da1c6 (diff)
downloadwebtools.dali-592832b180b5477783c5ae2517aec4b18cd8d2f1.tar.gz
webtools.dali-592832b180b5477783c5ae2517aec4b18cd8d2f1.tar.xz
webtools.dali-592832b180b5477783c5ae2517aec4b18cd8d2f1.zip
JAXB java resource model and tests for XmlAccessorType
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/GenericJaxbJpaAnnotationDefinitionProvider.java24
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlAccessorTypeAnnotationDefinition.java60
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlAccessorTypeAnnotation.java72
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlAccessorTypeAnnotation.java100
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/JAXB.java12
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessType.java66
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessorTypeAnnotation.java53
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java3
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypeAnnotationTests.java105
9 files changed, 485 insertions, 10 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 5eaa416a4e..87a4e79bff 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
@@ -13,6 +13,7 @@ import java.util.List;
import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider;
import org.eclipse.jpt.core.internal.AbstractJpaAnnotationDefintionProvider;
import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlAccessorTypeAnnotationDefinition;
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlEnumAnnotationDefinition;
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlRootElementAnnotationDefinition;
import org.eclipse.jpt.jaxb.core.internal.resource.java.XmlTransientAnnotationDefinition;
@@ -27,41 +28,46 @@ public class GenericJaxbJpaAnnotationDefinitionProvider
// singleton
private static final JpaAnnotationDefinitionProvider INSTANCE =
new GenericJaxbJpaAnnotationDefinitionProvider();
-
-
+
+
/**
* Return the singleton
*/
public static JpaAnnotationDefinitionProvider instance() {
return INSTANCE;
}
-
-
+
+
/**
* Enforce singleton usage
*/
private GenericJaxbJpaAnnotationDefinitionProvider() {
super();
}
-
-
+
+
+ @Override
+ protected void addPackageAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
+ definitions.add(XmlAccessorTypeAnnotationDefinition.instance());
+ }
+
@Override
protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
+ definitions.add(XmlAccessorTypeAnnotationDefinition.instance());
definitions.add(XmlEnumAnnotationDefinition.instance());
definitions.add(XmlRootElementAnnotationDefinition.instance());
definitions.add(XmlTransientAnnotationDefinition.instance());
definitions.add(XmlTypeAnnotationDefinition.instance());
}
-
+
@Override
protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
definitions.add(XmlTransientAnnotationDefinition.instance());
definitions.add(XmlTypeAnnotationDefinition.instance());
}
-
+
@Override
protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) {
definitions.add(XmlTransientAnnotationDefinition.instance());
}
-
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlAccessorTypeAnnotationDefinition.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlAccessorTypeAnnotationDefinition.java
new file mode 100644
index 0000000000..937a9a883e
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/XmlAccessorTypeAnnotationDefinition.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.utility.jdt.AnnotatedElement;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.binary.BinaryXmlAccessorTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourceXmlAccessorTypeAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation;
+
+/**
+ * javax.xml.bind.annotation.XmlAccessorType
+ */
+public final class XmlAccessorTypeAnnotationDefinition
+ implements AnnotationDefinition
+{
+ // singleton
+ private static final AnnotationDefinition INSTANCE = new XmlAccessorTypeAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private XmlAccessorTypeAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) {
+ return new SourceXmlAccessorTypeAnnotation(parent, annotatedElement);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourceAnnotatedElement parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
+ return new BinaryXmlAccessorTypeAnnotation(parent, jdtAnnotation);
+ }
+
+ public String getAnnotationName() {
+ return XmlAccessorTypeAnnotation.ANNOTATION_NAME;
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlAccessorTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlAccessorTypeAnnotation.java
new file mode 100644
index 0000000000..5bec974962
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlAccessorTypeAnnotation.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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 org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation;
+import org.eclipse.jpt.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation;
+
+/**
+ * javax.xml.bind.annotation.XmlAccessorType
+ */
+public final class BinaryXmlAccessorTypeAnnotation
+ extends BinaryAnnotation
+ implements XmlAccessorTypeAnnotation
+{
+ private XmlAccessType value;
+
+
+ public BinaryXmlAccessorTypeAnnotation(JavaResourceAnnotatedElement parent, IAnnotation jdtAnnotation) {
+ super(parent, jdtAnnotation);
+ this.value = this.buildValue();
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ public void update() {
+ super.update();
+ this.setValue_(this.buildValue());
+ }
+
+
+ //*************** XmlAccessorTypeAnnotation implementation ****************
+
+ // ***** value
+ public XmlAccessType getValue() {
+ return this.value;
+ }
+
+ public void setValue(XmlAccessType value) {
+ throw new UnsupportedOperationException();
+ }
+
+ private void setValue_(XmlAccessType value) {
+ XmlAccessType old = this.value;
+ this.value = value;
+ this.firePropertyChanged(VALUE_PROPERTY, old, value);
+ }
+
+ private XmlAccessType buildValue() {
+ return XmlAccessType.fromJavaAnnotationValue(this.getJdtMemberValue(JAXB.XML_ACCESSOR_TYPE__VALUE));
+ }
+
+ public TextRange getValueTextRange(CompilationUnit astRoot) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlAccessorTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlAccessorTypeAnnotation.java
new file mode 100644
index 0000000000..95e40c5401
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlAccessorTypeAnnotation.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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 org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.resource.java.JavaResourceAnnotatedElement;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotatedElement;
+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.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation;
+
+/**
+ * javax.xml.bind.annotation.XmlAccessorType
+ */
+public final class SourceXmlAccessorTypeAnnotation
+ extends SourceAnnotation<AnnotatedElement>
+ implements XmlAccessorTypeAnnotation
+{
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter();
+ private final AnnotationElementAdapter<String> valueAdapter;
+ private XmlAccessType value;
+
+
+ public SourceXmlAccessorTypeAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement) {
+ super(parent, annotatedElement, DECLARATION_ANNOTATION_ADAPTER);
+ this.valueAdapter = new AnnotatedElementAnnotationElementAdapter<String>(annotatedElement, VALUE_ADAPTER);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.value = this.buildValue(astRoot);
+ }
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ this.syncValue(this.buildValue(astRoot));
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.value);
+ }
+
+
+ //*************** XmlAccessorTypeAnnotation implementation ****************
+
+ // ***** value
+ public XmlAccessType getValue() {
+ return this.value;
+ }
+
+ public void setValue(XmlAccessType value) {
+ if (this.attributeValueHasChanged(this.value, value)) {
+ this.value = value;
+ this.valueAdapter.setValue(XmlAccessType.toJavaAnnotationValue(value));
+ }
+ }
+
+ private void syncValue(XmlAccessType astValue) {
+ XmlAccessType old = this.value;
+ this.value = astValue;
+ this.firePropertyChanged(VALUE_PROPERTY, old, astValue);
+ }
+
+ private XmlAccessType buildValue(CompilationUnit astRoot) {
+ return XmlAccessType.fromJavaAnnotationValue(this.valueAdapter.getValue(astRoot));
+ }
+
+ public TextRange getValueTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(VALUE_ADAPTER, astRoot);
+ }
+
+
+ // ********** static methods **********
+
+ private static DeclarationAnnotationElementAdapter<String> buildValueAdapter() {
+ //remove the XmlAccessorType annotation when the value element is removed.
+ return new EnumDeclarationAnnotationElementAdapter(DECLARATION_ANNOTATION_ADAPTER, JAXB.XML_ACCESSOR_TYPE__VALUE);
+ }
+
+}
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 523ffbe321..e430e55d71 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
@@ -33,6 +33,9 @@ public interface JAXB {
// JAXB annotations
+ String XML_ACCESSOR_TYPE = PACKAGE_ + "XmlAccessorType";
+ String XML_ACCESSOR_TYPE__VALUE = "value";
+
String XML_ENUM = PACKAGE_ + "XmlEnum";
String XML_ENUM__VALUE = "value";
@@ -49,4 +52,13 @@ public interface JAXB {
String XML_TRANSIENT = PACKAGE_ + "XmlTransient";
+ // JAXB enums
+
+ String XML_ACCESS_TYPE = PACKAGE_ + "XmlAccessType";
+ String XML_ACCESS_TYPE_ = XML_ACCESS_TYPE + '.';
+ String XML_ACCESS_TYPE__FIELD = XML_ACCESS_TYPE_ + "FIELD";
+ String XML_ACCESS_TYPE__NONE = XML_ACCESS_TYPE_ + "NONE";
+ String XML_ACCESS_TYPE__PROPERTY = XML_ACCESS_TYPE_ + "PROPERTY";
+ String XML_ACCESS_TYPE__PUBLIC_MEMBER = XML_ACCESS_TYPE_ + "PUBLIC_MEMBER";
+
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessType.java
new file mode 100644
index 0000000000..c3b3bd0967
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessType.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Corresponds to the JAXB enum
+ * javax.xml.bind.annotation.XmlAccessType
+ * <p>
+ * 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 enum XmlAccessType {
+
+ FIELD(JAXB.XML_ACCESS_TYPE__FIELD),
+ NONE(JAXB.XML_ACCESS_TYPE__NONE),
+ PROPERTY(JAXB.XML_ACCESS_TYPE__PROPERTY),
+ PUBLIC_MEMBER(JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER);
+
+
+ private String javaAnnotationValue;
+
+ XmlAccessType(String javaAnnotationValue) {
+ if (javaAnnotationValue == null) {
+ throw new NullPointerException();
+ }
+ this.javaAnnotationValue = javaAnnotationValue;
+ }
+
+ public String getJavaAnnotationValue() {
+ return this.javaAnnotationValue;
+ }
+
+
+ // ********** static methods **********
+
+ public static XmlAccessType fromJavaAnnotationValue(Object javaAnnotationValue) {
+ return (javaAnnotationValue == null) ? null : fromJavaAnnotationValue_(javaAnnotationValue);
+ }
+
+ private static XmlAccessType fromJavaAnnotationValue_(Object javaAnnotationValue) {
+ for (XmlAccessType accessType : XmlAccessType.values()) {
+ if (accessType.getJavaAnnotationValue().equals(javaAnnotationValue)) {
+ return accessType;
+ }
+ }
+ return null;
+ }
+
+ public static String toJavaAnnotationValue(XmlAccessType accessType) {
+ return (accessType == null) ? null : accessType.getJavaAnnotationValue();
+ }
+
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessorTypeAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessorTypeAnnotation.java
new file mode 100644
index 0000000000..6e4eb53075
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlAccessorTypeAnnotation.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * Corresponds to the JAXB annotation
+ * javax.xml.bind.annotation.XmlAccessorType
+ *
+ * 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 XmlAccessorTypeAnnotation
+ extends Annotation
+{
+ String ANNOTATION_NAME = JAXB.XML_ACCESSOR_TYPE;
+
+ /**
+ * Corresponds to the 'value' element of the XmlAccessorType annotation.
+ * Return null if the element does not exist in Java.
+ */
+ XmlAccessType getValue();
+ String VALUE_PROPERTY = "value"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'value' element of the XmlAccessorType annotation.
+ * Set to null to remove the element.
+ */
+ void setValue(XmlAccessType value);
+
+ /**
+ * Return the {@link TextRange} for the 'value' element. If the element
+ * does not exist return the {@link TextRange} for the XmlAccessorType annotation.
+ */
+ TextRange getValueTextRange(CompilationUnit astRoot);
+
+}
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 5378188050..33ea5c3ebd 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
@@ -16,11 +16,12 @@ public class JaxbJavaResourceModelTests {
public static Test suite() {
TestSuite suite = new TestSuite(JaxbJavaResourceModelTests.class.getName());
+ suite.addTestSuite(XmlAccessorTypeAnnotationTests.class);
suite.addTestSuite(XmlEnumAnnotationTests.class);
suite.addTestSuite(XmlRootElementAnnotationTests.class);
suite.addTestSuite(XmlTransientAnnotationTests.class);
suite.addTestSuite(XmlTypeAnnotationTests.class);
-
+
return suite;
}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypeAnnotationTests.java
new file mode 100644
index 0000000000..6afb03b6f6
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypeAnnotationTests.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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 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.XmlAccessType;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+@SuppressWarnings("nls")
+public class XmlAccessorTypeAnnotationTests extends JaxbJavaResourceModelTestCase {
+
+ public XmlAccessorTypeAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestXmlAccessorType() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ACCESSOR_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlAccessorType");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlAccessorTypeWithValue() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_ACCESSOR_TYPE, JAXB.XML_ACCESS_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlAccessorType(value = XmlAccessType.FIELD)");
+ }
+ });
+ }
+
+ public void testGetNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlAccessorType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) typeResource.getAnnotation(JAXB.XML_ACCESSOR_TYPE);
+ assertTrue(xmlAccessorTypeAnnotation != null);
+ assertNull(xmlAccessorTypeAnnotation.getValue());
+ }
+
+ public void testGetValue() throws Exception {
+ ICompilationUnit cu = this.createTestXmlAccessorTypeWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) typeResource.getAnnotation(JAXB.XML_ACCESSOR_TYPE);
+ assertEquals(XmlAccessType.FIELD, xmlAccessorTypeAnnotation.getValue());
+ }
+
+ public void testSetValue() throws Exception {
+ ICompilationUnit cu = this.createTestXmlAccessorType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) typeResource.getAnnotation(JAXB.XML_ACCESSOR_TYPE);
+ assertEquals(null, xmlAccessorTypeAnnotation.getValue());
+
+ xmlAccessorTypeAnnotation.setValue(XmlAccessType.PUBLIC_MEMBER);
+ assertEquals(XmlAccessType.PUBLIC_MEMBER, xmlAccessorTypeAnnotation.getValue());
+
+ assertSourceContains("@XmlAccessorType(PUBLIC_MEMBER)", cu);
+
+ xmlAccessorTypeAnnotation.setValue(XmlAccessType.PROPERTY);
+ assertEquals(XmlAccessType.PROPERTY, xmlAccessorTypeAnnotation.getValue());
+
+ assertSourceContains("@XmlAccessorType(PROPERTY)", cu);
+
+ xmlAccessorTypeAnnotation.setValue(XmlAccessType.NONE);
+ assertEquals(XmlAccessType.NONE, xmlAccessorTypeAnnotation.getValue());
+
+ assertSourceContains("@XmlAccessorType(NONE)", cu);
+ }
+
+ public void testSetValueNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlAccessorTypeWithValue();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) typeResource.getAnnotation(JAXB.XML_ACCESSOR_TYPE);
+ assertEquals(XmlAccessType.FIELD, xmlAccessorTypeAnnotation.getValue());
+
+ xmlAccessorTypeAnnotation.setValue(null);
+ assertNull(xmlAccessorTypeAnnotation.getValue());
+
+ assertSourceDoesNotContain("@XmlAccessorType", cu);
+ }
+}

Back to the top