diff options
Diffstat (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlJavaTypeAdapterAnnotation.java')
-rw-r--r-- | jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlJavaTypeAdapterAnnotation.java | 130 |
1 files changed, 91 insertions, 39 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlJavaTypeAdapterAnnotation.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlJavaTypeAdapterAnnotation.java index 3d18724557..bf6a5cf32e 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlJavaTypeAdapterAnnotation.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/java/source/SourceXmlJavaTypeAdapterAnnotation.java @@ -46,15 +46,19 @@ public final class SourceXmlJavaTypeAdapterAnnotation private final DeclarationAnnotationElementAdapter<String> valueDeclarationAdapter; private final AnnotationElementAdapter<String> valueAdapter; private String value; - private String fullyQualifiedValue; - - + + private final DeclarationAnnotationElementAdapter<String> typeDeclarationAdapter; + private final AnnotationElementAdapter<String> typeAdapter; + private String type; + private String fullyQualifiedType; + + // ********** constructors ********** public SourceXmlJavaTypeAdapterAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement element) { this(parent, element, DECLARATION_ANNOTATION_ADAPTER, new ElementAnnotationAdapter(element, DECLARATION_ANNOTATION_ADAPTER)); } - + /** * Parent is a JavaResourceNode instead of a JavaResourceAnnotatedElement because * the parent is sometimes the outer annotation XmlJavaTypeAdaptersAnnotation @@ -63,96 +67,145 @@ public final class SourceXmlJavaTypeAdapterAnnotation super(parent, element, daa, annotationAdapter); this.valueDeclarationAdapter = buildValueAdapter(daa); this.valueAdapter = this.buildAnnotationElementAdapter(this.valueDeclarationAdapter); + this.typeDeclarationAdapter = buildTypeAdapter(daa); + this.typeAdapter = this.buildAnnotationElementAdapter(this.typeDeclarationAdapter); } - + private DeclarationAnnotationElementAdapter<String> buildValueAdapter(DeclarationAnnotationAdapter daa) { return buildAnnotationElementAdapter(daa, JAXB.XML_JAVA_TYPE_ADAPTER__VALUE, SimpleTypeStringExpressionConverter.instance()); } - + + private DeclarationAnnotationElementAdapter<String> buildTypeAdapter(DeclarationAnnotationAdapter daa) { + return buildAnnotationElementAdapter(daa, JAXB.XML_JAVA_TYPE_ADAPTER__TYPE, SimpleTypeStringExpressionConverter.instance()); + } + static DeclarationAnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName, ExpressionConverter<String> converter) { return new ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter, elementName, false, converter); } - + protected AnnotationElementAdapter<String> buildAnnotationElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { return new AnnotatedElementAnnotationElementAdapter<String>(this.annotatedElement, daea); } - + public String getAnnotationName() { return ANNOTATION_NAME; } - + public void initialize(CompilationUnit astRoot) { - this.value = this.buildValue(astRoot); - this.fullyQualifiedValue = this.buildFullyQualifiedValue(astRoot); + this.value = buildValue(astRoot); + this.fullyQualifiedValue = buildFullyQualifiedValue(astRoot); + this.type = buildType(astRoot); + this.fullyQualifiedType = buildFullyQualifiedType(astRoot); } - + public void synchronizeWith(CompilationUnit astRoot) { - this.syncValue(this.buildValue(astRoot)); - this.syncFullyQualifiedValue(this.buildFullyQualifiedValue(astRoot)); + syncValue(buildValue(astRoot)); + syncFullyQualifiedValue(buildFullyQualifiedValue(astRoot)); + syncType(buildType(astRoot)); + syncFullyQualifiedType(buildFullyQualifiedType(astRoot)); } - + @Override public void toString(StringBuilder sb) { sb.append(this.value); } - - + + // ********** XmlJavaTypeAdapterAnnotation implementation ********** - + // ***** value public String getValue() { return this.value; } - + public void setValue(String value) { if (this.attributeValueHasChanged(this.value, value)) { this.value = value; this.valueAdapter.setValue(value); } } - + private void syncValue(String astValue) { String old = this.value; this.value = astValue; this.firePropertyChanged(VALUE_PROPERTY, old, astValue); } - + private String buildValue(CompilationUnit astRoot) { return this.valueAdapter.getValue(astRoot); } - + public TextRange getValueTextRange(CompilationUnit astRoot) { return this.getElementTextRange(this.valueDeclarationAdapter, astRoot); } - - // ***** fully-qualified value class name + public String getFullyQualifiedValue() { return this.fullyQualifiedValue; } - + private void syncFullyQualifiedValue(String name) { String old = this.fullyQualifiedValue; this.fullyQualifiedValue = name; this.firePropertyChanged(FULLY_QUALIFIED_VALUE_PROPERTY, old, name); } - + private String buildFullyQualifiedValue(CompilationUnit astRoot) { return (this.value == null) ? null : ASTTools.resolveFullyQualifiedName(this.valueAdapter.getExpression(astRoot)); } - - + + // ***** type + public String getType() { + return this.type; + } + + public void setType(String type) { + if (this.attributeValueHasChanged(this.type, type)) { + this.type = type; + this.typeAdapter.setValue(type); + } + } + + private void syncType(String astType) { + String old = this.type; + this.type = astType; + this.firePropertyChanged(TYPE_PROPERTY, old, astType); + } + + private String buildType(CompilationUnit astRoot) { + return this.typeAdapter.getValue(astRoot); + } + + public TextRange getTypeTextRange(CompilationUnit astRoot) { + return this.getElementTextRange(this.typeDeclarationAdapter, astRoot); + } + + public String getFullyQualifiedType() { + return this.fullyQualifiedType; + } + + private void syncFullyQualifiedType(String name) { + String old = this.fullyQualifiedType; + this.fullyQualifiedType = name; + this.firePropertyChanged(FULLY_QUALIFIED_TYPE_PROPERTY, old, name); + } + + private String buildFullyQualifiedType(CompilationUnit astRoot) { + return (this.type == null) ? null : ASTTools.resolveFullyQualifiedName(this.typeAdapter.getExpression(astRoot)); + } + + //*********** NestableAnnotation implementation **************** - - + /** * convenience implementation of method from NestableAnnotation interface * for subclasses */ public void initializeFrom(NestableAnnotation oldAnnotation) { XmlJavaTypeAdapterAnnotation oldJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) oldAnnotation; - this.setValue(oldJavaTypeAdapterAnnotation.getValue()); + setValue(oldJavaTypeAdapterAnnotation.getValue()); + setType(oldJavaTypeAdapterAnnotation.getType()); } - + /** * convenience implementation of method from NestableAnnotation interface * for subclasses @@ -160,23 +213,22 @@ public final class SourceXmlJavaTypeAdapterAnnotation public void moveAnnotation(int newIndex) { this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); } - + private IndexedAnnotationAdapter getIndexedAnnotationAdapter() { return (IndexedAnnotationAdapter) this.annotationAdapter; } - - + + // ********** static methods ********** - + static SourceXmlJavaTypeAdapterAnnotation createNestedXmlJavaTypeAdapterAnnotation(JavaResourceNode parent, AnnotatedElement annotatedElement, int index, DeclarationAnnotationAdapter javaTypeAdaptersAdapter) { IndexedDeclarationAnnotationAdapter idaa = buildNestedDeclarationAnnotationAdapter(index, javaTypeAdaptersAdapter); IndexedAnnotationAdapter annotationAdapter = new ElementIndexedAnnotationAdapter(annotatedElement, idaa); - + return new SourceXmlJavaTypeAdapterAnnotation(parent, annotatedElement, idaa, annotationAdapter); } - + private static IndexedDeclarationAnnotationAdapter buildNestedDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter javaTypeAdaptersAdapter) { return new NestedIndexedDeclarationAnnotationAdapter(javaTypeAdaptersAdapter, index, JAXB.XML_JAVA_TYPE_ADAPTER); } - } |