diff options
author | pfullbright | 2011-08-22 17:59:39 +0000 |
---|---|---|
committer | pfullbright | 2011-08-22 17:59:39 +0000 |
commit | a5bf4aef58f402f78f2830079bdd1bd4f96d8e1b (patch) | |
tree | 4ac0eba000eea43fd40c539613f6338f1d4a9e13 | |
parent | e87edc18e6f87cd25437c9c760bf2ad3bff70400 (diff) | |
download | webtools.dali-a5bf4aef58f402f78f2830079bdd1bd4f96d8e1b.tar.gz webtools.dali-a5bf4aef58f402f78f2830079bdd1bd4f96d8e1b.tar.xz webtools.dali-a5bf4aef58f402f78f2830079bdd1bd4f96d8e1b.zip |
added 'required' support to XmlElementRef annotation
6 files changed, 161 insertions, 7 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlElementRefAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlElementRefAnnotation.java index bf181bd5d7..0acdc0d616 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlElementRefAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/binary/BinaryXmlElementRefAnnotation.java @@ -26,6 +26,7 @@ public final class BinaryXmlElementRefAnnotation { private String name; private String namespace; + private Boolean required; private String type; @@ -33,6 +34,7 @@ public final class BinaryXmlElementRefAnnotation super(parent, jdtAnnotation); this.name = this.buildName(); this.namespace = this.buildNamespace(); + this.required = this.buildRequired(); this.type = this.buildType(); } @@ -45,6 +47,7 @@ public final class BinaryXmlElementRefAnnotation super.update(); this.setName_(this.buildName()); this.setNamespace_(this.buildNamespace()); + this.setRequired_(this.buildRequired()); this.setType_(this.buildType()); } @@ -109,6 +112,29 @@ public final class BinaryXmlElementRefAnnotation throw new UnsupportedOperationException(); } + // ***** required + public Boolean getRequired() { + return this.required; + } + + public void setRequired(Boolean required) { + throw new UnsupportedOperationException(); + } + + private void setRequired_(Boolean required) { + Boolean old = this.required; + this.required = required; + this.firePropertyChanged(REQUIRED_PROPERTY, old, required); + } + + private Boolean buildRequired() { + return (Boolean) this.getJdtMemberValue(JAXB.XML_ELEMENT__REQUIRED); + } + + public TextRange getRequiredTextRange(CompilationUnit astRoot) { + throw new UnsupportedOperationException(); + } + // ***** type public String getType() { return this.type; diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementAnnotation.java index e82a6931da..984ed4ac06 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementAnnotation.java @@ -370,6 +370,7 @@ public final class SourceXmlElementAnnotation * convenience implementation of method from NestableAnnotation interface * for subclasses */ + @Override public void moveAnnotation(int newIndex) { this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementRefAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementRefAnnotation.java index 09422ee9cb..4ea7f4572d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementRefAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlElementRefAnnotation.java @@ -52,6 +52,10 @@ public final class SourceXmlElementRefAnnotation private final AnnotationElementAdapter<String> namespaceAdapter; private String namespace; + private final DeclarationAnnotationElementAdapter<Boolean> requiredDeclarationAdapter; + private final AnnotationElementAdapter<Boolean> requiredAdapter; + private Boolean required; + private final DeclarationAnnotationElementAdapter<String> typeDeclarationAdapter; private final AnnotationElementAdapter<String> typeAdapter; private String type; @@ -100,6 +104,8 @@ public final class SourceXmlElementRefAnnotation this.nameAdapter = this.buildAnnotationElementAdapter(this.nameDeclarationAdapter); this.namespaceDeclarationAdapter = this.buildNamespaceDeclarationAdapter(); this.namespaceAdapter = this.buildAnnotationElementAdapter(this.namespaceDeclarationAdapter); + this.requiredDeclarationAdapter = this.buildRequiredAdapter(daa); + this.requiredAdapter = this.buildShortCircuitBooleanElementAdapter(this.requiredDeclarationAdapter); this.typeDeclarationAdapter = this.buildTypeDeclarationAdapter(); this.typeAdapter = this.buildAnnotationElementAdapter(this.typeDeclarationAdapter); } @@ -113,6 +119,10 @@ public final class SourceXmlElementRefAnnotation return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, JAXB.XML_ELEMENT_REF__NAMESPACE); } + private DeclarationAnnotationElementAdapter<Boolean> buildRequiredAdapter(DeclarationAnnotationAdapter daa) { + return ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, JAXB.XML_ELEMENT_REF__REQUIRED); + } + private DeclarationAnnotationElementAdapter<String> buildTypeDeclarationAdapter() { return buildAnnotationElementAdapter(this.daa, JAXB.XML_ELEMENT_REF__TYPE, SimpleTypeStringExpressionConverter.instance()); } @@ -125,6 +135,10 @@ public final class SourceXmlElementRefAnnotation return new AnnotatedElementAnnotationElementAdapter<String>(this.annotatedElement, daea); } + private AnnotationElementAdapter<Boolean> buildShortCircuitBooleanElementAdapter(DeclarationAnnotationElementAdapter<Boolean> daea) { + return new AnnotatedElementAnnotationElementAdapter<Boolean>(this.annotatedElement, daea); + } + public String getAnnotationName() { return ANNOTATION_NAME; } @@ -132,6 +146,7 @@ public final class SourceXmlElementRefAnnotation public void initialize(CompilationUnit astRoot) { this.name = this.buildName(astRoot); this.namespace = this.buildNamespace(astRoot); + this.required = this.buildRequired(astRoot); this.type = this.buildType(astRoot); this.fullyQualifiedTypeName = this.buildFullyQualifiedTypeName(astRoot); } @@ -139,6 +154,7 @@ public final class SourceXmlElementRefAnnotation public void synchronizeWith(CompilationUnit astRoot) { this.syncName(this.buildName(astRoot)); this.syncNamespace(this.buildNamespace(astRoot)); + this.syncRequired(this.buildRequired(astRoot)); this.syncType(this.buildType(astRoot)); this.syncFullyQualifiedTypeName(this.buildFullyQualifiedTypeName(astRoot)); } @@ -213,6 +229,32 @@ public final class SourceXmlElementRefAnnotation } + // ***** required + public Boolean getRequired() { + return this.required; + } + + public void setRequired(Boolean required) { + if (this.attributeValueHasChanged(this.required, required)) { + this.required = required; + this.requiredAdapter.setValue(required); + } + } + + private void syncRequired(Boolean astRequired) { + Boolean old = this.required; + this.required = astRequired; + this.firePropertyChanged(REQUIRED_PROPERTY, old, astRequired); + } + + private Boolean buildRequired(CompilationUnit astRoot) { + return this.requiredAdapter.getValue(astRoot); + } + + public TextRange getRequiredTextRange(CompilationUnit astRoot) { + return this.getElementTextRange(this.requiredDeclarationAdapter, astRoot); + } + // ***** type public String getType() { return this.type; @@ -261,6 +303,7 @@ public final class SourceXmlElementRefAnnotation * convenience implementation of method from NestableAnnotation interface * for subclasses */ + @Override public void moveAnnotation(int newIndex) { this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); } 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 a3b2be0c5b..37fa554d29 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 @@ -75,6 +75,7 @@ public interface JAXB { String XML_ELEMENT_REF = PACKAGE_ + "XmlElementRef"; String XML_ELEMENT_REF__NAME = "name"; String XML_ELEMENT_REF__NAMESPACE = "namespace"; + String XML_ELEMENT_REF__REQUIRED = "required"; String XML_ELEMENT_REF__TYPE = "type"; String XML_ELEMENT_REFS = PACKAGE_ + "XmlElementRefs"; diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlElementRefAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlElementRefAnnotation.java index 8979e60e17..031c1afa2d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlElementRefAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/resource/java/XmlElementRefAnnotation.java @@ -31,8 +31,42 @@ public interface XmlElementRefAnnotation String ANNOTATION_NAME = JAXB.XML_ELEMENT_REF; + + // ***** required ***** + + /** + * String associated with changes to the 'required' property of this annotation. + */ + String REQUIRED_PROPERTY = "required"; //$NON-NLS-1$ + /** - * Corresponds to the 'type' element of the XmlElementRef annotation. + * Corresponds to the 'required' element of this annotation. + * Return null if the element does not exist in Java. + */ + Boolean getRequired(); + + /** + * Corresponds to the 'required' element of this annotation. + * Set to null to remove the element. + */ + void setRequired(Boolean required); + + /** + * Return the {@link TextRange} for the 'required' element. If the element + * does not exist return the {@link TextRange} for the annotation itself. + */ + TextRange getRequiredTextRange(CompilationUnit astRoot); + + + // ***** type ***** + + /** + * String associated with changes to the 'type' property of this annotation. + */ + String TYPE_PROPERTY = "type"; //$NON-NLS-1$ + + /** + * Corresponds to the 'type' element of this annotation. * Return null if the element does not exist in Java. * Return the portion of the value preceding ".class". * <pre> @@ -41,19 +75,24 @@ public interface XmlElementRefAnnotation * will return "Foo" */ String getType(); - String TYPE_PROPERTY = "type"; //$NON-NLS-1$ - + /** - * Corresponds to the 'type' element of the XmlElementRef annotation. + * Corresponds to the 'type' element of this annotation. * Set to null to remove the element. */ void setType(String type); + /** * Return the {@link TextRange} for the 'type' element. If the element - * does not exist return the {@link TextRange} for the XmlElementRef annotation. + * does not exist return the {@link TextRange} for the annotation itself. */ TextRange getTypeTextRange(CompilationUnit astRoot); - + + /** + * String associated with changes to the 'fullyQualifiedName' property of this annotation. + */ + String FULLY_QUALIFIED_TYPE_NAME_PROPERTY = "fullyQualifiedTypeName"; //$NON-NLS-1$ + /** * Return the fully-qualified type name as resolved by the AST's bindings. * <pre> @@ -63,5 +102,4 @@ public interface XmlElementRefAnnotation * @return */ String getFullyQualifiedTypeName(); - String FULLY_QUALIFIED_TYPE_NAME_PROPERTY = "fullyQualifiedTypeName"; //$NON-NLS-1$ } diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java index 3865979b82..18eb4da02f 100644 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java +++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java @@ -71,6 +71,22 @@ public class XmlElementRefAnnotationTests }); } + private ICompilationUnit createTestXmlElementRefWithBooleanElement(final String booleanElement) throws Exception { + + return this.createTestType(new DefaultAnnotationWriter() { + + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@XmlElementRef(" + booleanElement + " = true)"); + } + }); + } + private ICompilationUnit createTestXmlElementRefWithType() throws Exception { return this.createTestType(new DefaultAnnotationWriter() { @@ -159,6 +175,35 @@ public class XmlElementRefAnnotationTests assertSourceDoesNotContain("@XmlElementRef(namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\")", cu); } + public void testGetRequired() throws Exception { + ICompilationUnit cu = this.createTestXmlElementRefWithBooleanElement("required"); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF); + + assertEquals(Boolean.TRUE, xmlElementRefAnnotation.getRequired()); + } + + public void testSetRequired() throws Exception { + ICompilationUnit cu = this.createTestXmlElementRef(); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF); + + assertNotNull(xmlElementRefAnnotation); + assertNull(xmlElementRefAnnotation.getRequired()); + + xmlElementRefAnnotation.setRequired(Boolean.FALSE); + + assertEquals(Boolean.FALSE, xmlElementRefAnnotation.getRequired()); + assertSourceContains("@XmlElementRef(required = false)", cu); + + xmlElementRefAnnotation.setRequired(null); + + assertSourceContains("@XmlElementRef", cu); + assertSourceDoesNotContain("required", cu); + } + public void testGetType() throws Exception { ICompilationUnit cu = this.createTestXmlElementRefWithType(); JavaResourceType resourceType = buildJavaResourceType(cu); |