diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core')
106 files changed, 2075 insertions, 1711 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java index 73fc9d6d80..91128f8036 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java @@ -9,7 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.core; -import java.util.ListIterator; +import java.util.Iterator; import org.eclipse.jpt.core.resource.java.AnnotationDefinition; /** @@ -22,34 +22,20 @@ import org.eclipse.jpt.core.resource.java.AnnotationDefinition; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. * - * @version 2.2 + * @version 3.0 * @since 2.2 */ -public interface JpaAnnotationDefinitionProvider { - +public interface JpaAnnotationDefinitionProvider +{ /** - * Return a ListIterator of mapping annotation definitions which can + * Return a ListIterator of all annotation definitions which can * be placed on a type */ - ListIterator<AnnotationDefinition> typeMappingAnnotationDefinitions(); - - /** - * Return a ListIterator of supporting annotation definitions which can - * be placed on a type. These annotations are used in conjunction with the - * type mapping annotations - */ - ListIterator<AnnotationDefinition> typeSupportingAnnotationDefinitions(); + Iterator<AnnotationDefinition> typeAnnotationDefinitions(); /** - * Return a ListIterator of mapping annotation definitions which can + * Return a ListIterator of all annotation definitions which can * be placed on an attribute */ - ListIterator<AnnotationDefinition> attributeMappingAnnotationDefinitions(); - - /** - * Return a ListIterator of supporting annotation definitions which can - * be placed on a attribute. These annotations are used in conjunction with the - * attribute mapping annotations - */ - ListIterator<AnnotationDefinition> attributeSupportingAnnotationDefinitions(); + Iterator<AnnotationDefinition> attributeAnnotationDefinitions(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java index e32ee5c676..649db41a87 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java @@ -9,8 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.core; -import java.util.ListIterator; - +import java.util.Iterator; import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jpt.core.resource.java.Annotation; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; @@ -19,7 +18,7 @@ import org.eclipse.jpt.core.utility.jdt.Attribute; import org.eclipse.jpt.core.utility.jdt.Type; /** - * This is used to provide type and attribute mapping and supporting annotations. + * This is used to provide type and attribute annotations. * Also provides list of supported annotation names, check the appropriate list * before trying to build an annotation with that name. An exception will * be thrown on an attempt to build an annotation that does not exist. @@ -28,7 +27,7 @@ import org.eclipse.jpt.core.utility.jdt.Type; * JpaAnnotationDefinitionProvider to extend the list of supported annotation definitions. * * @see JpaAnnotationDefinitionProvider - * @version 2.2 + * @version 3.0 * @since 2.0? * * Provisional API: This interface is part of an interim API that is still @@ -37,110 +36,68 @@ import org.eclipse.jpt.core.utility.jdt.Type; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface JpaAnnotationProvider { - +public interface JpaAnnotationProvider +{ // ********** type annotations ********** - + /** - * Return the names of the mapping annotations that can modify a type. + * Return the names of the annotations that can appear on a type. */ - ListIterator<String> typeMappingAnnotationNames(); - + Iterator<String> typeAnnotationNames(); + /** - * Build a type mapping annotation with the specified name. + * Build a type annotation with the specified name. * Throw an IllegalArgumentException if the specified name is unsupported. - * @see #typeMappingAnnotationNames() + * @see #typeAnnotationNames() */ - Annotation buildTypeMappingAnnotation(JavaResourcePersistentType parent, Type type, String annotationName); - + Annotation buildTypeAnnotation( + JavaResourcePersistentType parent, Type type, String annotationName); + /** - * Build a type mapping annotation for the specified JDT annotation. + * Build a type annotation for the specified JDT annotation. * Throw an IllegalArgumentException if the specified annotation is unsupported. - * @see #typeMappingAnnotationNames() + * @see #typeAnnotationNames() */ - Annotation buildTypeMappingAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation); - + Annotation buildTypeAnnotation( + JavaResourcePersistentType parent, IAnnotation jdtAnnotation); + /** - * Return the names of the supporting annotations that can modify a type. - */ - ListIterator<String> typeSupportingAnnotationNames(); - - /** - * Build a type supporting annotation with the specified name. - * Throw an IllegalArgumentException if the specified name is unsupported. - * @see #typeSupportingAnnotationNames() - */ - Annotation buildTypeSupportingAnnotation(JavaResourcePersistentType parent, Type type, String annotationName); - - /** - * Build a type supporting annotation for the specified JDT annotation. - * Throw an IllegalArgumentException if the specified annotation is unsupported. - * @see #typeSupportingAnnotationNames() - */ - Annotation buildTypeSupportingAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation); - - /** - * Build a null type supporting annotation with the specified name. + * Build a null type annotation with the specified name. * Throw an IllegalArgumentException if the specified annotation is unsupported. - * @see #typeSupportingAnnotationNames() + * @see #typeAnnotationNames() */ - Annotation buildNullTypeSupportingAnnotation(JavaResourcePersistentType parent, String annotationName); - - + Annotation buildNullTypeAnnotation( + JavaResourcePersistentType parent, String annotationName); + + // ********** attribute annotations ********** - + /** - * Return the names of the mapping annotations that can modify an attribute. + * Return the names of the annotations that can appear on an attribute. */ - ListIterator<String> attributeMappingAnnotationNames(); - + Iterator<String> attributeAnnotationNames(); + /** - * Build an attribute mapping annotation with the specified name. + * Build an attribute annotation with the specified name. * Throw an IllegalArgumentException if the specified name is unsupported. - * @see #attributeMappingAnnotationNames() + * @see #attributeAnnotationNames() */ - Annotation buildAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName); - + Annotation buildAttributeAnnotation( + JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName); + /** - * Build an attribute mapping annotation for the specified JDT annotation. + * Build an attribute annotation for the specified JDT annotation. * Throw an IllegalArgumentException if the specified annotation is unsupported. - * @see #attributeMappingAnnotationNames() + * @see #attributeAnnotationNames() */ - Annotation buildAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation); - + Annotation buildAttributeAnnotation( + JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation); + /** - * Build a null attribute mapping annotation with the specified name. + * Build a null attribute annotation with the specified name. * Throw an IllegalArgumentException if the specified annotation is unsupported. - * This is used by an attribute's "default" mapping, since there is no - * annotation present (thus the "default" part...). * @see #attributeMappingAnnotationNames() */ - Annotation buildNullAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, String annotationName); - - /** - * Return the names of the supporting annotations that can modify an attribute. - */ - ListIterator<String> attributeSupportingAnnotationNames(); - - /** - * Build an attribute supporting annotation with the specified name. - * Throw an IllegalArgumentException if the specified name is unsupported. - * @see #attributeSupportingAnnotationNames() - */ - Annotation buildAttributeSupportingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName); - - /** - * Build an attribute supporting annotation for the specified JDT annotation. - * Throw an IllegalArgumentException if the specified annotation is unsupported. - * @see #attributeSupportingAnnotationNames() - */ - Annotation buildAttributeSupportingAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation); - - /** - * Build a null attribute supporting annotation with the specified name. - * Throw an IllegalArgumentException if the specified annotation is unsupported. - * @see #attributeSupportingAnnotationNames() - */ - Annotation buildNullAttributeSupportingAnnotation(JavaResourcePersistentAttribute parent, String annotationName); - + Annotation buildNullAttributeAnnotation( + JavaResourcePersistentAttribute parent, String annotationName); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java index 00894913a9..bdce4e05b4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java @@ -15,7 +15,10 @@ import org.eclipse.jpt.core.context.MappingFileDefinition; import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; +import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; +import org.eclipse.jpt.core.context.java.NullDefaultJavaAttributeMappingProvider; +import org.eclipse.jpt.core.context.java.NullJavaTypeMappingProvider; +import org.eclipse.jpt.core.context.java.NullSpecifiedJavaAttributeMappingProvider; import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; import org.eclipse.jpt.db.ConnectionProfileFactory; import org.eclipse.jpt.db.DatabaseFinder; @@ -85,22 +88,21 @@ public interface JpaPlatform // ********** Java type/attribute mappings ********** /** - * Build a Java type mapping for the specified key and persistent type. - * Use identity when comparing keys; so clients must use the same key - * constants as the providers. - * Throw an IllegalArgumentException if the key is not supported by the - * platform. + * Return a {@link JavaTypeMappingProvider} that describes the interpretation of the type + * as it exists, complete with annotations. + * This may not be null (@see {@link NullJavaTypeMappingProvider},) else + * an {@link IllegalStateException} is thrown. + * + * @param type The persistent type to analyze + * @return The mapping provider describing the annotated state of the type */ - JavaTypeMapping buildJavaTypeMappingFromMappingKey(String key, JavaPersistentType type); + JavaTypeMappingProvider getJavaTypeMappingProvider(JavaPersistentType type); /** - * Build a Java type mapping for the specified annotation and persistent - * type. Use identity when comparing annotation names; so clients must - * use the same name constants as the providers. - * Throw an IllegalArgumentException if the mapping annotation is not - * supported by the platform. + * Return a {@link JavaTypeMappingProvider} for the given mapping key. + * Throw an {@link IllegalArgumentException} if the key is not supported by the platform. */ - JavaTypeMapping buildJavaTypeMappingFromAnnotation(String annotationName, JavaPersistentType type); + JavaTypeMappingProvider getJavaTypeMappingProvider(String mappingKey); /** * Return a {@link JavaAttributeMappingProvider} that describes the interpretation of the attribute @@ -117,7 +119,8 @@ public interface JpaPlatform * Return a {@link JavaAttributeMappingProvider} that describes the interpretation of the attribute * as it exists, complete with annotations. It is assumed that the attribute's default mapping * has already been determined. - * This may be null. + * This may not be null (@see {@link NullSpecifiedJavaAttributeMappingProvider},) else + * an {@link IllegalStateException} is thrown. * * @param attribute The persistent attribute to analyze * @return The mapping provider describing the annotated state of the attribute diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaAttributeMappingProvider.java index 1c10bfdf78..803e0668d4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaAttributeMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaAttributeMappingProvider.java @@ -44,11 +44,11 @@ public interface JavaAttributeMappingProvider * Return whether this mapping provider should be used for the given {@link JavaPersistentAttribute} * in the default (ignoring all mapping annotations) case. */ - boolean defaultApplies(JavaPersistentAttribute persistentAttribute); + boolean testDefault(JavaPersistentAttribute persistentAttribute); /** * Return whether this mapping provider should be used for the given {@link JavaPersistentAttribute} * in the specified (observing all mapping annotations) case. */ - boolean specifiedApplies(JavaPersistentAttribute persistentAttribute); + boolean testSpecified(JavaPersistentAttribute persistentAttribute); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java index aa81bc8b4c..f8fef26be9 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java @@ -34,16 +34,15 @@ public interface JavaPersistentType ListIterator<JavaPersistentAttribute> attributes(); JavaPersistentAttribute getAttributeNamed(String attributeName); - - + + // ********** Java ********** - + /** - * Return whether the persistent type contains an attribute with - * a mapping annotation. + * Return whether any attribute in this persistent type is annotated */ - boolean hasAnyAttributePersistenceAnnotations(); - + boolean hasAnyAnnotatedAttributes(); + /** * Return the Java resource persistent type. */ diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMapping.java index 10ef63df07..3fb9ff396a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMapping.java @@ -34,7 +34,7 @@ public interface JavaTypeMapping extends TypeMapping, JavaJpaContextNode String getAnnotationName(); - Iterator<String> correspondingAnnotationNames(); + Iterator<String> supportingAnnotationNames(); JavaPersistentType getPersistentType(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMappingProvider.java index 6225b78cd0..63851cca70 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaTypeMappingProvider.java @@ -39,5 +39,10 @@ public interface JavaTypeMappingProvider { * creation method instead of building a provider for the same key. */ public JavaTypeMapping buildMapping(JavaPersistentType type, JpaFactory factory); - + + /** + * Return whether this mapping provider should be used for the given {@link JavaPersistentType}, + * considering all annotations. + */ + boolean test(JavaPersistentType persistentType); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullDefaultJavaAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullDefaultJavaAttributeMappingProvider.java index fe1e627bda..ad25ee6de6 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullDefaultJavaAttributeMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullDefaultJavaAttributeMappingProvider.java @@ -58,14 +58,14 @@ public class NullDefaultJavaAttributeMappingProvider /** * This is typically the final test, so it should always apply */ - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { + public boolean testDefault(JavaPersistentAttribute persistentAttribute) { return true; } /** * Obviously, always false */ - public boolean specifiedApplies(JavaPersistentAttribute persistentAttribute) { + public boolean testSpecified(JavaPersistentAttribute persistentAttribute) { return false; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullJavaTypeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullJavaTypeMappingProvider.java index aec6fb2cc7..1556bcfe90 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullJavaTypeMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullJavaTypeMappingProvider.java @@ -21,7 +21,8 @@ public class NullJavaTypeMappingProvider implements JavaTypeMappingProvider { // singleton - private static final NullJavaTypeMappingProvider INSTANCE = new NullJavaTypeMappingProvider(); + private static final NullJavaTypeMappingProvider INSTANCE = + new NullJavaTypeMappingProvider(); /** @@ -52,6 +53,13 @@ public class NullJavaTypeMappingProvider return factory.buildJavaNullTypeMapping(parent); } + /** + * This is typically the final test, so it should always apply + */ + public boolean test(JavaPersistentType persistentType) { + return true; + } + @Override public String toString() { return StringTools.buildToStringFor(this, this.getAnnotationName()); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullSpecifiedJavaAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullSpecifiedJavaAttributeMappingProvider.java index a36b941c17..4919758e44 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullSpecifiedJavaAttributeMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/NullSpecifiedJavaAttributeMappingProvider.java @@ -58,14 +58,14 @@ public class NullSpecifiedJavaAttributeMappingProvider /** * Obviously false */ - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { + public boolean testDefault(JavaPersistentAttribute persistentAttribute) { return false; } /** * This is typically the final test, so it should always apply */ - public boolean specifiedApplies(JavaPersistentAttribute persistentAttribute) { + public boolean testSpecified(JavaPersistentAttribute persistentAttribute) { return true; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java index bde18ed5b8..68da85962e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java @@ -707,7 +707,7 @@ public abstract class AbstractJpaProject return new FilteringIterable<JavaResourcePersistentType, JavaResourcePersistentType>(this.getInternalSourceJavaResourcePersistentTypes()) { @Override protected boolean accept(JavaResourcePersistentType jrpType) { - return jrpType.isPersistable() && jrpType.isPersisted(); // i.e. the type is valid and has a type mapping annotation + return jrpType.isPersistable() && jrpType.isAnnotated(); // i.e. the type is valid and has a valid type annotation } }; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractRootContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractRootContextNode.java index c198d07db1..a9a0567468 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractRootContextNode.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractRootContextNode.java @@ -207,10 +207,9 @@ public abstract class AbstractRootContextNode JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CONTEXT, new String[] {persistenceUnit.getName()}, jrcu.getFile(), - jrpt.getMappingAnnotation().getTextRange(jrcu.buildASTRoot()) + jrpt.getTextRange(jrcu.buildASTRoot()) ) ); } } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMappingProvider.java index ceff9b1d50..626c54a17b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaAttributeMappingProvider.java @@ -22,15 +22,15 @@ public abstract class AbstractJavaAttributeMappingProvider /** * Default implementation. Override if the mapping provider ever applies in the default case. */ - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { + public boolean testDefault(JavaPersistentAttribute persistentAttribute) { return false; } /** * Default implementation. Override if the mapping provider needs to do more analysis. */ - public boolean specifiedApplies(JavaPersistentAttribute persistentAttribute) { - return persistentAttribute.getResourcePersistentAttribute().getMappingAnnotation(getAnnotationName()) + public boolean testSpecified(JavaPersistentAttribute persistentAttribute) { + return persistentAttribute.getResourcePersistentAttribute().getAnnotation(getAnnotationName()) != null; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java index 6a1502c9f3..33d35fde29 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java @@ -104,7 +104,7 @@ public abstract class AbstractJavaBaseEmbeddedMapping<T extends Annotation> } } - getResourcePersistentAttribute().removeSupportingAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + getResourcePersistentAttribute().removeAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); fireItemRemoved(Entity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); if (virtualAttributeOverride != null) { @@ -118,12 +118,15 @@ public abstract class AbstractJavaBaseEmbeddedMapping<T extends Annotation> JavaAttributeOverride newAttributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); this.specifiedAttributeOverrides.add(index, newAttributeOverride); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) getResourcePersistentAttribute().addSupportingAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + AttributeOverrideAnnotation attributeOverrideResource = + (AttributeOverrideAnnotation) getResourcePersistentAttribute().addAnnotation( + index, AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); newAttributeOverride.initialize(attributeOverrideResource); int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); this.virtualAttributeOverrides.remove(defaultIndex); - + newAttributeOverride.setName(oldAttributeOverride.getName()); newAttributeOverride.getColumn().setSpecifiedName(oldAttributeOverride.getColumn().getName()); @@ -175,7 +178,8 @@ public abstract class AbstractJavaBaseEmbeddedMapping<T extends Annotation> public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - getResourcePersistentAttribute().moveSupportingAnnotation(targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); + getResourcePersistentAttribute().moveAnnotation( + targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); fireItemMoved(BaseEmbeddedMapping.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); } @@ -235,7 +239,10 @@ public abstract class AbstractJavaBaseEmbeddedMapping<T extends Annotation> } protected void initializeAttributeOverrides() { - ListIterator<NestableAnnotation> annotations = this.resourcePersistentAttribute.supportingAnnotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> annotations = + this.resourcePersistentAttribute.annotations( + AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); while(annotations.hasNext()) { JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, this); @@ -264,7 +271,10 @@ public abstract class AbstractJavaBaseEmbeddedMapping<T extends Annotation> } protected void updateSpecifiedAttributeOverrides() { ListIterator<JavaAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<NestableAnnotation> resourceAttributeOverrides = this.resourcePersistentAttribute.supportingAnnotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> resourceAttributeOverrides = + this.resourcePersistentAttribute.annotations( + AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); while (attributeOverrides.hasNext()) { JavaAttributeOverride attributeOverride = attributeOverrides.next(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBasicMapping.java index ff18621605..024a6d148f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBasicMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaBasicMapping.java @@ -66,7 +66,7 @@ public abstract class AbstractJavaBasicMapping extends AbstractJavaAttributeMapp } public ColumnAnnotation getResourceColumn() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullSupportingAnnotation(ColumnAnnotation.ANNOTATION_NAME); + return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); } //************** AttributeMapping implementation *************** @@ -236,13 +236,13 @@ public abstract class AbstractJavaBasicMapping extends AbstractJavaAttributeMapp } protected String getResourceConverterType() { - if (this.resourcePersistentAttribute.getSupportingAnnotation(EnumeratedAnnotation.ANNOTATION_NAME) != null) { + if (this.resourcePersistentAttribute.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME) != null) { return Converter.ENUMERATED_CONVERTER; } - else if (this.resourcePersistentAttribute.getSupportingAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { + else if (this.resourcePersistentAttribute.getAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { return Converter.TEMPORAL_CONVERTER; } - else if (this.resourcePersistentAttribute.getSupportingAnnotation(LobAnnotation.ANNOTATION_NAME) != null) { + else if (this.resourcePersistentAttribute.getAnnotation(LobAnnotation.ANNOTATION_NAME) != null) { return Converter.LOB_CONVERTER; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEmbeddable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEmbeddable.java index be8cd1d5ee..272d0f0cd3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEmbeddable.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEmbeddable.java @@ -33,7 +33,7 @@ public abstract class AbstractJavaEmbeddable return EmbeddableAnnotation.ANNOTATION_NAME; } - public Iterator<String> correspondingAnnotationNames() { + public Iterator<String> supportingAnnotationNames() { return EmptyIterator.instance(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java index 68a9e1efa2..b205bc11a8 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java @@ -87,7 +87,6 @@ public abstract class AbstractJavaEntity extends AbstractJavaTypeMapping implements JavaEntity { - protected String specifiedName; protected String defaultName; @@ -238,14 +237,24 @@ public abstract class AbstractJavaEntity } protected void initializeSecondaryTables() { - for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) { - this.specifiedSecondaryTables.add(buildSecondaryTable((SecondaryTableAnnotation) stream.next())); + for (Iterator<NestableAnnotation> stream = + this.javaResourcePersistentType.annotations( + SecondaryTableAnnotation.ANNOTATION_NAME, + SecondaryTablesAnnotation.ANNOTATION_NAME); + stream.hasNext(); ) { + this.specifiedSecondaryTables.add( + buildSecondaryTable((SecondaryTableAnnotation) stream.next())); } } protected void initializePrimaryKeyJoinColumns() { - for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); stream.hasNext(); ) { - this.specifiedPrimaryKeyJoinColumns.add(buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) stream.next())); + for (Iterator<NestableAnnotation> stream = + this.javaResourcePersistentType.annotations( + PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, + PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); + stream.hasNext(); ) { + this.specifiedPrimaryKeyJoinColumns.add( + buildPrimaryKeyJoinColumn((PrimaryKeyJoinColumnAnnotation) stream.next())); } } @@ -259,10 +268,15 @@ public abstract class AbstractJavaEntity } this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumnAnnotation(this.javaResourcePersistentType)); } - + protected void initializeSpecifiedAttributeOverrides() { - for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) { - this.specifiedAttributeOverrides.add(buildAttributeOverride((AttributeOverrideAnnotation) stream.next())); + for (Iterator<NestableAnnotation> stream = + this.javaResourcePersistentType.annotations( + AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); + stream.hasNext(); ) { + this.specifiedAttributeOverrides.add( + buildAttributeOverride((AttributeOverrideAnnotation) stream.next())); } } @@ -276,8 +290,13 @@ public abstract class AbstractJavaEntity } protected void initializeSpecifiedAssociationOverrides() { - for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) { - this.specifiedAssociationOverrides.add(buildAssociationOverride((AssociationOverrideAnnotation) stream.next())); + for (Iterator<NestableAnnotation> stream = + this.javaResourcePersistentType.annotations( + AssociationOverrideAnnotation.ANNOTATION_NAME, + AssociationOverridesAnnotation.ANNOTATION_NAME); + stream.hasNext(); ) { + this.specifiedAssociationOverrides.add( + buildAssociationOverride((AssociationOverrideAnnotation) stream.next())); } } @@ -295,13 +314,15 @@ public abstract class AbstractJavaEntity //You could call more than one setter before this object has received any notification //from the java resource model protected InheritanceAnnotation getResourceInheritance() { - return (InheritanceAnnotation) this.javaResourcePersistentType.getNonNullSupportingAnnotation(InheritanceAnnotation.ANNOTATION_NAME); + return (InheritanceAnnotation) this.javaResourcePersistentType. + getNonNullAnnotation(InheritanceAnnotation.ANNOTATION_NAME); } protected DiscriminatorValueAnnotation getResourceDiscriminatorValue() { - return (DiscriminatorValueAnnotation) this.javaResourcePersistentType.getNonNullSupportingAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); + return (DiscriminatorValueAnnotation) this.javaResourcePersistentType. + getNonNullAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); } - + protected void initializeIdClass() { IdClassAnnotation resourceIdClass = getResourceIdClass(); if (resourceIdClass != null) { @@ -375,7 +396,7 @@ public abstract class AbstractJavaEntity return EntityAnnotation.ANNOTATION_NAME; } - public Iterator<String> correspondingAnnotationNames() { + public Iterator<String> supportingAnnotationNames() { return new ArrayIterator<String>( JPA.TABLE, JPA.SECONDARY_TABLE, @@ -457,7 +478,11 @@ public abstract class AbstractJavaEntity public JavaSecondaryTable addSpecifiedSecondaryTable(int index) { JavaSecondaryTable secondaryTable = getJpaFactory().buildJavaSecondaryTable(this); this.specifiedSecondaryTables.add(index, secondaryTable); - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) this.javaResourcePersistentType.addSupportingAnnotation(index, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); + SecondaryTableAnnotation secondaryTableResource = + (SecondaryTableAnnotation) this.javaResourcePersistentType. + addAnnotation( + index, SecondaryTableAnnotation.ANNOTATION_NAME, + SecondaryTablesAnnotation.ANNOTATION_NAME); secondaryTable.initialize(secondaryTableResource); fireItemAdded(SPECIFIED_SECONDARY_TABLES_LIST, index, secondaryTable); return secondaryTable; @@ -481,7 +506,8 @@ public abstract class AbstractJavaEntity public void removeSpecifiedSecondaryTable(int index) { JavaSecondaryTable removedSecondaryTable = this.specifiedSecondaryTables.remove(index); - this.javaResourcePersistentType.removeSupportingAnnotation(index, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.removeAnnotation( + index, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); fireItemRemoved(SPECIFIED_SECONDARY_TABLES_LIST, index, removedSecondaryTable); } @@ -491,7 +517,8 @@ public abstract class AbstractJavaEntity public void moveSpecifiedSecondaryTable(int targetIndex, int sourceIndex) { CollectionTools.move(this.specifiedSecondaryTables, targetIndex, sourceIndex); - this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, SecondaryTablesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.moveAnnotation( + targetIndex, sourceIndex, SecondaryTablesAnnotation.ANNOTATION_NAME); fireItemMoved(SPECIFIED_SECONDARY_TABLES_LIST, targetIndex, sourceIndex); } @@ -697,7 +724,11 @@ public abstract class AbstractJavaEntity } JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = getJpaFactory().buildJavaPrimaryKeyJoinColumn(this, createPrimaryKeyJoinColumnOwner()); this.specifiedPrimaryKeyJoinColumns.add(index, primaryKeyJoinColumn); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) this.javaResourcePersistentType.addSupportingAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); + PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = + (PrimaryKeyJoinColumnAnnotation) this.javaResourcePersistentType. + addAnnotation( + index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, + PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); primaryKeyJoinColumn.initialize(pkJoinColumnResource); this.fireItemAdded(SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, primaryKeyJoinColumn); if (oldDefaultPkJoinColumn != null) { @@ -726,7 +757,9 @@ public abstract class AbstractJavaEntity //in the UI because the change notifications end up in the wrong order. this.defaultPrimaryKeyJoinColumn = buildPrimaryKeyJoinColumn(new NullPrimaryKeyJoinColumnAnnotation(this.javaResourcePersistentType)); } - this.javaResourcePersistentType.removeSupportingAnnotation(index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.removeAnnotation( + index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, + PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); fireItemRemoved(SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST, index, removedPrimaryKeyJoinColumn); if (this.defaultPrimaryKeyJoinColumn != null) { //fire change notification if a defaultJoinColumn was created above @@ -739,7 +772,8 @@ public abstract class AbstractJavaEntity } public void moveSpecifiedPrimaryKeyJoinColumn(int targetIndex, int sourceIndex) { - this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.moveAnnotation( + targetIndex, sourceIndex, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); moveItemInList(targetIndex, sourceIndex, this.specifiedPrimaryKeyJoinColumns, SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST); } @@ -771,7 +805,10 @@ public abstract class AbstractJavaEntity protected JavaAttributeOverride addSpecifiedAttributeOverride(int index) { JavaAttributeOverride attributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); this.specifiedAttributeOverrides.add(index, attributeOverride); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) this.javaResourcePersistentType.addSupportingAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + AttributeOverrideAnnotation attributeOverrideResource = + (AttributeOverrideAnnotation) this.javaResourcePersistentType.addAnnotation( + index, AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); attributeOverride.initialize(attributeOverrideResource); this.fireItemAdded(SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); return attributeOverride; @@ -804,7 +841,9 @@ public abstract class AbstractJavaEntity } } - this.javaResourcePersistentType.removeSupportingAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.removeAnnotation( + index, AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); fireItemRemoved(SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, index, attributeOverride); if (virtualAttributeOverride != null) { @@ -818,7 +857,10 @@ public abstract class AbstractJavaEntity JavaAttributeOverride newAttributeOverride = getJpaFactory().buildJavaAttributeOverride(this, createAttributeOverrideOwner()); this.specifiedAttributeOverrides.add(index, newAttributeOverride); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) this.javaResourcePersistentType.addSupportingAnnotation(index, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + AttributeOverrideAnnotation attributeOverrideResource = + (AttributeOverrideAnnotation) this.javaResourcePersistentType.addAnnotation( + index, AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); newAttributeOverride.initialize(attributeOverrideResource); int defaultIndex = this.virtualAttributeOverrides.indexOf(oldAttributeOverride); @@ -851,7 +893,8 @@ public abstract class AbstractJavaEntity public void moveSpecifiedAttributeOverride(int targetIndex, int sourceIndex) { CollectionTools.move(this.specifiedAttributeOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.moveAnnotation( + targetIndex, sourceIndex, AttributeOverridesAnnotation.ANNOTATION_NAME); fireItemMoved(SPECIFIED_ATTRIBUTE_OVERRIDES_LIST, targetIndex, sourceIndex); } @@ -941,7 +984,10 @@ public abstract class AbstractJavaEntity public JavaAssociationOverride addSpecifiedAssociationOverride(int index) { JavaAssociationOverride associationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); this.specifiedAssociationOverrides.add(index, associationOverride); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) this.javaResourcePersistentType.addSupportingAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); + AssociationOverrideAnnotation associationOverrideResource = + (AssociationOverrideAnnotation) this.javaResourcePersistentType.addAnnotation( + index, AssociationOverrideAnnotation.ANNOTATION_NAME, + AssociationOverridesAnnotation.ANNOTATION_NAME); associationOverride.initialize(associationOverrideResource); this.fireItemAdded(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); return associationOverride; @@ -965,7 +1011,8 @@ public abstract class AbstractJavaEntity public void moveSpecifiedAssociationOverride(int targetIndex, int sourceIndex) { CollectionTools.move(this.specifiedAssociationOverrides, targetIndex, sourceIndex); - this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, AssociationOverridesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.moveAnnotation( + targetIndex, sourceIndex, AssociationOverridesAnnotation.ANNOTATION_NAME); fireItemMoved(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, targetIndex, sourceIndex); } @@ -996,7 +1043,9 @@ public abstract class AbstractJavaEntity } } - this.javaResourcePersistentType.removeSupportingAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.removeAnnotation( + index, AssociationOverrideAnnotation.ANNOTATION_NAME, + AssociationOverridesAnnotation.ANNOTATION_NAME); fireItemRemoved(SPECIFIED_ASSOCIATION_OVERRIDES_LIST, index, associationOverride); if (virtualAssociationOverride != null) { @@ -1010,7 +1059,10 @@ public abstract class AbstractJavaEntity JavaAssociationOverride newAssociationOverride = getJpaFactory().buildJavaAssociationOverride(this, createAssociationOverrideOwner()); this.specifiedAssociationOverrides.add(index, newAssociationOverride); - AssociationOverrideAnnotation attributeOverrideResource = (AssociationOverrideAnnotation) this.javaResourcePersistentType.addSupportingAnnotation(index, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); + AssociationOverrideAnnotation attributeOverrideResource = + (AssociationOverrideAnnotation) this.javaResourcePersistentType.addAnnotation( + index, AssociationOverrideAnnotation.ANNOTATION_NAME, + AssociationOverridesAnnotation.ANNOTATION_NAME); newAssociationOverride.initialize(attributeOverrideResource); int virtualIndex = this.virtualAssociationOverrides.indexOf(oldAssociationOverride); @@ -1073,15 +1125,16 @@ public abstract class AbstractJavaEntity } protected IdClassAnnotation getResourceIdClass() { - return (IdClassAnnotation) this.javaResourcePersistentType.getSupportingAnnotation(IdClassAnnotation.ANNOTATION_NAME); + return (IdClassAnnotation) this.javaResourcePersistentType. + getAnnotation(IdClassAnnotation.ANNOTATION_NAME); } protected void addResourceIdClass() { - this.javaResourcePersistentType.addSupportingAnnotation(IdClassAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); } protected void removeResourceIdClass() { - this.javaResourcePersistentType.removeSupportingAnnotation(IdClassAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); } public Entity getParentEntity() { @@ -1519,7 +1572,9 @@ public abstract class AbstractJavaEntity protected void updateSecondaryTables() { ListIterator<JavaSecondaryTable> secondaryTables = specifiedSecondaryTables(); - ListIterator<NestableAnnotation> resourceSecondaryTables = this.javaResourcePersistentType.supportingAnnotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> resourceSecondaryTables = + this.javaResourcePersistentType.annotations( + SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); while (secondaryTables.hasNext()) { JavaSecondaryTable secondaryTable = secondaryTables.next(); @@ -1541,12 +1596,13 @@ public abstract class AbstractJavaEntity secondaryTable.initialize(secondaryTableResource); return secondaryTable; } - - protected void updateSpecifiedPrimaryKeyJoinColumns() { ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = specifiedPrimaryKeyJoinColumns(); - ListIterator<NestableAnnotation> resourcePrimaryKeyJoinColumns = this.javaResourcePersistentType.supportingAnnotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> resourcePrimaryKeyJoinColumns = + this.javaResourcePersistentType.annotations( + PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, + PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); while (primaryKeyJoinColumns.hasNext()) { JavaPrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns.next(); @@ -1584,7 +1640,10 @@ public abstract class AbstractJavaEntity protected void updateSpecifiedAttributeOverrides() { ListIterator<JavaAttributeOverride> attributeOverrides = specifiedAttributeOverrides(); - ListIterator<NestableAnnotation> resourceAttributeOverrides = this.javaResourcePersistentType.supportingAnnotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> resourceAttributeOverrides = + this.javaResourcePersistentType.annotations( + AttributeOverrideAnnotation.ANNOTATION_NAME, + AttributeOverridesAnnotation.ANNOTATION_NAME); while (attributeOverrides.hasNext()) { JavaAttributeOverride attributeOverride = attributeOverrides.next(); @@ -1640,7 +1699,10 @@ public abstract class AbstractJavaEntity protected void updateSpecifiedAssociationOverrides() { ListIterator<JavaAssociationOverride> associationOverrides = specifiedAssociationOverrides(); - ListIterator<NestableAnnotation> resourceAssociationOverrides = this.javaResourcePersistentType.supportingAnnotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> resourceAssociationOverrides = + this.javaResourcePersistentType.annotations( + AssociationOverrideAnnotation.ANNOTATION_NAME, + AssociationOverridesAnnotation.ANNOTATION_NAME); while (associationOverrides.hasNext()) { JavaAssociationOverride associationOverride = associationOverrides.next(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java index 9af5b6785f..e8086d5f60 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMapping.java @@ -79,7 +79,8 @@ public abstract class AbstractJavaIdMapping } public ColumnAnnotation getResourceColumn() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullSupportingAnnotation(ColumnAnnotation.ANNOTATION_NAME); + return (ColumnAnnotation) getResourcePersistentAttribute(). + getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); } //************** JavaAttributeMapping implementation *************** @@ -120,7 +121,9 @@ public abstract class AbstractJavaIdMapping throw new IllegalStateException("gemeratedValue already exists"); //$NON-NLS-1$ } this.generatedValue = getJpaFactory().buildJavaGeneratedValue(this); - GeneratedValueAnnotation generatedValueResource = (GeneratedValueAnnotation) getResourcePersistentAttribute().addSupportingAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); + GeneratedValueAnnotation generatedValueResource = + (GeneratedValueAnnotation) getResourcePersistentAttribute(). + addAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); this.generatedValue.initialize(generatedValueResource); firePropertyChanged(GENERATED_VALUE_PROPERTY, null, this.generatedValue); return this.generatedValue; @@ -132,7 +135,7 @@ public abstract class AbstractJavaIdMapping } JavaGeneratedValue oldGeneratedValue = this.generatedValue; this.generatedValue = null; - getResourcePersistentAttribute().removeSupportingAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); + getResourcePersistentAttribute().removeAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); firePropertyChanged(GENERATED_VALUE_PROPERTY, oldGeneratedValue, null); } @@ -232,15 +235,18 @@ public abstract class AbstractJavaIdMapping } protected TableGeneratorAnnotation getResourceTableGenerator() { - return (TableGeneratorAnnotation) this.resourcePersistentAttribute.getSupportingAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); + return (TableGeneratorAnnotation) this.resourcePersistentAttribute. + getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); } protected SequenceGeneratorAnnotation getResourceSequenceGenerator() { - return (SequenceGeneratorAnnotation) this.resourcePersistentAttribute.getSupportingAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); + return (SequenceGeneratorAnnotation) this.resourcePersistentAttribute. + getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); } protected GeneratedValueAnnotation getResourceGeneratedValue() { - return (GeneratedValueAnnotation) this.resourcePersistentAttribute.getSupportingAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); + return (GeneratedValueAnnotation) this.resourcePersistentAttribute. + getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME); } protected JavaConverter buildSpecifiedConverter(String converterType) { @@ -251,7 +257,7 @@ public abstract class AbstractJavaIdMapping } protected String getResourceConverterType() { - if (this.resourcePersistentAttribute.getSupportingAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { + if (this.resourcePersistentAttribute.getAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { return Converter.TEMPORAL_CONVERTER; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMappingProvider.java new file mode 100644 index 0000000000..8822fc03eb --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaIdMappingProvider.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.context.java; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.resource.java.IdAnnotation; + +public abstract class AbstractJavaIdMappingProvider + extends AbstractJavaAttributeMappingProvider +{ + protected AbstractJavaIdMappingProvider() { + super(); + } + + + public String getKey() { + return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; + } + + public String getAnnotationName() { + return IdAnnotation.ANNOTATION_NAME; + } + + public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { + return factory.buildJavaIdMapping(parent); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinColumnJoiningStrategy.java index d91f6bd619..b270511d72 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinColumnJoiningStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaJoinColumnJoiningStrategy.java @@ -13,7 +13,6 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.JoinColumn; import org.eclipse.jpt.core.context.JoinColumnEnabledRelationshipReference; @@ -185,7 +184,7 @@ public abstract class AbstractJavaJoinColumnJoiningStrategy protected abstract void moveAnnotation(int targetIndex, int sourceIndex); - protected abstract ListIterator<JoinColumnAnnotation> joinColumnAnnotations(); + protected abstract Iterator<JoinColumnAnnotation> joinColumnAnnotations(); protected abstract JoinColumnAnnotation buildNullJoinColumnAnnotation(); @@ -198,7 +197,7 @@ public abstract class AbstractJavaJoinColumnJoiningStrategy } protected void initializeSpecifiedJoinColumns() { - ListIterator<JoinColumnAnnotation> annotations = joinColumnAnnotations(); + Iterator<JoinColumnAnnotation> annotations = joinColumnAnnotations(); while (annotations.hasNext()) { this.specifiedJoinColumns.add(buildJoinColumn(annotations.next())); } @@ -218,7 +217,7 @@ public abstract class AbstractJavaJoinColumnJoiningStrategy protected void updateSpecifiedJoinColumns() { ListIterator<JavaJoinColumn> joinColumns = specifiedJoinColumns(); - ListIterator<JoinColumnAnnotation> resourceJoinColumns = joinColumnAnnotations(); + Iterator<JoinColumnAnnotation> resourceJoinColumns = joinColumnAnnotations(); while (joinColumns.hasNext()) { JavaJoinColumn joinColumn = joinColumns.next(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java index 5c4eeb7985..eacdfea6eb 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java @@ -44,7 +44,7 @@ public abstract class AbstractJavaMappedSuperclass extends AbstractJavaTypeMappi return MappedSuperclassAnnotation.ANNOTATION_NAME; } - public Iterator<String> correspondingAnnotationNames() { + public Iterator<String> supportingAnnotationNames() { return new ArrayIterator<String>( JPA.ID_CLASS, JPA.EXCLUDE_DEFAULT_LISTENERS, @@ -91,15 +91,16 @@ public abstract class AbstractJavaMappedSuperclass extends AbstractJavaTypeMappi } protected IdClassAnnotation getResourceIdClass() { - return (IdClassAnnotation) this.javaResourcePersistentType.getSupportingAnnotation(IdClassAnnotation.ANNOTATION_NAME); + return (IdClassAnnotation) this.javaResourcePersistentType. + getAnnotation(IdClassAnnotation.ANNOTATION_NAME); } protected void addResourceIdClass() { - this.javaResourcePersistentType.addSupportingAnnotation(IdClassAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); } protected void removeResourceIdClass() { - this.javaResourcePersistentType.removeSupportingAnnotation(IdClassAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentType.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java index 55f929a775..8d1b65669a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java @@ -70,15 +70,17 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi } protected OrderByAnnotation getResourceOrderBy() { - return (OrderByAnnotation) getResourcePersistentAttribute().getSupportingAnnotation(OrderByAnnotation.ANNOTATION_NAME); + return (OrderByAnnotation) getResourcePersistentAttribute(). + getAnnotation(OrderByAnnotation.ANNOTATION_NAME); } protected OrderByAnnotation addResourceOrderBy() { - return (OrderByAnnotation) getResourcePersistentAttribute().addSupportingAnnotation(OrderByAnnotation.ANNOTATION_NAME); + return (OrderByAnnotation) getResourcePersistentAttribute(). + addAnnotation(OrderByAnnotation.ANNOTATION_NAME); } protected void removeResourceOrderBy() { - getResourcePersistentAttribute().removeSupportingAnnotation(OrderByAnnotation.ANNOTATION_NAME); + getResourcePersistentAttribute().removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); } public boolean isNoOrdering() { @@ -165,11 +167,11 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi this.getMapKeyResource().setName(newMapKey); } else { - getResourcePersistentAttribute().removeSupportingAnnotation(MapKeyAnnotation.ANNOTATION_NAME); + getResourcePersistentAttribute().removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); } } else if (newMapKey != null) { - getResourcePersistentAttribute().addSupportingAnnotation(MapKeyAnnotation.ANNOTATION_NAME); + getResourcePersistentAttribute().addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); getMapKeyResource().setName(newMapKey); } } @@ -211,7 +213,8 @@ public abstract class AbstractJavaMultiRelationshipMapping<T extends Relationshi } protected MapKeyAnnotation getMapKeyResource() { - return (MapKeyAnnotation) this.resourcePersistentAttribute.getSupportingAnnotation(MapKeyAnnotation.ANNOTATION_NAME); + return (MapKeyAnnotation) this.resourcePersistentAttribute. + getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); } public Iterator<String> candidateMapKeyNames() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java index 53c925d986..754c2ae595 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.core.internal.context.java; import java.util.Iterator; import java.util.List; - import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.Modifier; @@ -33,7 +32,6 @@ import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.utility.Filter; import org.eclipse.jpt.utility.internal.ClassTools; import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -397,8 +395,8 @@ public abstract class AbstractJavaPersistentAttribute } protected JavaAttributeMapping buildDefaultMapping(JavaAttributeMappingProvider mappingProvider) { - Annotation annotation = - this.resourcePersistentAttribute.getNullMappingAnnotation(mappingProvider.getAnnotationName()); + Annotation annotation = this.resourcePersistentAttribute. + getNullAnnotation(mappingProvider.getAnnotationName()); JavaAttributeMapping mapping = mappingProvider.buildMapping(this, getJpaFactory()); mapping.initialize(annotation); return mapping; @@ -435,16 +433,13 @@ public abstract class AbstractJavaPersistentAttribute protected JavaAttributeMapping buildSpecifiedMapping() { JavaAttributeMappingProvider mappingProvider = - getJpaPlatform().getSpecifiedJavaAttributeMappingProvider(this); + getJpaPlatform().getSpecifiedJavaAttributeMappingProvider(this); return buildSpecifiedMapping(mappingProvider); } protected JavaAttributeMapping buildSpecifiedMapping(JavaAttributeMappingProvider mappingProvider) { - if (mappingProvider == null) { - return null; - } - Annotation annotation = - this.resourcePersistentAttribute.getMappingAnnotation(mappingProvider.getAnnotationName()); + Annotation annotation = this.resourcePersistentAttribute. + getAnnotation(mappingProvider.getAnnotationName()); JavaAttributeMapping mapping = mappingProvider.buildMapping(this, getJpaFactory()); // specified mappings may be null if (mapping != null) { @@ -465,24 +460,29 @@ public abstract class AbstractJavaPersistentAttribute // to the new mapping; this can't be done in the same was as XmlAttributeMapping // since we don't know all the possible mapping types public void setSpecifiedMappingKey(String key) { - if (this.valuesAreEqual(key, this.getSpecifiedMappingKey())) { + if (key == this.getSpecifiedMappingKey()) { return; } JavaAttributeMapping oldMapping = this.specifiedMapping; JavaAttributeMapping newMapping = this.buildMappingFromMappingKey(key); - + this.specifiedMapping = newMapping; - this.resourcePersistentAttribute.setMappingAnnotation((newMapping == null) ? null : newMapping.getAnnotationName()); - this.firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, newMapping); - - // remove "supporting annotations" that do not "support" to the new mapping - if (oldMapping != null) { - HashBag<String> annotationsToRemove = CollectionTools.collection(oldMapping.supportingAnnotationNames()); - CollectionTools.removeAll(annotationsToRemove, this.supportingAnnotationNames()); - for (String annotationName : annotationsToRemove) { - this.resourcePersistentAttribute.removeSupportingAnnotation(annotationName); - } + + String newAnnotation; + String[] newSupportingAnnotationNames; + if (newMapping != null) { + newAnnotation = newMapping.getAnnotationName(); + newSupportingAnnotationNames = + CollectionTools.array(newMapping.supportingAnnotationNames(), new String[0]); } + else { + newAnnotation = null; + newSupportingAnnotationNames = + CollectionTools.array(this.defaultMapping.supportingAnnotationNames(), new String[0]); + } + this.resourcePersistentAttribute.setPrimaryAnnotation( + newAnnotation, newSupportingAnnotationNames); + this.firePropertyChanged(SPECIFIED_MAPPING_PROPERTY, oldMapping, newMapping); } /** @@ -518,12 +518,11 @@ public abstract class AbstractJavaPersistentAttribute protected void updateDefaultMapping() { // There will always be a mapping provider, even if it is a "null" mapping provider ... JavaAttributeMappingProvider mappingProvider = - getJpaPlatform().getDefaultJavaAttributeMappingProvider(this); + getJpaPlatform().getDefaultJavaAttributeMappingProvider(this); String mappingKey = mappingProvider.getKey(); if (this.valuesAreEqual(this.defaultMapping.getKey(), mappingKey)) { - this.defaultMapping.update( - this.resourcePersistentAttribute.getNullMappingAnnotation( - mappingProvider.getAnnotationName())); + this.defaultMapping.update(this.resourcePersistentAttribute. + getNullAnnotation(mappingProvider.getAnnotationName())); } else { setDefaultMapping(buildDefaultMapping(mappingProvider)); @@ -531,15 +530,14 @@ public abstract class AbstractJavaPersistentAttribute } protected void updateSpecifiedMapping() { - // There may not be a mapping provider ... + // There will always be a mapping provider, even if it is a "null" mapping provider ... JavaAttributeMappingProvider mappingProvider = - getJpaPlatform().getSpecifiedJavaAttributeMappingProvider(this); - // ... so there may not be a mapping annotation name - String annotationName = (mappingProvider == null) ? null : mappingProvider.getAnnotationName(); + getJpaPlatform().getSpecifiedJavaAttributeMappingProvider(this); + String mappingKey = mappingProvider.getKey(); if (this.specifiedMapping != null - && this.specifiedMapping.getAnnotationName().equals(annotationName)) { - this.specifiedMapping.update( - this.resourcePersistentAttribute.getMappingAnnotation(annotationName)); + && this.specifiedMapping.getKey().equals(mappingKey)) { + this.specifiedMapping.update(this.resourcePersistentAttribute. + getAnnotation(mappingProvider.getAnnotationName())); } else { setSpecifiedMapping(buildSpecifiedMapping(mappingProvider)); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java index 620e03381b..b77301b472 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java @@ -16,7 +16,6 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.content.IContentType; @@ -31,8 +30,8 @@ import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaStructureNodes; import org.eclipse.jpt.core.context.java.JavaTypeMapping; +import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; import org.eclipse.jpt.core.internal.resource.java.source.SourceNode; -import org.eclipse.jpt.core.resource.java.Annotation; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.utility.TextRange; @@ -54,28 +53,34 @@ public abstract class AbstractJavaPersistentType extends AbstractJavaJpaContextNode implements JavaPersistentType { - protected String name; + protected JavaResourcePersistentType resourcePersistentType; - protected JavaTypeMapping mapping; - - protected final Vector<JavaPersistentAttribute> attributes = new Vector<JavaPersistentAttribute>(); - protected PersistentType parentPersistentType; - - protected JavaResourcePersistentType resourcePersistentType; - + + protected String name; + protected AccessType defaultAccess; + protected AccessType specifiedAccess; + + protected JavaTypeMapping mapping; + + protected final Vector<JavaPersistentAttribute> attributes = + new Vector<JavaPersistentAttribute>(); + + protected AbstractJavaPersistentType(PersistentType.Owner parent, JavaResourcePersistentType jrpt) { super(parent); this.initialize(jrpt); } + @Override public IResource getResource() { return this.resourcePersistentType.getFile(); } - + + //****************** JpaStructureNode implementation ******************* public String getId() { @@ -86,6 +91,7 @@ public abstract class AbstractJavaPersistentType return JptCorePlugin.JAVA_SOURCE_CONTENT_TYPE; } + //****************** PersistentType implementation ******************* public JavaResourcePersistentType getResourcePersistentType() { @@ -103,6 +109,30 @@ public abstract class AbstractJavaPersistentType return getParent(); } + + // **************** name ************************************************** + + public String getName() { + return this.name; + } + + public String getShortName(){ + return getName().substring(getName().lastIndexOf('.') + 1); + } + + protected void setName(String newName) { + String oldName = this.name; + this.name = newName; + firePropertyChanged(NAME_PROPERTY, oldName, newName); + } + + protected String buildName() { + return this.resourcePersistentType.getQualifiedName(); + } + + + // **************** access ************************************************ + public AccessType getAccess() { return getSpecifiedAccess() != null ? getSpecifiedAccess() : getDefaultAccess(); } @@ -117,19 +147,53 @@ public abstract class AbstractJavaPersistentType firePropertyChanged(DEFAULT_ACCESS_PROPERTY, oldAccess, newDefaultAccess); } - public String getName() { - return this.name; + public AccessType getSpecifiedAccess() { + return this.specifiedAccess; } - public String getShortName(){ - return getName().substring(getName().lastIndexOf('.') + 1); + /** + * Check the access "specified" by the java resource model. + * Check java annotations first. + * If still null check xml mapping specified access + * If still null then set to parentPersistentType access. + * If still null check entity-mappings specified access setting if this persistent-type is listed in an orm.xml file + * If still null check the persistence-unit default Access + * Default to FIELD if all else fails. + */ + protected AccessType buildDefaultAccess() { + AccessType accessType = AccessType.fromJavaResourceModel(this.resourcePersistentType.getAccess()); + if (accessType != null) { + return accessType; + } + accessType = this.getOwnerOverrideAccess(); + if (accessType != null) { + return accessType; + } + + if (this.parentPersistentType != null) { + accessType = this.parentPersistentType.getDefaultAccess(); + if (accessType != null) { + return accessType; + } + } + + accessType = this.getOwnerDefaultAccess(); + if (accessType != null) { + return accessType; + } + + // last ditch attempt to allow the user to annotate *something* + return AccessType.FIELD; } - protected void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } + /** + * Build an access type based on annotations from the resource model. + * (This is platform dependent) + */ + protected abstract AccessType buildSpecifiedAccess(); + + + // **************** mapping *********************************************** public JavaTypeMapping getMapping() { return this.mapping; @@ -144,22 +208,13 @@ public abstract class AbstractJavaPersistentType return; } JavaTypeMapping oldMapping = getMapping(); - JavaTypeMapping newMapping = createJavaTypeMappingFromMappingKey(key); - - this.mapping = newMapping; - this.resourcePersistentType.setMappingAnnotation(newMapping.getAnnotationName()); + JavaTypeMapping newMapping = buildMappingFromMappingKey(key); + + this.mapping = newMapping; + this.resourcePersistentType.setPrimaryAnnotation( + newMapping.getAnnotationName(), + CollectionTools.array(newMapping.supportingAnnotationNames(), new String[0])); firePropertyChanged(PersistentType.MAPPING_PROPERTY, oldMapping, newMapping); - - if (oldMapping != null) { - Collection<String> annotationsToRemove = CollectionTools.collection(oldMapping.correspondingAnnotationNames()); - if (getMapping() != null) { - CollectionTools.removeAll(annotationsToRemove, getMapping().correspondingAnnotationNames()); - } - - for (String annotationName : annotationsToRemove) { - this.resourcePersistentType.removeSupportingAnnotation(annotationName); - } - } } protected void setMapping(JavaTypeMapping newMapping) { @@ -168,6 +223,30 @@ public abstract class AbstractJavaPersistentType firePropertyChanged(PersistentType.MAPPING_PROPERTY, oldMapping, newMapping); } + protected JavaTypeMapping buildMapping() { + JavaTypeMappingProvider mappingProvider = + getJpaPlatform().getJavaTypeMappingProvider(this); + return buildMapping(mappingProvider); + } + + protected JavaTypeMapping buildMapping(JavaTypeMappingProvider mappingProvider) { + JavaTypeMapping mapping = mappingProvider.buildMapping(this, getJpaFactory()); + // mapping may be null + if (mapping != null) { + mapping.initialize(this.resourcePersistentType); + } + return mapping; + } + + protected JavaTypeMapping buildMappingFromMappingKey(String key) { + JavaTypeMappingProvider mappingProvider = getJpaPlatform().getJavaTypeMappingProvider(key); + JavaTypeMapping mapping = mappingProvider.buildMapping(this, getJpaFactory()); + //no mapping.initialize(JavaResourcePersistentType) call here + //we do not yet have a mapping annotation so we can't call initialize + return mapping; + } + + public boolean isMapped() { return getMapping().isMapped(); } @@ -350,29 +429,22 @@ public abstract class AbstractJavaPersistentType firePropertyChanged(PersistentType.PARENT_PERSISTENT_TYPE_PROPERTY, oldParentPersistentType, newParentPersistentType); } - public boolean hasAnyAttributePersistenceAnnotations() { - return this.resourcePersistentType.hasAnyAttributePersistenceAnnotations(); + public boolean hasAnyAnnotatedAttributes() { + return this.resourcePersistentType.hasAnyAnnotatedAttributes(); } - // ******************** Updating ********************** + // **************** initialization / updating ***************************** + protected void initialize(JavaResourcePersistentType jrpt) { this.resourcePersistentType = jrpt; this.parentPersistentType = this.buildParentPersistentType(); this.name = this.buildName(); - this.initializeAccess(); - this.initializeMapping(); + this.defaultAccess = buildDefaultAccess(); + this.specifiedAccess = buildSpecifiedAccess(); + this.mapping = buildMapping(); this.initializeAttributes(); } - protected void initializeAccess() { - this.defaultAccess = this.buildDefaultAccess(); - } - - protected void initializeMapping() { - this.mapping = this.getJpaPlatform().buildJavaTypeMappingFromAnnotation(this.getJavaMappingAnnotationName(), this); - this.mapping.initialize(this.resourcePersistentType); - } - protected void initializeAttributes() { for (Iterator<JavaResourcePersistentAttribute> stream = this.resourceAttributes(); stream.hasNext(); ) { this.attributes.add(this.createAttribute(stream.next())); @@ -412,69 +484,20 @@ public abstract class AbstractJavaPersistentType } - /** - * Check the access "specified" by the java resource model. - * Check java annotations first. - * If still null check xml mapping specified access - * If still null then set to parentPersistentType access. - * If still null check entity-mappings specified access setting if this persistent-type is listed in an orm.xml file - * If still null check the persistence-unit default Access - * Default to FIELD if all else fails. - */ - protected AccessType buildDefaultAccess() { - AccessType accessType = AccessType.fromJavaResourceModel(this.resourcePersistentType.getAccess()); - if (accessType != null) { - return accessType; - } - accessType = this.getOwnerOverrideAccess(); - if (accessType != null) { - return accessType; - } - - if (this.parentPersistentType != null) { - accessType = this.parentPersistentType.getDefaultAccess(); - if (accessType != null) { - return accessType; - } - } - - accessType = this.getOwnerDefaultAccess(); - if (accessType != null) { - return accessType; - } - - // last ditch attempt to allow the user to annotate *something* - return AccessType.FIELD; - } - - protected String buildName() { - return this.resourcePersistentType.getQualifiedName(); - } - protected void updateMapping() { - String javaMappingAnnotationName = this.getJavaMappingAnnotationName(); - if (this.valuesAreEqual(this.getMapping().getAnnotationName(), javaMappingAnnotationName)) { - this.getMapping().update(this.resourcePersistentType); - } else { - this.setMapping(this.createJavaTypeMappingFromAnnotation(javaMappingAnnotationName)); + // There will always be a mapping provider, even if it is a "null" mapping provider ... + JavaTypeMappingProvider mappingProvider = + getJpaPlatform().getJavaTypeMappingProvider(this); + String mappingKey = mappingProvider.getKey(); + if (this.mapping != null + && valuesAreEqual(this.mapping.getKey(), mappingKey)) { + this.mapping.update(this.resourcePersistentType); + } + else { + setMapping(buildMapping(mappingProvider)); } } - protected JavaTypeMapping createJavaTypeMappingFromMappingKey(String key) { - return getJpaPlatform().buildJavaTypeMappingFromMappingKey(key, this); - } - - protected JavaTypeMapping createJavaTypeMappingFromAnnotation(String annotationName) { - JavaTypeMapping typeMapping = getJpaPlatform().buildJavaTypeMappingFromAnnotation(annotationName, this); - typeMapping.initialize(this.resourcePersistentType); - return typeMapping; - } - - protected String getJavaMappingAnnotationName() { - Annotation mappingAnnotation = this.resourcePersistentType.getMappingAnnotation(); - return (mappingAnnotation == null) ? null : mappingAnnotation.getAnnotationName(); - } - protected void updateAttributes() { HashBag<JavaPersistentAttribute> contextAttributesToRemove = CollectionTools.bag(this.attributes(), this.attributesSize()); ArrayList<JavaPersistentAttribute> contextAttributesToUpdate = new ArrayList<JavaPersistentAttribute>(this.attributesSize()); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java index 8ecf5b375f..f8fef674d6 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaSingleRelationshipMapping.java @@ -28,6 +28,11 @@ public abstract class AbstractJavaSingleRelationshipMapping<T extends Relationsh } + @Override + public boolean isOverridableAssociationMapping() { + return true; + } + // **************** optional *********************************************** public boolean isOptional() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java index 099455724b..dc11452cf3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMapping.java @@ -40,7 +40,7 @@ public abstract class AbstractJavaTypeMapping extends AbstractJavaJpaContextNode } protected Annotation getResourceMappingAnnotation() { - return this.javaResourcePersistentType.getMappingAnnotation(getAnnotationName()); + return this.javaResourcePersistentType.getAnnotation(getAnnotationName()); } //***************** TypeMapping impl *************************************** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMappingProvider.java new file mode 100644 index 0000000000..11c652918f --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaTypeMappingProvider.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.context.java; + +import org.eclipse.jpt.core.context.java.JavaPersistentType; +import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; +import org.eclipse.jpt.utility.internal.StringTools; + +public abstract class AbstractJavaTypeMappingProvider + implements JavaTypeMappingProvider +{ + protected AbstractJavaTypeMappingProvider() { + super(); + } + + + /** + * Default implementation. Override if the mapping provider needs to do more analysis. + */ + public boolean test(JavaPersistentType persistentType) { + return persistentType.getResourcePersistentType().getAnnotation(getAnnotationName()) + != null; + } + + @Override + public String toString() { + return StringTools.buildToStringFor(this, this.getAnnotationName()); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaVersionMapping.java index cb3733f032..4d64b0b90f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaVersionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaVersionMapping.java @@ -54,7 +54,8 @@ public abstract class AbstractJavaVersionMapping } public ColumnAnnotation getResourceColumn() { - return (ColumnAnnotation) getResourcePersistentAttribute().getNonNullSupportingAnnotation(ColumnAnnotation.ANNOTATION_NAME); + return (ColumnAnnotation) getResourcePersistentAttribute(). + getNonNullAnnotation(ColumnAnnotation.ANNOTATION_NAME); } //************** JavaAttributeMapping implementation *************** @@ -153,7 +154,7 @@ public abstract class AbstractJavaVersionMapping } protected String getResourceConverterType() { - if (this.resourcePersistentAttribute.getSupportingAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { + if (this.resourcePersistentAttribute.getAnnotation(TemporalAnnotation.ANNOTATION_NAME) != null) { return Converter.TEMPORAL_CONVERTER; } return null; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java index e524a1ef78..8ca8fb555c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinColumnJoiningStrategy.java @@ -9,7 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.context.java; -import java.util.ListIterator; +import java.util.Iterator; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.BaseJoinColumn; import org.eclipse.jpt.core.context.Entity; @@ -25,7 +25,7 @@ import org.eclipse.jpt.core.resource.java.JoinColumnsAnnotation; import org.eclipse.jpt.core.resource.java.NestableAnnotation; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.db.Table; -import org.eclipse.jpt.utility.internal.iterators.TransformationListIterator; +import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; public class GenericJavaJoinColumnJoiningStrategy extends AbstractJavaJoinColumnJoiningStrategy @@ -63,9 +63,10 @@ public class GenericJavaJoinColumnJoiningStrategy } @Override - protected ListIterator<JoinColumnAnnotation> joinColumnAnnotations() { - return new TransformationListIterator<NestableAnnotation, JoinColumnAnnotation>( - this.getResourcePersistentAttribute().supportingAnnotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)) { + protected Iterator<JoinColumnAnnotation> joinColumnAnnotations() { + return new TransformationIterator<NestableAnnotation, JoinColumnAnnotation>( + this.getResourcePersistentAttribute().annotations( + JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)) { @Override protected JoinColumnAnnotation transform(NestableAnnotation next) { return (JoinColumnAnnotation) next; @@ -81,7 +82,7 @@ public class GenericJavaJoinColumnJoiningStrategy @Override protected JoinColumnAnnotation addAnnotation(int index) { return (JoinColumnAnnotation) this.getResourcePersistentAttribute(). - addSupportingAnnotation( + addAnnotation( index, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); @@ -90,7 +91,7 @@ public class GenericJavaJoinColumnJoiningStrategy @Override protected void removeAnnotation(int index) { this.getResourcePersistentAttribute(). - removeSupportingAnnotation( + removeAnnotation( index, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); @@ -99,7 +100,7 @@ public class GenericJavaJoinColumnJoiningStrategy @Override protected void moveAnnotation(int targetIndex, int sourceIndex) { this.getResourcePersistentAttribute(). - moveSupportingAnnotation( + moveAnnotation( targetIndex, sourceIndex, JoinColumnsAnnotation.ANNOTATION_NAME); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTableJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTableJoiningStrategy.java index fdcc1e2e68..8cbca2c542 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTableJoiningStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaJoinTableJoiningStrategy.java @@ -51,13 +51,13 @@ public class GenericJavaJoinTableJoiningStrategy @Override protected JoinTableAnnotation addAnnotation() { return (JoinTableAnnotation) this.resourcePersistentAttribute. - addSupportingAnnotation(JoinTableAnnotation.ANNOTATION_NAME); + addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); } @Override protected void removeAnnotation() { this.resourcePersistentAttribute. - removeSupportingAnnotation(JoinTableAnnotation.ANNOTATION_NAME); + removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); } @@ -80,9 +80,8 @@ public class GenericJavaJoinTableJoiningStrategy } public JoinTableAnnotation getAnnotation() { - return (JoinTableAnnotation) - this.resourcePersistentAttribute.getNonNullSupportingAnnotation( - JoinTableAnnotation.ANNOTATION_NAME); + return (JoinTableAnnotation) this.resourcePersistentAttribute. + getNonNullAnnotation(JoinTableAnnotation.ANNOTATION_NAME); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnJoiningStrategy.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnJoiningStrategy.java index 7b638d27f3..cb7fa70263 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnJoiningStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnJoiningStrategy.java @@ -124,7 +124,7 @@ public class GenericJavaPrimaryKeyJoinColumnJoiningStrategy protected PrimaryKeyJoinColumnAnnotation addAnnotation(int index) { return (PrimaryKeyJoinColumnAnnotation) this.resourcePersistentAttribute. - addSupportingAnnotation( + addAnnotation( index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); @@ -132,7 +132,7 @@ public class GenericJavaPrimaryKeyJoinColumnJoiningStrategy protected void removeAnnotation(int index) { this.resourcePersistentAttribute. - removeSupportingAnnotation( + removeAnnotation( index, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); @@ -140,7 +140,7 @@ public class GenericJavaPrimaryKeyJoinColumnJoiningStrategy protected void moveAnnotation(int targetIndex, int sourceIndex) { this.resourcePersistentAttribute. - moveSupportingAnnotation( + moveAnnotation( targetIndex, sourceIndex, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); @@ -169,8 +169,8 @@ public class GenericJavaPrimaryKeyJoinColumnJoiningStrategy } protected void initializePrimaryKeyJoinColumns() { - ListIterator<NestableAnnotation> annotations = - this.resourcePersistentAttribute.supportingAnnotations( + Iterator<NestableAnnotation> annotations = + this.resourcePersistentAttribute.annotations( PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); @@ -190,8 +190,8 @@ public class GenericJavaPrimaryKeyJoinColumnJoiningStrategy protected void updatePrimaryKeyJoinColumns() { ListIterator<JavaPrimaryKeyJoinColumn> joinColumns = primaryKeyJoinColumns(); - ListIterator<NestableAnnotation> annotations = - this.resourcePersistentAttribute.supportingAnnotations( + Iterator<NestableAnnotation> annotations = + this.resourcePersistentAttribute.annotations( PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java index ac1b162b0d..234c3ae401 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaBasicMappingProvider.java @@ -53,7 +53,7 @@ public class JavaBasicMappingProvider } @Override - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { + public boolean testDefault(JavaPersistentAttribute persistentAttribute) { return persistentAttribute.typeIsBasic(); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java index a4a6bb0876..8fe2c29106 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddableProvider.java @@ -15,29 +15,31 @@ import org.eclipse.jpt.core.context.java.JavaEmbeddable; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.utility.internal.StringTools; public class JavaEmbeddableProvider - implements JavaTypeMappingProvider + extends AbstractJavaTypeMappingProvider { - // singleton - private static final JavaEmbeddableProvider INSTANCE = new JavaEmbeddableProvider(); - + private static final JavaEmbeddableProvider INSTANCE = + new JavaEmbeddableProvider(); + + /** - * Return the singleton. + * Return the singleton */ public static JavaTypeMappingProvider instance() { return INSTANCE; } - + + /** - * Ensure single instance. + * Enforce singleton usage */ private JavaEmbeddableProvider() { super(); } - + + public String getKey() { return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; } @@ -49,10 +51,4 @@ public class JavaEmbeddableProvider public JavaEmbeddable buildMapping(JavaPersistentType parent, JpaFactory factory) { return factory.buildJavaEmbeddable(parent); } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getAnnotationName()); - } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java index 696f2687e5..cb87832a56 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEmbeddedMappingProvider.java @@ -53,7 +53,7 @@ public class JavaEmbeddedMappingProvider } @Override - public boolean defaultApplies(JavaPersistentAttribute persistentAttribute) { + public boolean testDefault(JavaPersistentAttribute persistentAttribute) { return persistentAttribute.getEmbeddable() != null; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java index 264237e2f2..fe94c62976 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityProvider.java @@ -15,32 +15,31 @@ import org.eclipse.jpt.core.context.java.JavaEntity; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.utility.internal.StringTools; -/** - * - */ public class JavaEntityProvider - implements JavaTypeMappingProvider + extends AbstractJavaTypeMappingProvider { - // singleton - private static final JavaEntityProvider INSTANCE = new JavaEntityProvider(); - + private static final JavaEntityProvider INSTANCE = + new JavaEntityProvider(); + + /** - * Return the singleton. + * Return the singleton */ public static JavaTypeMappingProvider instance() { return INSTANCE; } - + + /** - * Ensure single instance. + * Enforce singleton usage */ private JavaEntityProvider() { super(); } - + + public String getKey() { return MappingKeys.ENTITY_TYPE_MAPPING_KEY; } @@ -48,14 +47,8 @@ public class JavaEntityProvider public String getAnnotationName() { return EntityAnnotation.ANNOTATION_NAME; } - + public JavaEntity buildMapping(JavaPersistentType parent, JpaFactory factory) { return factory.buildJavaEntity(parent); } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getAnnotationName()); - } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java index 307a73b328..af9fd34eb6 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaIdMappingProvider.java @@ -9,15 +9,10 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.context.java; -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.resource.java.IdAnnotation; public class JavaIdMappingProvider - extends AbstractJavaAttributeMappingProvider + extends AbstractJavaIdMappingProvider { // singleton private static final JavaIdMappingProvider INSTANCE = @@ -38,17 +33,4 @@ public class JavaIdMappingProvider private JavaIdMappingProvider() { super(); } - - - public String getKey() { - return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; - } - - public String getAnnotationName() { - return IdAnnotation.ANNOTATION_NAME; - } - - public JavaAttributeMapping buildMapping(JavaPersistentAttribute parent, JpaFactory factory) { - return factory.buildJavaIdMapping(parent); - } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java index 5c04c85f33..062af54d74 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaMappedSuperclassProvider.java @@ -15,29 +15,31 @@ import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.utility.internal.StringTools; public class JavaMappedSuperclassProvider - implements JavaTypeMappingProvider + extends AbstractJavaTypeMappingProvider { - // singleton - private static final JavaMappedSuperclassProvider INSTANCE = new JavaMappedSuperclassProvider(); - + private static final JavaMappedSuperclassProvider INSTANCE = + new JavaMappedSuperclassProvider(); + + /** - * Return the singleton. + * Return the singleton */ public static JavaTypeMappingProvider instance() { return INSTANCE; } - + + /** - * Ensure single instance. + * Enforce singleton usage */ private JavaMappedSuperclassProvider() { super(); } - + + public String getKey() { return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; } @@ -45,14 +47,8 @@ public class JavaMappedSuperclassProvider public String getAnnotationName() { return MappedSuperclassAnnotation.ANNOTATION_NAME; } - + public JavaMappedSuperclass buildMapping(JavaPersistentType parent, JpaFactory factory) { return factory.buildJavaMappedSuperclass(parent); } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.getAnnotationName()); - } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java index 8d32a0abc8..fefecbf43f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaNullTypeMapping.java @@ -40,7 +40,7 @@ public class JavaNullTypeMapping extends AbstractJavaTypeMapping return false; } - public Iterator<String> correspondingAnnotationNames() { + public Iterator<String> supportingAnnotationNames() { return EmptyIterator.instance(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideAnnotation.java index 9b11534929..bb49e25227 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAssociationOverrideAnnotation.java @@ -54,8 +54,8 @@ public abstract class VirtualAssociationOverrideAnnotation } @Override - protected AssociationOverrideAnnotation addSupportingAnnotation() { - return (AssociationOverrideAnnotation) super.addSupportingAnnotation(); + protected AssociationOverrideAnnotation addAnnotation() { + return (AssociationOverrideAnnotation) super.addAnnotation(); } // ***** join columns diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideAnnotation.java index 0c8c83fdf6..25e71fa18e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualAttributeOverrideAnnotation.java @@ -34,8 +34,8 @@ public class VirtualAttributeOverrideAnnotation } @Override - protected AttributeOverrideAnnotation addSupportingAnnotation() { - return (AttributeOverrideAnnotation) super.addSupportingAnnotation(); + protected AttributeOverrideAnnotation addAnnotation() { + return (AttributeOverrideAnnotation) super.addAnnotation(); } // ****** column diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualOverrideAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualOverrideAnnotation.java index d50cc088b4..01f16152ed 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualOverrideAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/VirtualOverrideAnnotation.java @@ -33,8 +33,8 @@ public abstract class VirtualOverrideAnnotation } @Override - protected OverrideAnnotation addSupportingAnnotation() { - return (OverrideAnnotation) super.addSupportingAnnotation(); + protected OverrideAnnotation addAnnotation() { + return (OverrideAnnotation) super.addAnnotation(); } @Override @@ -49,7 +49,7 @@ public abstract class VirtualOverrideAnnotation public void setName(String name) { if (name != null) { - this.addSupportingAnnotation().setName(name); + this.addAnnotation().setName(name); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentType.java index b475e756b9..0fcc040311 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentType.java @@ -547,7 +547,7 @@ public abstract class AbstractOrmPersistentType protected boolean javaPersistentTypeHasSpecifiedAccess() { return this.javaPersistentType.getSpecifiedAccess() != null || - this.javaPersistentType.hasAnyAttributePersistenceAnnotations(); + this.javaPersistentType.hasAnyAnnotatedAttributes(); } protected JavaPersistentType buildJavaPersistentType() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaDiscriminatorColumn.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaDiscriminatorColumn.java index bae633c5e2..90217eafa2 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaDiscriminatorColumn.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaDiscriminatorColumn.java @@ -67,7 +67,8 @@ public class GenericJavaDiscriminatorColumn extends AbstractJavaNamedColumn<Disc @Override protected DiscriminatorColumnAnnotation getResourceColumn() { - return (DiscriminatorColumnAnnotation) this.persistenceResource.getNonNullSupportingAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME); + return (DiscriminatorColumnAnnotation) this.persistenceResource. + getNonNullAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME); } public boolean isResourceSpecified() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEnumeratedConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEnumeratedConverter.java index 6bba09e3a2..69c03c3f65 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEnumeratedConverter.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEnumeratedConverter.java @@ -46,11 +46,11 @@ public class GenericJavaEnumeratedConverter extends AbstractJavaJpaContextNode } public void addToResourceModel() { - this.resourcePersistenceAttribute.addSupportingAnnotation(getAnnotationName()); + this.resourcePersistenceAttribute.addAnnotation(getAnnotationName()); } public void removeFromResourceModel() { - this.resourcePersistenceAttribute.removeSupportingAnnotation(getAnnotationName()); + this.resourcePersistenceAttribute.removeAnnotation(getAnnotationName()); } public EnumType getEnumType() { @@ -79,7 +79,8 @@ public class GenericJavaEnumeratedConverter extends AbstractJavaJpaContextNode } protected EnumeratedAnnotation getResourceEnumerated() { - return (EnumeratedAnnotation) this.resourcePersistenceAttribute.getSupportingAnnotation(getAnnotationName()); + return (EnumeratedAnnotation) this.resourcePersistenceAttribute. + getAnnotation(getAnnotationName()); } protected void initialize(JavaResourcePersistentAttribute jrpa) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java index 9f8a1f1339..1f4586a705 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java @@ -53,7 +53,9 @@ public class GenericJavaGeneratorContainer extends AbstractJavaJpaContextNode throw new IllegalStateException("tableGenerator already exists"); //$NON-NLS-1$ } this.tableGenerator = getJpaFactory().buildJavaTableGenerator(this); - TableGeneratorAnnotation tableGeneratorResource = (TableGeneratorAnnotation) this.javaResourcePersistentMember.addSupportingAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); + TableGeneratorAnnotation tableGeneratorResource = + (TableGeneratorAnnotation) this.javaResourcePersistentMember. + addAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); this.tableGenerator.initialize(tableGeneratorResource); firePropertyChanged(TABLE_GENERATOR_PROPERTY, null, this.tableGenerator); return this.tableGenerator; @@ -65,7 +67,7 @@ public class GenericJavaGeneratorContainer extends AbstractJavaJpaContextNode } JavaTableGenerator oldTableGenerator = this.tableGenerator; this.tableGenerator = null; - this.javaResourcePersistentMember.removeSupportingAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentMember.removeAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); firePropertyChanged(TABLE_GENERATOR_PROPERTY, oldTableGenerator, null); } @@ -84,7 +86,9 @@ public class GenericJavaGeneratorContainer extends AbstractJavaJpaContextNode throw new IllegalStateException("sequenceGenerator already exists"); //$NON-NLS-1$ } this.sequenceGenerator = getJpaFactory().buildJavaSequenceGenerator(this); - SequenceGeneratorAnnotation sequenceGeneratorResource = (SequenceGeneratorAnnotation) this.javaResourcePersistentMember.addSupportingAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); + SequenceGeneratorAnnotation sequenceGeneratorResource = + (SequenceGeneratorAnnotation) this.javaResourcePersistentMember. + addAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); this.sequenceGenerator.initialize(sequenceGeneratorResource); firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, null, this.sequenceGenerator); return this.sequenceGenerator; @@ -96,7 +100,7 @@ public class GenericJavaGeneratorContainer extends AbstractJavaJpaContextNode } JavaSequenceGenerator oldSequenceGenerator = this.sequenceGenerator; this.sequenceGenerator = null; - this.javaResourcePersistentMember.removeSupportingAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentMember.removeAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); firePropertyChanged(SEQUENCE_GENERATOR_PROPERTY, oldSequenceGenerator,null); } @@ -161,7 +165,8 @@ public class GenericJavaGeneratorContainer extends AbstractJavaJpaContextNode } protected TableGeneratorAnnotation getResourceTableGenerator() { - return (TableGeneratorAnnotation) this.javaResourcePersistentMember.getSupportingAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); + return (TableGeneratorAnnotation) this.javaResourcePersistentMember. + getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME); } protected void updateSequenceGenerator() { @@ -188,9 +193,11 @@ public class GenericJavaGeneratorContainer extends AbstractJavaJpaContextNode } protected SequenceGeneratorAnnotation getResourceSequenceGenerator() { - return (SequenceGeneratorAnnotation) this.javaResourcePersistentMember.getSupportingAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); + return (SequenceGeneratorAnnotation) this.javaResourcePersistentMember. + getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME); } + //******************** Code Completion ************************* @Override diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaLobConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaLobConverter.java index fa8acb3516..0ab1f95469 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaLobConverter.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaLobConverter.java @@ -44,15 +44,16 @@ public class GenericJavaLobConverter extends AbstractJavaJpaContextNode } public void addToResourceModel() { - this.resourcePersistentAttribute.addSupportingAnnotation(getAnnotationName()); + this.resourcePersistentAttribute.addAnnotation(getAnnotationName()); } public void removeFromResourceModel() { - this.resourcePersistentAttribute.removeSupportingAnnotation(getAnnotationName()); + this.resourcePersistentAttribute.removeAnnotation(getAnnotationName()); } protected TemporalAnnotation getResourceLob() { - return (TemporalAnnotation) this.resourcePersistentAttribute.getSupportingAnnotation(getAnnotationName()); + return (TemporalAnnotation) this.resourcePersistentAttribute. + getAnnotation(getAnnotationName()); } protected void initialize(JavaResourcePersistentAttribute jrpa) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentType.java index 10590ddcc2..963887add8 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentType.java @@ -23,14 +23,20 @@ public class GenericJavaPersistentType } - //****************** PersistentType implementation ******************* + // **************** access type ******************************************* + /** - * GenericJavaPersistentType does not support specified access (no Access annotation in 1.0), so we return null + * GenericJavaPersistentType does not support specified access (no Access annotation in 1.0), + * so we return null */ - public AccessType getSpecifiedAccess() { + @Override + protected AccessType buildSpecifiedAccess() { return null; } + /** + * GenericJavaPersistentType does not support specified access (no Access annotation in 1.0) + */ public void setSpecifiedAccess(AccessType specifiedAccess) { throw new UnsupportedOperationException(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryContainer.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryContainer.java index 88cea9d202..3baaedc7bc 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryContainer.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaQueryContainer.java @@ -70,7 +70,11 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode public JavaNamedQuery addNamedQuery(int index) { JavaNamedQuery namedQuery = getJpaFactory().buildJavaNamedQuery(this); this.namedQueries.add(index, namedQuery); - NamedQueryAnnotation namedQueryAnnotation = (NamedQueryAnnotation) this.javaResourcePersistentMember.addSupportingAnnotation(index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); + NamedQueryAnnotation namedQueryAnnotation = + (NamedQueryAnnotation) this.javaResourcePersistentMember. + addAnnotation( + index, NamedQueryAnnotation.ANNOTATION_NAME, + NamedQueriesAnnotation.ANNOTATION_NAME); namedQuery.initialize(namedQueryAnnotation); fireItemAdded(NAMED_QUERIES_LIST, index, namedQuery); return namedQuery; @@ -90,7 +94,8 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode public void removeNamedQuery(int index) { JavaNamedQuery removedNamedQuery = this.namedQueries.remove(index); - this.javaResourcePersistentMember.removeSupportingAnnotation(index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentMember.removeAnnotation( + index, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); fireItemRemoved(NAMED_QUERIES_LIST, index, removedNamedQuery); } @@ -100,7 +105,8 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode public void moveNamedQuery(int targetIndex, int sourceIndex) { CollectionTools.move(this.namedQueries, targetIndex, sourceIndex); - this.javaResourcePersistentMember.moveSupportingAnnotation(targetIndex, sourceIndex, NamedQueriesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentMember.moveAnnotation( + targetIndex, sourceIndex, NamedQueriesAnnotation.ANNOTATION_NAME); fireItemMoved(NAMED_QUERIES_LIST, targetIndex, sourceIndex); } @@ -115,7 +121,11 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode public JavaNamedNativeQuery addNamedNativeQuery(int index) { JavaNamedNativeQuery namedNativeQuery = getJpaFactory().buildJavaNamedNativeQuery(this); this.namedNativeQueries.add(index, namedNativeQuery); - NamedNativeQueryAnnotation namedNativeQueryAnnotation = (NamedNativeQueryAnnotation) this.javaResourcePersistentMember.addSupportingAnnotation(index, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); + NamedNativeQueryAnnotation namedNativeQueryAnnotation = + (NamedNativeQueryAnnotation) this.javaResourcePersistentMember. + addAnnotation( + index, NamedNativeQueryAnnotation.ANNOTATION_NAME, + NamedNativeQueriesAnnotation.ANNOTATION_NAME); namedNativeQuery.initialize(namedNativeQueryAnnotation); fireItemAdded(NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); return namedNativeQuery; @@ -135,7 +145,9 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode public void removeNamedNativeQuery(int index) { JavaNamedNativeQuery removedNamedNativeQuery = this.namedNativeQueries.remove(index); - this.javaResourcePersistentMember.removeSupportingAnnotation(index, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentMember.removeAnnotation( + index, NamedNativeQueryAnnotation.ANNOTATION_NAME, + NamedNativeQueriesAnnotation.ANNOTATION_NAME); fireItemRemoved(NAMED_NATIVE_QUERIES_LIST, index, removedNamedNativeQuery); } @@ -145,7 +157,8 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { CollectionTools.move(this.namedNativeQueries, targetIndex, sourceIndex); - this.javaResourcePersistentMember.moveSupportingAnnotation(targetIndex, sourceIndex, NamedNativeQueriesAnnotation.ANNOTATION_NAME); + this.javaResourcePersistentMember.moveAnnotation( + targetIndex, sourceIndex, NamedNativeQueriesAnnotation.ANNOTATION_NAME); fireItemMoved(NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex); } @@ -158,13 +171,21 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode } protected void initializeNamedQueries() { - for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentMember.supportingAnnotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) { + for (Iterator<NestableAnnotation> stream = this.javaResourcePersistentMember. + annotations( + NamedQueryAnnotation.ANNOTATION_NAME, + NamedQueriesAnnotation.ANNOTATION_NAME); + stream.hasNext(); ) { this.namedQueries.add(buildNamedQuery((NamedQueryAnnotation) stream.next())); } } protected void initializeNamedNativeQueries() { - for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentMember.supportingAnnotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) { + for (Iterator<NestableAnnotation> stream = this.javaResourcePersistentMember. + annotations( + NamedNativeQueryAnnotation.ANNOTATION_NAME, + NamedNativeQueriesAnnotation.ANNOTATION_NAME); + stream.hasNext(); ) { this.namedNativeQueries.add(buildNamedNativeQuery((NamedNativeQueryAnnotation) stream.next())); } } @@ -189,7 +210,10 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode protected void updateNamedQueries() { ListIterator<JavaNamedQuery> queries = namedQueries(); - ListIterator<NestableAnnotation> resourceNamedQueries = this.javaResourcePersistentMember.supportingAnnotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> resourceNamedQueries = + this.javaResourcePersistentMember.annotations( + NamedQueryAnnotation.ANNOTATION_NAME, + NamedQueriesAnnotation.ANNOTATION_NAME); while (queries.hasNext()) { JavaNamedQuery namedQuery = queries.next(); @@ -208,7 +232,10 @@ public class GenericJavaQueryContainer extends AbstractJavaJpaContextNode protected void updateNamedNativeQueries() { ListIterator<JavaNamedNativeQuery> queries = namedNativeQueries(); - ListIterator<NestableAnnotation> resourceNamedNativeQueries = this.javaResourcePersistentMember.supportingAnnotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); + Iterator<NestableAnnotation> resourceNamedNativeQueries = + this.javaResourcePersistentMember.annotations( + NamedNativeQueryAnnotation.ANNOTATION_NAME, + NamedNativeQueriesAnnotation.ANNOTATION_NAME); while (queries.hasNext()) { JavaNamedNativeQuery namedQuery = queries.next(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTable.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTable.java index b71cdab1e8..ec81d5fb15 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTable.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTable.java @@ -21,9 +21,6 @@ import org.eclipse.jpt.core.resource.java.TableAnnotation; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; -/** - * - */ public class GenericJavaTable extends AbstractJavaTable implements JavaTable @@ -46,7 +43,8 @@ public class GenericJavaTable @Override protected TableAnnotation getAnnotation() { //TODO get the NullTable from the resource model or build it here in the context model?? - return (TableAnnotation) this.resourcePersistentMember.getNonNullSupportingAnnotation(getAnnotationName()); + return (TableAnnotation) this.resourcePersistentMember. + getNonNullAnnotation(getAnnotationName()); } public boolean isResourceSpecified() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java index ce7cb829f4..c52983e206 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java @@ -45,11 +45,11 @@ public class GenericJavaTemporalConverter extends AbstractJavaJpaContextNode } public void addToResourceModel() { - this.resourcePersistentAttribute.addSupportingAnnotation(getAnnotationName()); + this.resourcePersistentAttribute.addAnnotation(getAnnotationName()); } public void removeFromResourceModel() { - this.resourcePersistentAttribute.removeSupportingAnnotation(getAnnotationName()); + this.resourcePersistentAttribute.removeAnnotation(getAnnotationName()); } public TemporalType getTemporalType() { @@ -71,7 +71,8 @@ public class GenericJavaTemporalConverter extends AbstractJavaJpaContextNode protected TemporalAnnotation getResourceTemporal() { - return (TemporalAnnotation) this.resourcePersistentAttribute.getSupportingAnnotation(getAnnotationName()); + return (TemporalAnnotation) this.resourcePersistentAttribute. + getAnnotation(getAnnotationName()); } protected void initialize(JavaResourcePersistentAttribute jrpa) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/AbstractJavaManyToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/AbstractJavaManyToOneMapping2_0.java new file mode 100644 index 0000000000..33d32f0720 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/AbstractJavaManyToOneMapping2_0.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.jpa2.context.java; + +import java.util.Iterator; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaManyToOneMapping; +import org.eclipse.jpt.core.jpa2.context.DerivedId2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0; +import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; + +public abstract class AbstractJavaManyToOneMapping2_0 + extends AbstractJavaManyToOneMapping + implements JavaManyToOneMapping2_0 +{ + protected JavaDerivedId2_0 derivedId; + + + protected AbstractJavaManyToOneMapping2_0(JavaPersistentAttribute parent) { + super(parent); + this.derivedId = buildDerivedId(); + } + + + protected JavaDerivedId2_0 buildDerivedId() { + return new GenericJavaDerivedId2_0(this); + } + + @Override + public Iterator<String> supportingAnnotationNames() { + return new CompositeIterator( + super.supportingAnnotationNames(), + JPA.ID); + } + + public DerivedId2_0 getDerivedId() { + return this.derivedId; + } + + @Override + protected void initialize() { + super.initialize(); + this.derivedId.initialize(); + } + + @Override + protected void update() { + super.update(); + this.derivedId.update(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/AbstractJavaOneToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/AbstractJavaOneToOneMapping2_0.java new file mode 100644 index 0000000000..ac57481dd7 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/AbstractJavaOneToOneMapping2_0.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.jpa2.context.java; + +import java.util.Iterator; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaOneToOneMapping; +import org.eclipse.jpt.core.jpa2.context.DerivedId2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0; +import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; + +public abstract class AbstractJavaOneToOneMapping2_0 + extends AbstractJavaOneToOneMapping + implements JavaOneToOneMapping2_0 +{ + protected JavaDerivedId2_0 derivedId; + + + protected AbstractJavaOneToOneMapping2_0(JavaPersistentAttribute parent) { + super(parent); + this.derivedId = buildDerivedId(); + } + + + protected JavaDerivedId2_0 buildDerivedId() { + return new GenericJavaDerivedId2_0(this); + } + + @Override + public Iterator<String> supportingAnnotationNames() { + return new CompositeIterator( + super.supportingAnnotationNames(), + JPA.ID); + } + + public DerivedId2_0 getDerivedId() { + return this.derivedId; + } + + @Override + protected void initialize() { + super.initialize(); + this.derivedId.initialize(); + } + + @Override + protected void update() { + super.update(); + this.derivedId.update(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaDerivedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaDerivedId2_0.java new file mode 100644 index 0000000000..444e0d2b85 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaDerivedId2_0.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.jpa2.context.java; + +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; +import org.eclipse.jpt.core.jpa2.context.java.JavaDerivedId2_0; +import org.eclipse.jpt.core.jpa2.context.java.JavaSingleRelationshipMapping2_0; +import org.eclipse.jpt.core.resource.java.IdAnnotation; +import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.core.utility.TextRange; + +public class GenericJavaDerivedId2_0 + extends AbstractJavaJpaContextNode + implements JavaDerivedId2_0 +{ + protected boolean derivedId; + + + public GenericJavaDerivedId2_0(JavaSingleRelationshipMapping2_0 parent) { + super(parent); + } + + + @Override + public JavaSingleRelationshipMapping2_0 getParent() { + return (JavaSingleRelationshipMapping2_0) super.getParent(); + } + + protected JavaResourcePersistentAttribute getResourceAttribute() { + return getParent().getPersistentAttribute().getResourcePersistentAttribute(); + } + + public boolean isDerivedId() { + return this.derivedId; + } + + public void setDerivedId(boolean newDerivedId) { + if (this.derivedId == newDerivedId) { + return; + } + boolean oldDerivedId = this.derivedId; + this.derivedId = newDerivedId; + + if (newDerivedId) { + addIdAnnotation(); + } + else { + removeIdAnnotation(); + } + firePropertyChanged(DERIVED_ID_PROPERTY, oldDerivedId, newDerivedId); + } + + protected void setDerivedId_(boolean newDerivedId) { + boolean oldDerivedId = this.derivedId; + this.derivedId = newDerivedId; + firePropertyChanged(DERIVED_ID_PROPERTY, oldDerivedId, newDerivedId); + } + + protected boolean getResourceDerivedId() { + return getIdAnnotation() != null; + } + + protected IdAnnotation getIdAnnotation() { + return (IdAnnotation) getResourceAttribute().getAnnotation(JPA.ID); + } + + protected void addIdAnnotation() { + getResourceAttribute().addAnnotation(JPA.ID); + } + + protected void removeIdAnnotation() { + getResourceAttribute().removeAnnotation(JPA.ID); + } + + public void initialize() { + this.derivedId = getResourceDerivedId(); + } + + public void update() { + this.setDerivedId_(getResourceDerivedId()); + } + + public TextRange getValidationTextRange(CompilationUnit astRoot) { + IdAnnotation annotation = this.getIdAnnotation(); + return annotation == null ? null : annotation.getTextRange(astRoot); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0.java new file mode 100644 index 0000000000..5e450fdd32 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaManyToOneMapping2_0.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.jpa2.context.ManyToOneMapping2_0; + +public class GenericJavaManyToOneMapping2_0 + extends AbstractJavaManyToOneMapping2_0 + implements ManyToOneMapping2_0 +{ + public GenericJavaManyToOneMapping2_0(JavaPersistentAttribute parent) { + super(parent); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0.java new file mode 100644 index 0000000000..b14c6edee7 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaOneToOneMapping2_0.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0; + +public class GenericJavaOneToOneMapping2_0 + extends AbstractJavaOneToOneMapping2_0 + implements OneToOneMapping2_0 +{ + public GenericJavaOneToOneMapping2_0(JavaPersistentAttribute parent) { + super(parent); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java index 7cd3595f97..aefe7cfc6c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java @@ -52,7 +52,9 @@ public class GenericJavaPersistentAttribute2_0 } protected AccessType buildSpecifiedAccess() { - Access2_0Annotation accessAnnotation = (Access2_0Annotation) this.resourcePersistentAttribute.getSupportingAnnotation(Access2_0Annotation.ANNOTATION_NAME); + Access2_0Annotation accessAnnotation = + (Access2_0Annotation) this.resourcePersistentAttribute. + getAnnotation(Access2_0Annotation.ANNOTATION_NAME); return accessAnnotation == null ? null : AccessType.fromJavaResourceModel(accessAnnotation.getValue()); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentType2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentType2_0.java index 05d18858d6..469dc9fd33 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentType2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentType2_0.java @@ -23,22 +23,23 @@ public class GenericJavaPersistentType2_0 extends AbstractJavaPersistentType implements JavaPersistentType2_0 { - protected AccessType specifiedAccess; - public GenericJavaPersistentType2_0(PersistentType.Owner parent, JavaResourcePersistentType jrpt) { super(parent, jrpt); } + protected Access2_0Annotation getAccessAnnotation() { - return (Access2_0Annotation) this.resourcePersistentType.getNonNullSupportingAnnotation(getAccessAnnotationName()); + return (Access2_0Annotation) this.resourcePersistentType. + getNonNullAnnotation(getAccessAnnotationName()); } - + protected String getAccessAnnotationName() { return Access2_0Annotation.ANNOTATION_NAME; } - public AccessType getSpecifiedAccess() { - return this.specifiedAccess; + @Override + protected AccessType buildSpecifiedAccess() { + return this.getResourceAccess(); } public void setSpecifiedAccess(AccessType specifiedAccess) { @@ -62,13 +63,7 @@ public class GenericJavaPersistentType2_0 } @Override - protected void initializeAccess() { - super.initializeAccess(); - this.specifiedAccess = this.getResourceAccess(); - } - - @Override - protected void updateAccess() { + public void updateAccess() { super.updateAccess(); this.setSpecifiedAccess_(this.getResourceAccess()); } @@ -76,9 +71,8 @@ public class GenericJavaPersistentType2_0 protected AccessType getResourceAccess() { return AccessType.fromJavaResourceModel(this.getAccessAnnotation().getValue()); } - + public void synchronizeStaticMetaModel() { // TODO } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/JavaIdMappingProvider2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/JavaIdMappingProvider2_0.java new file mode 100644 index 0000000000..e7ce8444b0 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/JavaIdMappingProvider2_0.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.internal.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaIdMappingProvider; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; +import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; + +public class JavaIdMappingProvider2_0 + extends AbstractJavaIdMappingProvider +{ + // singleton + private static final JavaIdMappingProvider2_0 INSTANCE = + new JavaIdMappingProvider2_0(); + + + /** + * Return the singleton. + */ + public static JavaAttributeMappingProvider instance() { + return INSTANCE; + } + + + /** + * Enforce singleton usage + */ + private JavaIdMappingProvider2_0() { + super(); + } + + + @Override + public boolean testSpecified(JavaPersistentAttribute persistentAttribute) { + return super.testSpecified(persistentAttribute) && ! testDerivedId(persistentAttribute); + } + + /** + * Return whether the Id annotation, if present, is used as a supporting annotation for + * 1-1 or M-1 mapping, rather than as a primary mapping annotation + */ + protected boolean testDerivedId(JavaPersistentAttribute persistentAttribute) { + JavaResourcePersistentAttribute resourceAttribute = + persistentAttribute.getResourcePersistentAttribute(); + return resourceAttribute.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME) != null + || resourceAttribute.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME) != null; + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaAnnotationDefinitionProvider.java index 6ee4c837d7..44f6bb267e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaAnnotationDefinitionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaAnnotationDefinitionProvider.java @@ -58,37 +58,35 @@ import org.eclipse.jpt.core.internal.resource.java.VersionAnnotationDefinition; import org.eclipse.jpt.core.resource.java.AnnotationDefinition; /** - * Provides annotations for JPA 2.0, including those in JPA 1.0 + * Support for existing JPA 1.0 annotations, new JPA 2.0 annotations, and + * augmented support for annotations changed from 1.0 to 2.0 */ public class Generic2_0JpaAnnotationDefinitionProvider extends AbstractJpaAnnotationDefintionProvider { // singleton - private static final JpaAnnotationDefinitionProvider INSTANCE = new Generic2_0JpaAnnotationDefinitionProvider(); - + private static final JpaAnnotationDefinitionProvider INSTANCE = + new Generic2_0JpaAnnotationDefinitionProvider(); + + /** - * Return the singleton. + * Return the singleton */ public static JpaAnnotationDefinitionProvider instance() { return INSTANCE; } - + + /** - * Ensure single instance. + * Enforce singleton usage */ private Generic2_0JpaAnnotationDefinitionProvider() { super(); } - - @Override - protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(EmbeddableAnnotationDefinition.instance()); - definitions.add(EntityAnnotationDefinition.instance()); - definitions.add(MappedSuperclassAnnotationDefinition.instance()); - } + @Override - protected void addTypeSupportingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { + protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { definitions.add(Access2_0AnnotationDefinition.instance()); definitions.add(AssociationOverride2_0AnnotationDefinition.instance()); definitions.add(AssociationOverrides2_0AnnotationDefinition.instance()); @@ -96,8 +94,11 @@ public class Generic2_0JpaAnnotationDefinitionProvider definitions.add(AttributeOverridesAnnotationDefinition.instance()); definitions.add(DiscriminatorColumnAnnotationDefinition.instance()); definitions.add(DiscriminatorValueAnnotationDefinition.instance()); + definitions.add(EmbeddableAnnotationDefinition.instance()); + definitions.add(EntityAnnotationDefinition.instance()); definitions.add(IdClassAnnotationDefinition.instance()); definitions.add(InheritanceAnnotationDefinition.instance()); + definitions.add(MappedSuperclassAnnotationDefinition.instance()); definitions.add(NamedQueryAnnotationDefinition.instance()); definitions.add(NamedQueriesAnnotationDefinition.instance()); definitions.add(NamedNativeQueryAnnotationDefinition.instance()); @@ -110,42 +111,37 @@ public class Generic2_0JpaAnnotationDefinitionProvider definitions.add(TableAnnotationDefinition.instance()); definitions.add(TableGeneratorAnnotationDefinition.instance()); } - - @Override - protected void addAttributeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(BasicAnnotationDefinition.instance()); - definitions.add(EmbeddedAnnotationDefinition.instance()); - definitions.add(EmbeddedIdAnnotationDefinition.instance()); - definitions.add(IdAnnotationDefinition.instance()); - definitions.add(ManyToManyAnnotationDefinition.instance()); - definitions.add(ManyToOneAnnotationDefinition.instance()); - definitions.add(OneToManyAnnotationDefinition.instance()); - definitions.add(OneToOneAnnotationDefinition.instance()); - definitions.add(TransientAnnotationDefinition.instance()); - definitions.add(VersionAnnotationDefinition.instance()); - } @Override - protected void addAttributeSupportingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { + protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { definitions.add(Access2_0AnnotationDefinition.instance()); definitions.add(AssociationOverride2_0AnnotationDefinition.instance()); definitions.add(AssociationOverrides2_0AnnotationDefinition.instance()); definitions.add(AttributeOverrideAnnotationDefinition.instance()); definitions.add(AttributeOverridesAnnotationDefinition.instance()); + definitions.add(BasicAnnotationDefinition.instance()); definitions.add(ColumnAnnotationDefinition.instance()); + definitions.add(EmbeddedAnnotationDefinition.instance()); + definitions.add(EmbeddedIdAnnotationDefinition.instance()); definitions.add(EnumeratedAnnotationDefinition.instance()); definitions.add(GeneratedValueAnnotationDefinition.instance()); + definitions.add(IdAnnotationDefinition.instance()); definitions.add(JoinColumnAnnotationDefinition.instance()); definitions.add(JoinColumnsAnnotationDefinition.instance()); definitions.add(JoinTableAnnotationDefinition.instance()); definitions.add(LobAnnotationDefinition.instance()); + definitions.add(ManyToManyAnnotationDefinition.instance()); + definitions.add(ManyToOneAnnotationDefinition.instance()); definitions.add(MapKeyAnnotationDefinition.instance()); + definitions.add(OneToManyAnnotationDefinition.instance()); + definitions.add(OneToOneAnnotationDefinition.instance()); definitions.add(OrderByAnnotationDefinition.instance()); definitions.add(PrimaryKeyJoinColumnAnnotationDefinition.instance()); definitions.add(PrimaryKeyJoinColumnsAnnotationDefinition.instance()); definitions.add(SequenceGenerator2_0AnnotationDefinition.instance()); definitions.add(TableGeneratorAnnotationDefinition.instance()); definitions.add(TemporalAnnotationDefinition.instance()); + definitions.add(TransientAnnotationDefinition.instance()); + definitions.add(VersionAnnotationDefinition.instance()); } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaPlatformProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaPlatformProvider.java index cf9cfff3e2..34fd6ba6da 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaPlatformProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/Generic2_0JpaPlatformProvider.java @@ -23,7 +23,6 @@ import org.eclipse.jpt.core.internal.context.java.JavaEmbeddableProvider; import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedIdMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaEntityProvider; -import org.eclipse.jpt.core.internal.context.java.JavaIdMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaManyToManyMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaManyToOneMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaMappedSuperclassProvider; @@ -35,6 +34,7 @@ import org.eclipse.jpt.core.internal.context.orm.GenericOrmMappingFileDefinition import org.eclipse.jpt.core.internal.jpa2.Orm2_0ResourceModelProvider; import org.eclipse.jpt.core.internal.jpa2.Persistence2_0ResourceModelProvider; import org.eclipse.jpt.core.internal.jpa2.context.GenericOrm2_0MappingFileDefinition; +import org.eclipse.jpt.core.internal.jpa2.context.java.JavaIdMappingProvider2_0; import org.eclipse.jpt.core.internal.platform.AbstractJpaPlatformProvider; /** @@ -111,7 +111,7 @@ public class Generic2_0JpaPlatformProvider return new JavaAttributeMappingProvider[] { JavaTransientMappingProvider.instance(), //JavaElementCollectionMappingProvider.instance(), - JavaIdMappingProvider.instance(), + JavaIdMappingProvider2_0.instance(), JavaVersionMappingProvider.instance(), JavaBasicMappingProvider.instance(), JavaEmbeddedMappingProvider.instance(), diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/GenericJpaFactory2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/GenericJpaFactory2_0.java index 4234f1c341..b5deb2865d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/GenericJpaFactory2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/platform/GenericJpaFactory2_0.java @@ -17,7 +17,6 @@ import org.eclipse.jpt.core.context.JpaRootContextNode; import org.eclipse.jpt.core.context.MappingFile; import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.PersistentType.Owner; import org.eclipse.jpt.core.context.java.JavaAssociationOverride; import org.eclipse.jpt.core.context.java.JavaAssociationOverrideRelationshipReference; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; @@ -63,9 +62,10 @@ import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.core.context.persistence.PersistenceXml; import org.eclipse.jpt.core.internal.jpa2.GenericJpaProject2_0; import org.eclipse.jpt.core.internal.jpa2.context.GenericRootContextNode2_0; -import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJarFile2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaAssociationOverrideRelationshipReference2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaEmbeddable2_0; +import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaManyToOneMapping2_0; +import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaOneToOneMapping2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaPersistentAttribute2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaPersistentType2_0; import org.eclipse.jpt.core.internal.jpa2.context.java.GenericJavaSequenceGenerator2_0; @@ -99,10 +99,8 @@ import org.eclipse.jpt.core.internal.platform.AbstractJpaFactory; import org.eclipse.jpt.core.jpa2.JpaFactory2_0; import org.eclipse.jpt.core.jpa2.JpaProject2_0; import org.eclipse.jpt.core.jpa2.context.JpaRootContextNode2_0; -import org.eclipse.jpt.core.jpa2.context.java.JarFile2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmSequenceGenerator2_0; import org.eclipse.jpt.core.jpa2.context.persistence.ClassRef2_0; -import org.eclipse.jpt.core.jpa2.context.persistence.JarFileRef2_0; import org.eclipse.jpt.core.jpa2.context.persistence.MappingFileRef2_0; import org.eclipse.jpt.core.jpa2.context.persistence.Persistence2_0; import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0; @@ -124,7 +122,6 @@ import org.eclipse.jpt.core.jpa2.resource.orm.XmlSequenceGenerator; import org.eclipse.jpt.core.jpa2.resource.orm.XmlTransient; import org.eclipse.jpt.core.jpa2.resource.orm.XmlVersion; import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.resource.orm.XmlGeneratorContainer; @@ -137,8 +134,10 @@ import org.eclipse.jpt.core.resource.persistence.XmlPersistence; import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; import org.eclipse.jpt.core.resource.xml.JpaXmlResource; + /** - * JPA 2.0 factory + * Central class that allows extenders to easily replace implementations of + * various Dali interfaces. */ public class GenericJpaFactory2_0 extends AbstractJpaFactory @@ -147,39 +146,39 @@ public class GenericJpaFactory2_0 public GenericJpaFactory2_0() { super(); } - - + + // ********** Core Model ********** @Override public JpaProject2_0 buildJpaProject(JpaProject.Config config) throws CoreException { return new GenericJpaProject2_0(config); } - - + + // ********** Context Nodes ********** - + @Override public JpaRootContextNode2_0 buildRootContextNode(JpaProject parent) { return new GenericRootContextNode2_0((JpaProject2_0) parent); } public MappingFile buildMappingFile2_0(MappingFileRef parent, JpaXmlResource resource) { - return this.buildOrmXml2_0(parent, resource); + return buildOrmXml2_0((MappingFileRef2_0) parent, resource); } - + protected GenericOrmXml2_0 buildOrmXml2_0(MappingFileRef parent, JpaXmlResource resource) { return new GenericOrmXml2_0((MappingFileRef2_0) parent, resource); } - + // ********** Persistence Context Model ********** - + @Override public PersistenceXml2_0 buildPersistenceXml(JpaRootContextNode parent, JpaXmlResource resource) { return new GenericPersistenceXml2_0((JpaRootContextNode2_0) parent, resource); } - + @Override public Persistence2_0 buildPersistence(PersistenceXml parent, XmlPersistence xmlPersistence) { return new GenericPersistence2_0((PersistenceXml2_0) parent, xmlPersistence); @@ -189,43 +188,86 @@ public class GenericJpaFactory2_0 public PersistenceUnit2_0 buildPersistenceUnit(Persistence parent, XmlPersistenceUnit xmlPersistenceUnit) { return new GenericPersistenceUnit2_0((Persistence2_0) parent, xmlPersistenceUnit); } - + @Override public MappingFileRef2_0 buildMappingFileRef(PersistenceUnit parent, XmlMappingFileRef xmlMappingFileRef) { return new GenericMappingFileRef2_0((PersistenceUnit2_0) parent, xmlMappingFileRef); } - + @Override public MappingFileRef2_0 buildImpliedMappingFileRef(PersistenceUnit parent) { return new ImpliedMappingFileRef2_0((PersistenceUnit2_0) parent, JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH ); } - + @Override public ClassRef2_0 buildClassRef(PersistenceUnit parent, XmlJavaClassRef classRef) { return new GenericClassRef2_0((PersistenceUnit2_0) parent, classRef); } - + @Override public ClassRef2_0 buildClassRef(PersistenceUnit parent, String className) { return new GenericClassRef2_0((PersistenceUnit2_0) parent, className); } - + @Override public JarFileRef buildJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { return new GenericJarFileRef2_0((PersistenceUnit2_0) parent, xmlJarFileRef); } - - - // ********** JPA 2.0 ORM Context Model ********** - + + + // ********** Java Context Model ********** + + @Override + public JavaPersistentType buildJavaPersistentType(PersistentType.Owner owner, JavaResourcePersistentType jrpt) { + return new GenericJavaPersistentType2_0(owner, jrpt); + } + + @Override + public JavaPersistentAttribute buildJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa) { + return new GenericJavaPersistentAttribute2_0(parent, jrpa); + } + + @Override + public JavaEmbeddable buildJavaEmbeddable(JavaPersistentType parent) { + return new GenericJavaEmbeddable2_0(parent); + } + + @Override + public JavaManyToOneMapping buildJavaManyToOneMapping(JavaPersistentAttribute parent) { + return new GenericJavaManyToOneMapping2_0(parent); + } + + @Override + public JavaOneToOneMapping buildJavaOneToOneMapping(JavaPersistentAttribute parent) { + return new GenericJavaOneToOneMapping2_0(parent); + } + + @Override + public JavaSequenceGenerator buildJavaSequenceGenerator(JavaJpaContextNode parent) { + return new GenericJavaSequenceGenerator2_0(parent); + } + + @Override + public JavaAssociationOverrideRelationshipReference buildJavaAssociationOverrideRelationshipReference(JavaAssociationOverride parent) { + return new GenericJavaAssociationOverrideRelationshipReference2_0(parent); + } + + @Override + public AssociationOverrideAnnotation buildJavaVirtualAssociationOverrideAnnotation(JavaResourcePersistentType jrpt, String name, JoiningStrategy joiningStrategy) { + return new VirtualAssociationOverride2_0Annotation(jrpt, name, joiningStrategy); + } + + + // ********** Generic 2.0-specific ORM Context Model ********** + public EntityMappings buildEntityMappings2_0(GenericOrmXml2_0 parent, XmlEntityMappings xmlEntityMappings) { return new GenericEntityMappings2_0(parent, xmlEntityMappings); } - + public PersistenceUnitMetadata buildPersistenceUnitMetadata2_0(GenericEntityMappings2_0 parent, XmlEntityMappings xmlEntityMappings) { return new GenericPersistenceUnitMetadata2_0(parent, xmlEntityMappings); } - + public OrmPersistentType buildOrmPersistentType2_0(EntityMappings parent, XmlTypeMapping resourceMapping) { return new GenericOrmPersistentType2_0(parent, resourceMapping); } @@ -241,55 +283,55 @@ public class GenericJpaFactory2_0 public OrmMappedSuperclass buildOrmMappedSuperclass2_0(OrmPersistentType parent, XmlMappedSuperclass resourceMapping) { return buildOrmMappedSuperclass(parent, resourceMapping); } - + public OrmPersistentAttribute buildOrmPersistentAttribute2_0(OrmPersistentType parent, OrmPersistentAttribute.Owner owner, XmlAttributeMapping resourceMapping) { return new GenericOrmPersistentAttribute2_0(parent, owner, resourceMapping); } - + public OrmBasicMapping buildOrmBasicMapping2_0(OrmPersistentAttribute parent, XmlBasic resourceMapping) { return buildOrmBasicMapping(parent, resourceMapping); } - + public OrmEmbeddedMapping buildOrmEmbeddedMapping2_0(OrmPersistentAttribute parent, XmlEmbedded resourceMapping) { return buildOrmEmbeddedMapping(parent, resourceMapping); } - + public OrmEmbeddedIdMapping buildOrmEmbeddedIdMapping2_0(OrmPersistentAttribute parent, XmlEmbeddedId resourceMapping) { return buildOrmEmbeddedIdMapping(parent, resourceMapping); } - + public OrmIdMapping buildOrmIdMapping2_0(OrmPersistentAttribute parent, XmlId resourceMapping) { return buildOrmIdMapping(parent, resourceMapping); } - + public OrmManyToManyMapping buildOrmManyToManyMapping2_0(OrmPersistentAttribute parent, XmlManyToMany resourceMapping) { return buildOrmManyToManyMapping(parent, resourceMapping); } - + public OrmManyToOneMapping buildOrmManyToOneMapping2_0(OrmPersistentAttribute parent, XmlManyToOne resourceMapping) { return buildOrmManyToOneMapping(parent, resourceMapping); } - + public OrmOneToManyMapping buildOrmOneToManyMapping2_0(OrmPersistentAttribute parent, XmlOneToMany resourceMapping) { return buildOrmOneToManyMapping(parent, resourceMapping); } - + public OrmOneToOneMapping buildOrmOneToOneMapping2_0(OrmPersistentAttribute parent, XmlOneToOne resourceMapping) { return buildOrmOneToOneMapping(parent, resourceMapping); } - + public OrmTransientMapping buildOrmTransientMapping2_0(OrmPersistentAttribute parent, XmlTransient resourceMapping) { return buildOrmTransientMapping(parent, resourceMapping); } - + public OrmVersionMapping buildOrmVersionMapping2_0(OrmPersistentAttribute parent, XmlVersion resourceMapping) { return buildOrmVersionMapping(parent, resourceMapping); } - + public OrmAttributeMapping buildOrmNullAttributeMapping2_0(OrmPersistentAttribute parent, XmlNullAttributeMapping resourceMapping) { return buildOrmNullAttributeMapping(parent, resourceMapping); } - + public OrmGeneratorContainer buildOrmGeneratorContainer2_0(XmlContextNode parent, XmlGeneratorContainer resourceGeneratorContainer) { return super.buildOrmGeneratorContainer(parent, resourceGeneratorContainer); } @@ -297,90 +339,48 @@ public class GenericJpaFactory2_0 public OrmSequenceGenerator2_0 buildOrmSequenceGenerator2_0(XmlContextNode parent, XmlSequenceGenerator resourceSequenceGenerator) { return new GenericOrmSequenceGenerator2_0(parent, resourceSequenceGenerator); } - + public XmlBasic buildVirtualXmlBasic2_0(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { return new VirtualXmlBasic2_0(ormTypeMapping, javaBasicMapping); } - + public XmlId buildVirtualXmlId2_0(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { return new VirtualXmlId2_0(ormTypeMapping, javaIdMapping); } - + public XmlEmbeddedId buildVirtualXmlEmbeddedId2_0(OrmTypeMapping ormTypeMapping, JavaEmbeddedIdMapping javaEmbeddedIdMapping) { return new VirtualXmlEmbeddedId2_0(ormTypeMapping, javaEmbeddedIdMapping); } - + public XmlEmbedded buildVirtualXmlEmbedded2_0(OrmTypeMapping ormTypeMapping, JavaEmbeddedMapping javaEmbeddedMapping) { return new VirtualXmlEmbedded2_0(ormTypeMapping, javaEmbeddedMapping); } - + public XmlManyToMany buildVirtualXmlManyToMany2_0(OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { return new VirtualXmlManyToMany2_0(ormTypeMapping, javaManyToManyMapping); } - + public XmlManyToOne buildVirtualXmlManyToOne2_0(OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { return new VirtualXmlManyToOne2_0(ormTypeMapping, javaManyToOneMapping); } - + public XmlOneToMany buildVirtualXmlOneToMany2_0(OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { return new VirtualXmlOneToMany2_0(ormTypeMapping, javaOneToManyMapping); } - + public XmlOneToOne buildVirtualXmlOneToOne2_0(OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { return new VirtualXmlOneToOne2_0(ormTypeMapping, javaOneToOneMapping); } - + public XmlTransient buildVirtualXmlTransient2_0(OrmTypeMapping ormTypeMapping, JavaTransientMapping javaTransientMapping) { return new VirtualXmlTransient2_0(ormTypeMapping, javaTransientMapping); } - + public XmlVersion buildVirtualXmlVersion2_0(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { return new VirtualXmlVersion2_0(ormTypeMapping, javaVersionMapping); } - + public XmlNullAttributeMapping buildVirtualXmlNullAttributeMapping2_0(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { return new VirtualXmlNullAttributeMapping2_0(ormTypeMapping, javaAttributeMapping); } - - - // ********** Java Context Model ********** - - @Override - public JavaPersistentType buildJavaPersistentType(Owner owner, JavaResourcePersistentType jrpt) { - return new GenericJavaPersistentType2_0(owner, jrpt); - } - - @Override - public JavaPersistentAttribute buildJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa) { - return new GenericJavaPersistentAttribute2_0(parent, jrpa); - } - - @Override - public JavaEmbeddable buildJavaEmbeddable(JavaPersistentType parent) { - return new GenericJavaEmbeddable2_0(parent); - } - - @Override - public JavaSequenceGenerator buildJavaSequenceGenerator(JavaJpaContextNode parent) { - return new GenericJavaSequenceGenerator2_0(parent); - } - - @Override - public JavaAssociationOverrideRelationshipReference buildJavaAssociationOverrideRelationshipReference(JavaAssociationOverride parent) { - return new GenericJavaAssociationOverrideRelationshipReference2_0(parent); - } - - @Override - public AssociationOverrideAnnotation buildJavaVirtualAssociationOverrideAnnotation(JavaResourcePersistentType jrpt, String name, JoiningStrategy joiningStrategy) { - return new VirtualAssociationOverride2_0Annotation(jrpt, name, joiningStrategy); - } - - - // ********** JAR Context Model ********** - - @Override - public JarFile2_0 buildJarFile(JarFileRef parent, JavaResourcePackageFragmentRoot jarResourcePackageFragmentRoot) { - return new GenericJarFile2_0((JarFileRef2_0) parent, jarResourcePackageFragmentRoot); - } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAccess2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAccess2_0Annotation.java index 3e3239afaa..d3990a5aaf 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAccess2_0Annotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/NullAccess2_0Annotation.java @@ -33,8 +33,8 @@ public class NullAccess2_0Annotation } @Override - protected Access2_0Annotation addSupportingAnnotation() { - return (Access2_0Annotation) super.addSupportingAnnotation(); + protected Access2_0Annotation addAnnotation() { + return (Access2_0Annotation) super.addAnnotation(); } // ***** value @@ -44,7 +44,7 @@ public class NullAccess2_0Annotation public void setValue(AccessType value) { if (value != null) { - this.addSupportingAnnotation().setValue(value); + this.addAnnotation().setValue(value); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverride2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverride2_0Annotation.java index a6af8e8c69..27e2fcb276 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverride2_0Annotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/binary/BinaryAssociationOverride2_0Annotation.java @@ -14,7 +14,7 @@ import org.eclipse.jpt.core.internal.resource.java.NullJoinTableAnnotation; import org.eclipse.jpt.core.internal.resource.java.binary.BinaryAssociationOverrideAnnotation; import org.eclipse.jpt.core.internal.resource.java.binary.BinaryJoinTableAnnotation; import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA; +import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; import org.eclipse.jpt.core.resource.java.JavaResourceNode; import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; @@ -74,7 +74,7 @@ public final class BinaryAssociationOverride2_0Annotation } private IAnnotation getJdtJoinTable() { - return (IAnnotation) this.getJdtMemberValue(JPA.ASSOCIATION_OVERRIDE__JOIN_TABLE); + return (IAnnotation) this.getJdtMemberValue(JPA2_0.ASSOCIATION_OVERRIDE__JOIN_TABLE); } private void setJoinTable(JoinTableAnnotation column) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverride2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverride2_0Annotation.java index dfc227ab48..02cf8620ad 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverride2_0Annotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceAssociationOverride2_0Annotation.java @@ -18,7 +18,7 @@ import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; import org.eclipse.jpt.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter; import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; import org.eclipse.jpt.core.jpa2.resource.java.AssociationOverride2_0Annotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA; +import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; import org.eclipse.jpt.core.resource.java.JavaResourceNode; import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; @@ -125,7 +125,7 @@ public final class SourceAssociationOverride2_0Annotation } static DeclarationAnnotationAdapter buildJoinTableAnnotationAdapter(DeclarationAnnotationAdapter associationOverrideAnnotationAdapter) { - return new NestedDeclarationAnnotationAdapter(associationOverrideAnnotationAdapter, JPA.ASSOCIATION_OVERRIDE__JOIN_TABLE, org.eclipse.jpt.core.resource.java.JPA.JOIN_TABLE); + return new NestedDeclarationAnnotationAdapter(associationOverrideAnnotationAdapter, JPA2_0.ASSOCIATION_OVERRIDE__JOIN_TABLE, org.eclipse.jpt.core.resource.java.JPA.JOIN_TABLE); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceSequenceGenerator2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceSequenceGenerator2_0Annotation.java index a274ab4630..f1c09d3aa0 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceSequenceGenerator2_0Annotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/resource/java/source/SourceSequenceGenerator2_0Annotation.java @@ -11,7 +11,7 @@ package org.eclipse.jpt.core.internal.jpa2.resource.java.source; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.internal.resource.java.source.SourceSequenceGeneratorAnnotation; -import org.eclipse.jpt.core.jpa2.resource.java.JPA; +import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; import org.eclipse.jpt.core.jpa2.resource.java.SequenceGenerator2_0Annotation; import org.eclipse.jpt.core.resource.java.JavaResourceNode; import org.eclipse.jpt.core.utility.TextRange; @@ -26,11 +26,11 @@ public final class SourceSequenceGenerator2_0Annotation extends SourceSequenceGeneratorAnnotation implements SequenceGenerator2_0Annotation { - private static final DeclarationAnnotationElementAdapter<String> CATALOG_ADAPTER = buildAdapter(JPA.SEQUENCE_GENERATOR__CATALOG); + private static final DeclarationAnnotationElementAdapter<String> CATALOG_ADAPTER = buildAdapter(JPA2_0.SEQUENCE_GENERATOR__CATALOG); private final AnnotationElementAdapter<String> catalogAdapter; private String catalog; - private static final DeclarationAnnotationElementAdapter<String> SCHEMA_ADAPTER = buildAdapter(JPA.SEQUENCE_GENERATOR__SCHEMA); + private static final DeclarationAnnotationElementAdapter<String> SCHEMA_ADAPTER = buildAdapter(JPA2_0.SEQUENCE_GENERATOR__SCHEMA); private final AnnotationElementAdapter<String> schemaAdapter; private String schema; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/AbstractJpaAnnotationDefintionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/AbstractJpaAnnotationDefintionProvider.java index 40f73491b4..3c986adc31 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/AbstractJpaAnnotationDefintionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/AbstractJpaAnnotationDefintionProvider.java @@ -10,114 +10,64 @@ package org.eclipse.jpt.core.internal.platform; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; -import java.util.ListIterator; - import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; import org.eclipse.jpt.core.resource.java.AnnotationDefinition; +import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; -/** - * - */ public abstract class AbstractJpaAnnotationDefintionProvider implements JpaAnnotationDefinitionProvider { - /** - * Ordered list of possible type mapping annotations. Ordered because this - * is used to determine the mapping in the case where 2 mapping annotations exist - */ - private AnnotationDefinition[] typeMappingAnnotationDefinitions; + private AnnotationDefinition[] typeAnnotationDefinitions; - private AnnotationDefinition[] typeSupportingAnnotationDefinitions; + private AnnotationDefinition[] attributeAnnotationDefinitions; - /** - * Ordered list of possible attribute mapping annotations. Ordered because this - * is used to determine the mapping in the case where 2 mapping annotations exist - */ - private AnnotationDefinition[] attributeMappingAnnotationDefinitions; - - private AnnotationDefinition[] attributeSupportingAnnotationDefinitions; protected AbstractJpaAnnotationDefintionProvider() { super(); } - // ********** type annotation definitions ********** - - public synchronized ListIterator<AnnotationDefinition> typeMappingAnnotationDefinitions() { - if (this.typeMappingAnnotationDefinitions == null) { - this.typeMappingAnnotationDefinitions = this.buildTypeMappingAnnotationDefinitions(); - } - return new ArrayListIterator<AnnotationDefinition>(this.typeMappingAnnotationDefinitions); - } - - protected AnnotationDefinition[] buildTypeMappingAnnotationDefinitions() { - ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>(); - this.addTypeMappingAnnotationDefinitionsTo(definitions); - return definitions.toArray(new AnnotationDefinition[definitions.size()]); - } - /** - * Subclasses must override this to specify type mapping annotation definitions. - */ - protected abstract void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions); + // ********** type annotation definitions ********** - public synchronized ListIterator<AnnotationDefinition> typeSupportingAnnotationDefinitions() { - if (this.typeSupportingAnnotationDefinitions == null) { - this.typeSupportingAnnotationDefinitions = this.buildTypeSupportingAnnotationDefinitions(); + public synchronized Iterator<AnnotationDefinition> typeAnnotationDefinitions() { + if (this.typeAnnotationDefinitions == null) { + this.typeAnnotationDefinitions = this.buildTypeAnnotationDefinitions(); } - return new ArrayListIterator<AnnotationDefinition>(this.typeSupportingAnnotationDefinitions); + return new ArrayIterator<AnnotationDefinition>(this.typeAnnotationDefinitions); } - protected AnnotationDefinition[] buildTypeSupportingAnnotationDefinitions() { + protected AnnotationDefinition[] buildTypeAnnotationDefinitions() { ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>(); - this.addTypeSupportingAnnotationDefinitionsTo(definitions); + this.addTypeAnnotationDefinitionsTo(definitions); return definitions.toArray(new AnnotationDefinition[definitions.size()]); } /** - * Subclasses must override this to specify type supporting annotation definitions. + * Subclasses must override this to specify type annotation definitions. */ - protected abstract void addTypeSupportingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions); + protected abstract void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions); + - // ********** attribute annotation definitions ********** - public synchronized ListIterator<AnnotationDefinition> attributeMappingAnnotationDefinitions() { - if (this.attributeMappingAnnotationDefinitions == null) { - this.attributeMappingAnnotationDefinitions = this.buildAttributeMappingAnnotationDefinitions(); + public synchronized Iterator<AnnotationDefinition> attributeAnnotationDefinitions() { + if (this.attributeAnnotationDefinitions == null) { + this.attributeAnnotationDefinitions = this.buildAttributeAnnotationDefinitions(); } - return new ArrayListIterator<AnnotationDefinition>(this.attributeMappingAnnotationDefinitions); + return new ArrayListIterator<AnnotationDefinition>(this.attributeAnnotationDefinitions); } - protected AnnotationDefinition[] buildAttributeMappingAnnotationDefinitions() { + protected AnnotationDefinition[] buildAttributeAnnotationDefinitions() { ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>(); - this.addAttributeMappingAnnotationDefinitionsTo(definitions); + this.addAttributeAnnotationDefinitionsTo(definitions); return definitions.toArray(new AnnotationDefinition[definitions.size()]); } /** - * Subclasses must override this to specify attribute mapping annotation definitions. + * Subclasses must override this to specify attribute annotation definitions. */ - protected abstract void addAttributeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions); - - public synchronized ListIterator<AnnotationDefinition> attributeSupportingAnnotationDefinitions() { - if (this.attributeSupportingAnnotationDefinitions == null) { - this.attributeSupportingAnnotationDefinitions = this.buildAttributeSupportingAnnotationDefinitions(); - } - return new ArrayListIterator<AnnotationDefinition>(this.attributeSupportingAnnotationDefinitions); - } - - protected AnnotationDefinition[] buildAttributeSupportingAnnotationDefinitions() { - ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>(); - this.addAttributeSupportingAnnotationDefinitionsTo(definitions); - return definitions.toArray(new AnnotationDefinition[definitions.size()]); - } - - /** - * Subclasses must override this to specify attribute supporting annotation definitions. - */ - protected abstract void addAttributeSupportingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions); - + protected abstract void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationDefinitionProvider.java index c893b1242b..b81383b091 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationDefinitionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationDefinitionProvider.java @@ -55,45 +55,43 @@ import org.eclipse.jpt.core.internal.resource.java.TransientAnnotationDefinition import org.eclipse.jpt.core.internal.resource.java.VersionAnnotationDefinition; import org.eclipse.jpt.core.resource.java.AnnotationDefinition; -/** - * - */ -public class GenericJpaAnnotationDefinitionProvider extends AbstractJpaAnnotationDefintionProvider +public class GenericJpaAnnotationDefinitionProvider + extends AbstractJpaAnnotationDefintionProvider { // singleton - private static final JpaAnnotationDefinitionProvider INSTANCE = new GenericJpaAnnotationDefinitionProvider(); - + private static final JpaAnnotationDefinitionProvider INSTANCE = + new GenericJpaAnnotationDefinitionProvider(); + + /** - * Return the singleton. + * Return the singleton */ public static JpaAnnotationDefinitionProvider instance() { return INSTANCE; } - + + /** - * Ensure single instance. + * Ensure singleton usage */ protected GenericJpaAnnotationDefinitionProvider() { super(); } - - @Override - protected void addTypeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(EmbeddableAnnotationDefinition.instance()); - definitions.add(EntityAnnotationDefinition.instance()); - definitions.add(MappedSuperclassAnnotationDefinition.instance()); - } - + + @Override - protected void addTypeSupportingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { + protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { definitions.add(AssociationOverrideAnnotationDefinition.instance()); definitions.add(AssociationOverridesAnnotationDefinition.instance()); definitions.add(AttributeOverrideAnnotationDefinition.instance()); definitions.add(AttributeOverridesAnnotationDefinition.instance()); definitions.add(DiscriminatorColumnAnnotationDefinition.instance()); definitions.add(DiscriminatorValueAnnotationDefinition.instance()); + definitions.add(EmbeddableAnnotationDefinition.instance()); + definitions.add(EntityAnnotationDefinition.instance()); definitions.add(IdClassAnnotationDefinition.instance()); definitions.add(InheritanceAnnotationDefinition.instance()); + definitions.add(MappedSuperclassAnnotationDefinition.instance()); definitions.add(NamedQueryAnnotationDefinition.instance()); definitions.add(NamedQueriesAnnotationDefinition.instance()); definitions.add(NamedNativeQueryAnnotationDefinition.instance()); @@ -108,39 +106,34 @@ public class GenericJpaAnnotationDefinitionProvider extends AbstractJpaAnnotatio } @Override - protected void addAttributeMappingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { - definitions.add(BasicAnnotationDefinition.instance()); - definitions.add(EmbeddedAnnotationDefinition.instance()); - definitions.add(EmbeddedIdAnnotationDefinition.instance()); - definitions.add(IdAnnotationDefinition.instance()); - definitions.add(ManyToManyAnnotationDefinition.instance()); - definitions.add(ManyToOneAnnotationDefinition.instance()); - definitions.add(OneToManyAnnotationDefinition.instance()); - definitions.add(OneToOneAnnotationDefinition.instance()); - definitions.add(TransientAnnotationDefinition.instance()); - definitions.add(VersionAnnotationDefinition.instance()); - } - - @Override - protected void addAttributeSupportingAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { + protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition> definitions) { definitions.add(AssociationOverrideAnnotationDefinition.instance()); definitions.add(AssociationOverridesAnnotationDefinition.instance()); definitions.add(AttributeOverrideAnnotationDefinition.instance()); definitions.add(AttributeOverridesAnnotationDefinition.instance()); + definitions.add(BasicAnnotationDefinition.instance()); definitions.add(ColumnAnnotationDefinition.instance()); + definitions.add(EmbeddedAnnotationDefinition.instance()); + definitions.add(EmbeddedIdAnnotationDefinition.instance()); definitions.add(EnumeratedAnnotationDefinition.instance()); definitions.add(GeneratedValueAnnotationDefinition.instance()); + definitions.add(IdAnnotationDefinition.instance()); definitions.add(JoinColumnAnnotationDefinition.instance()); definitions.add(JoinColumnsAnnotationDefinition.instance()); definitions.add(JoinTableAnnotationDefinition.instance()); definitions.add(LobAnnotationDefinition.instance()); + definitions.add(ManyToManyAnnotationDefinition.instance()); + definitions.add(ManyToOneAnnotationDefinition.instance()); definitions.add(MapKeyAnnotationDefinition.instance()); + definitions.add(OneToManyAnnotationDefinition.instance()); + definitions.add(OneToOneAnnotationDefinition.instance()); definitions.add(OrderByAnnotationDefinition.instance()); definitions.add(PrimaryKeyJoinColumnAnnotationDefinition.instance()); definitions.add(PrimaryKeyJoinColumnsAnnotationDefinition.instance()); definitions.add(SequenceGeneratorAnnotationDefinition.instance()); definitions.add(TableGeneratorAnnotationDefinition.instance()); definitions.add(TemporalAnnotationDefinition.instance()); + definitions.add(TransientAnnotationDefinition.instance()); + definitions.add(VersionAnnotationDefinition.instance()); } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationProvider.java index b26335f63e..d80effd8fd 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaAnnotationProvider.java @@ -9,8 +9,8 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.platform; +import java.util.Iterator; import java.util.ListIterator; - import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider; import org.eclipse.jpt.core.JpaAnnotationProvider; @@ -21,8 +21,8 @@ import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.utility.jdt.Attribute; import org.eclipse.jpt.core.utility.jdt.Type; import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; -import org.eclipse.jpt.utility.internal.iterators.CompositeListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationListIterator; +import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; +import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; /** * Delegate to annotation definition providers. @@ -39,8 +39,32 @@ public class GenericJpaAnnotationProvider super(); this.annotationDefinitionProviders = annotationDefinitionProviders; } - - + + + // ********** static methods ********** + + protected static Iterator<String> annotationNames( + Iterator<AnnotationDefinition> annotationDefinitions) { + return new TransformationIterator<AnnotationDefinition, String>(annotationDefinitions) { + @Override + protected String transform(AnnotationDefinition annotationDefinition) { + return annotationDefinition.getAnnotationName(); + } + }; + } + + protected static AnnotationDefinition getAnnotationDefinition( + String annotationName, Iterator<AnnotationDefinition> annotationDefinitions) { + while (annotationDefinitions.hasNext()) { + AnnotationDefinition annotationDefinition = annotationDefinitions.next(); + if (annotationDefinition.getAnnotationName().equals(annotationName)) { + return annotationDefinition; + } + } + return null; + } + + // ********** annotation definition providers ********** protected ListIterator<JpaAnnotationDefinitionProvider> annotationDefinitionProviders() { @@ -49,170 +73,93 @@ public class GenericJpaAnnotationProvider // ********** type annotations ********** - + @SuppressWarnings("unchecked") - public ListIterator<String> typeMappingAnnotationNames() { - return new CompositeListIterator<String>(annotationNames(typeMappingAnnotationDefinitions())); + public Iterator<String> typeAnnotationNames() { + return new CompositeIterator<String>( + annotationNames(typeAnnotationDefinitions())); } - - protected ListIterator<AnnotationDefinition> typeMappingAnnotationDefinitions() { - return new CompositeListIterator<AnnotationDefinition> ( - new TransformationListIterator<JpaAnnotationDefinitionProvider, ListIterator<AnnotationDefinition>>(this.annotationDefinitionProviders()) { + + protected Iterator<AnnotationDefinition> typeAnnotationDefinitions() { + return new CompositeIterator<AnnotationDefinition> ( + new TransformationIterator<JpaAnnotationDefinitionProvider, Iterator<AnnotationDefinition>>( + this.annotationDefinitionProviders()) { @Override - protected ListIterator<AnnotationDefinition> transform(JpaAnnotationDefinitionProvider annotationDefinitionProvider) { - return annotationDefinitionProvider.typeMappingAnnotationDefinitions(); + protected Iterator<AnnotationDefinition> transform( + JpaAnnotationDefinitionProvider annotationDefinitionProvider) { + return annotationDefinitionProvider.typeAnnotationDefinitions(); } - } - ); - } - - public Annotation buildTypeMappingAnnotation(JavaResourcePersistentType parent, Type type, String annotationName) { - return this.getTypeMappingAnnotationDefinition(annotationName).buildAnnotation(parent, type); + }); } - public Annotation buildTypeMappingAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - return this.getTypeMappingAnnotationDefinition(jdtAnnotation.getElementName()).buildAnnotation(parent, jdtAnnotation); + public Annotation buildTypeAnnotation( + JavaResourcePersistentType parent, Type type, String annotationName) { + return this.getTypeAnnotationDefinition(annotationName).buildAnnotation(parent, type); } - protected AnnotationDefinition getTypeMappingAnnotationDefinition(String annotationName) { - AnnotationDefinition annotationDefinition = getAnnotationDefinition(annotationName, this.typeMappingAnnotationDefinitions()); - if (annotationDefinition == null) { - throw new IllegalArgumentException("unsupported type mapping annotation: " + annotationName); //$NON-NLS-1$ - } - return annotationDefinition; + public Annotation buildTypeAnnotation( + JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { + return this.getTypeAnnotationDefinition(jdtAnnotation.getElementName()). + buildAnnotation(parent, jdtAnnotation); } - @SuppressWarnings("unchecked") - public ListIterator<String> typeSupportingAnnotationNames() { - return new CompositeListIterator<String>(annotationNames(typeSupportingAnnotationDefinitions())); - } - - protected ListIterator<AnnotationDefinition> typeSupportingAnnotationDefinitions() { - return new CompositeListIterator<AnnotationDefinition> ( - new TransformationListIterator<JpaAnnotationDefinitionProvider, ListIterator<AnnotationDefinition>>(this.annotationDefinitionProviders()) { - @Override - protected ListIterator<AnnotationDefinition> transform(JpaAnnotationDefinitionProvider annotationDefinitionProvider) { - return annotationDefinitionProvider.typeSupportingAnnotationDefinitions(); - } - } - ); - } - - public Annotation buildTypeSupportingAnnotation(JavaResourcePersistentType parent, Type type, String annotationName) { - return this.getTypeSupportingAnnotationDefinition(annotationName).buildAnnotation(parent, type); - } - - public Annotation buildTypeSupportingAnnotation(JavaResourcePersistentType parent, IAnnotation jdtAnnotation) { - return this.getTypeSupportingAnnotationDefinition(jdtAnnotation.getElementName()).buildAnnotation(parent, jdtAnnotation); - } - - public Annotation buildNullTypeSupportingAnnotation(JavaResourcePersistentType parent, String annotationName) { - return this.getTypeSupportingAnnotationDefinition(annotationName).buildNullAnnotation(parent); - } - - protected AnnotationDefinition getTypeSupportingAnnotationDefinition(String annotationName) { - AnnotationDefinition annotationDefinition = getAnnotationDefinition(annotationName, this.typeSupportingAnnotationDefinitions()); + protected AnnotationDefinition getTypeAnnotationDefinition(String annotationName) { + AnnotationDefinition annotationDefinition = + getAnnotationDefinition(annotationName, this.typeAnnotationDefinitions()); if (annotationDefinition == null) { - throw new IllegalArgumentException("unsupported type supporting annotation: " + annotationName); //$NON-NLS-1$ + throw new IllegalArgumentException("unsupported type annotation: " + annotationName); //$NON-NLS-1$ } return annotationDefinition; } - - - // ********** attribute annotations ********** - - @SuppressWarnings("unchecked") - public ListIterator<String> attributeMappingAnnotationNames() { - return new CompositeListIterator<String>(annotationNames(attributeMappingAnnotationDefinitions())); - } - - protected ListIterator<AnnotationDefinition> attributeMappingAnnotationDefinitions() { - return new CompositeListIterator<AnnotationDefinition> ( - new TransformationListIterator<JpaAnnotationDefinitionProvider, ListIterator<AnnotationDefinition>>(this.annotationDefinitionProviders()) { - @Override - protected ListIterator<AnnotationDefinition> transform(JpaAnnotationDefinitionProvider annotationDefinitionProvider) { - return annotationDefinitionProvider.attributeMappingAnnotationDefinitions(); - } - } - ); - } - - public Annotation buildAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName) { - return this.getAttributeMappingAnnotationDefinition(annotationName).buildAnnotation(parent, attribute); - } - public Annotation buildAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - return this.getAttributeMappingAnnotationDefinition(jdtAnnotation.getElementName()).buildAnnotation(parent, jdtAnnotation); + public Annotation buildNullTypeAnnotation( + JavaResourcePersistentType parent, String annotationName) { + return this.getTypeAnnotationDefinition(annotationName).buildNullAnnotation(parent); } - public Annotation buildNullAttributeMappingAnnotation(JavaResourcePersistentAttribute parent, String annotationName) { - return this.getAttributeMappingAnnotationDefinition(annotationName).buildNullAnnotation(parent); - } - protected AnnotationDefinition getAttributeMappingAnnotationDefinition(String annotationName) { - AnnotationDefinition annotationDefinition = getAnnotationDefinition(annotationName, this.attributeMappingAnnotationDefinitions()); - if (annotationDefinition == null) { - throw new IllegalArgumentException("unsupported attribute mapping annotation: " + annotationName); //$NON-NLS-1$ - } - return annotationDefinition; - } + // ********** attribute annotations ********** @SuppressWarnings("unchecked") - public ListIterator<String> attributeSupportingAnnotationNames() { - return new CompositeListIterator<String>(annotationNames(attributeSupportingAnnotationDefinitions())); + public Iterator<String> attributeAnnotationNames() { + return new CompositeIterator<String>( + annotationNames(attributeAnnotationDefinitions())); } - - protected ListIterator<AnnotationDefinition> attributeSupportingAnnotationDefinitions() { - return new CompositeListIterator<AnnotationDefinition> ( - new TransformationListIterator<JpaAnnotationDefinitionProvider, ListIterator<AnnotationDefinition>>(this.annotationDefinitionProviders()) { + + protected Iterator<AnnotationDefinition> attributeAnnotationDefinitions() { + return new CompositeIterator<AnnotationDefinition> ( + new TransformationIterator<JpaAnnotationDefinitionProvider, Iterator<AnnotationDefinition>>( + this.annotationDefinitionProviders()) { @Override - protected ListIterator<AnnotationDefinition> transform(JpaAnnotationDefinitionProvider annotationDefinitionProvider) { - return annotationDefinitionProvider.attributeSupportingAnnotationDefinitions(); + protected Iterator<AnnotationDefinition> transform( + JpaAnnotationDefinitionProvider annotationDefinitionProvider) { + return annotationDefinitionProvider.attributeAnnotationDefinitions(); } - } - ); + }); } - public Annotation buildAttributeSupportingAnnotation(JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName) { - return this.getAttributeSupportingAnnotationDefinition(annotationName).buildAnnotation(parent, attribute); + public Annotation buildAttributeAnnotation( + JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName) { + return this.getAttributeAnnotationDefinition(annotationName).buildAnnotation(parent, attribute); } - public Annotation buildAttributeSupportingAnnotation(JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { - return this.getAttributeSupportingAnnotationDefinition(jdtAnnotation.getElementName()).buildAnnotation(parent, jdtAnnotation); + public Annotation buildAttributeAnnotation( + JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation) { + return this.getAttributeAnnotationDefinition(jdtAnnotation.getElementName()). + buildAnnotation(parent, jdtAnnotation); } - public Annotation buildNullAttributeSupportingAnnotation(JavaResourcePersistentAttribute parent, String annotationName) { - return this.getAttributeSupportingAnnotationDefinition(annotationName).buildNullAnnotation(parent); + public Annotation buildNullAttributeAnnotation( + JavaResourcePersistentAttribute parent, String annotationName) { + return this.getAttributeAnnotationDefinition(annotationName).buildNullAnnotation(parent); } - protected AnnotationDefinition getAttributeSupportingAnnotationDefinition(String annotationName) { - AnnotationDefinition annotationDefinition = getAnnotationDefinition(annotationName, this.attributeSupportingAnnotationDefinitions()); + protected AnnotationDefinition getAttributeAnnotationDefinition(String annotationName) { + AnnotationDefinition annotationDefinition = + getAnnotationDefinition(annotationName, this.attributeAnnotationDefinitions()); if (annotationDefinition == null) { - throw new IllegalArgumentException("unsupported attribute supporting annotation: " + annotationName); //$NON-NLS-1$ + throw new IllegalArgumentException("unsupported attribute annotation: " + annotationName); //$NON-NLS-1$ } return annotationDefinition; } - - - // ********** static methods ********** - - protected static ListIterator<String> annotationNames(ListIterator<AnnotationDefinition> annotationDefinitions) { - return new TransformationListIterator<AnnotationDefinition, String>(annotationDefinitions) { - @Override - protected String transform(AnnotationDefinition annotationDefinition) { - return annotationDefinition.getAnnotationName(); - } - }; - } - - protected static AnnotationDefinition getAnnotationDefinition(String annotationName, ListIterator<AnnotationDefinition> annotationDefinitions) { - while (annotationDefinitions.hasNext()) { - AnnotationDefinition annotationDefinition = annotationDefinitions.next(); - if (annotationDefinition.getAnnotationName().equals(annotationName)) { - return annotationDefinition; - } - } - return null; - } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java index 22f24eeefb..da9a685b62 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java @@ -10,7 +10,6 @@ package org.eclipse.jpt.core.internal.platform; import java.util.ListIterator; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.EntityGeneratorDatabaseAnnotationNameBuilder; @@ -19,15 +18,14 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaPlatform; import org.eclipse.jpt.core.JpaPlatformProvider; +import org.eclipse.jpt.core.JpaPlatformVariation; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JpaResourceModel; import org.eclipse.jpt.core.JpaResourceModelProvider; -import org.eclipse.jpt.core.JpaPlatformVariation; import org.eclipse.jpt.core.context.MappingFileDefinition; import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; import org.eclipse.jpt.core.internal.utility.PlatformTools; import org.eclipse.jpt.core.internal.utility.jdt.DefaultAnnotationEditFormatter; @@ -132,37 +130,31 @@ public class GenericJpaPlatform // ********** Java type mappings ********** - - public JavaTypeMapping buildJavaTypeMappingFromMappingKey(String key, JavaPersistentType type) { - return this.getJavaTypeMappingProviderForMappingKey(key).buildMapping(type, this.jpaFactory); - } - protected JavaTypeMappingProvider getJavaTypeMappingProviderForMappingKey(String key) { - for (JavaTypeMappingProvider provider : CollectionTools.iterable(javaTypeMappingProviders())) { - if (Tools.valuesAreEqual(provider.getKey(), key)) { + public JavaTypeMappingProvider getJavaTypeMappingProvider(JavaPersistentType type) { + for (JavaTypeMappingProvider provider : + CollectionTools.iterable(javaTypeMappingProviders())) { + if (provider.test(type)) { return provider; } } - throw new IllegalArgumentException("Illegal type mapping key: " + key); //$NON-NLS-1$ - } - - protected ListIterator<JavaTypeMappingProvider> javaTypeMappingProviders() { - return this.platformProvider.javaTypeMappingProviders(); - } - - public JavaTypeMapping buildJavaTypeMappingFromAnnotation(String annotationName, JavaPersistentType type) { - return this.getJavaTypeMappingProviderForAnnotation(annotationName).buildMapping(type, this.jpaFactory); + throw new IllegalStateException("There must be a mapping provider for all types"); //$NON-NLS-1$ } - - protected JavaTypeMappingProvider getJavaTypeMappingProviderForAnnotation(String annotationName) { - for (JavaTypeMappingProvider provider : CollectionTools.iterable(javaTypeMappingProviders())) { - if (Tools.valuesAreEqual(provider.getAnnotationName(), annotationName)) { + + public JavaTypeMappingProvider getJavaTypeMappingProvider(String mappingKey) { + for (JavaTypeMappingProvider provider : + CollectionTools.iterable(javaTypeMappingProviders())) { + if (Tools.valuesAreEqual(provider.getKey(), mappingKey)) { return provider; } } - throw new IllegalArgumentException("Illegal annotation name: " + annotationName); //$NON-NLS-1$ + throw new IllegalArgumentException("Illegal type mapping key: " + mappingKey); //$NON-NLS-1$ } - + + protected ListIterator<JavaTypeMappingProvider> javaTypeMappingProviders() { + return this.platformProvider.javaTypeMappingProviders(); + } + // ********** Java attribute mappings ********** @@ -170,7 +162,7 @@ public class GenericJpaPlatform JavaPersistentAttribute attribute) { for (JavaAttributeMappingProvider provider : CollectionTools.iterable(defaultJavaAttributeMappingProviders())) { - if (provider.defaultApplies(attribute)) { + if (provider.testDefault(attribute)) { return provider; } } @@ -185,7 +177,7 @@ public class GenericJpaPlatform JavaPersistentAttribute attribute) { for (JavaAttributeMappingProvider provider : CollectionTools.iterable(specifiedJavaAttributeMappingProviders())) { - if (provider.specifiedApplies(attribute)) { + if (provider.testSpecified(attribute)) { return provider; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAnnotation.java index e61f395f62..3fc989ff90 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAnnotation.java @@ -65,33 +65,23 @@ public abstract class NullAnnotation } /** - * Convenience method: Set the type or attribute's mapping annotation + * Convenience method: Add the type or attribute's annotation * and return it. * Pre-condition: The annotation's parent must be a persistent member * (type or attribute). */ - protected Annotation setMappingAnnotation() { - return this.getMember().setMappingAnnotation(this.getAnnotationName()); - } - - /** - * Convenience method: Add to the type or attribute's list of "supporting" - * annotations and return the newly created annotation. - * Pre-condition: The annotation's parent must be a persistent member - * (type or attribute). - */ - protected Annotation addSupportingAnnotation() { - return this.getMember().addSupportingAnnotation(this.getAnnotationName()); + protected Annotation addAnnotation() { + return this.getMember().addAnnotation(this.getAnnotationName()); } /** - * Convenience method: Add to the type or attribute's list of "supporting" - * annotations and return the newly created annotation. + * Convenience method: Add the type or attribute's annotation + * and return it. * Pre-condition: The annotation's parent must be a persistent member * (type or attribute). */ - protected Annotation addSupportingAnnotation(JavaResourcePersistentMember.AnnotationInitializer initializer) { - return this.getMember().addSupportingAnnotation(this.getAnnotationName(), initializer); + protected Annotation addAnnotation( + JavaResourcePersistentMember.AnnotationInitializer initializer) { + return this.getMember().addAnnotation(this.getAnnotationName(), initializer); } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumnAnnotation.java index 7e458a36eb..85f0c6fe08 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumnAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullAttributeOverrideColumnAnnotation.java @@ -30,5 +30,4 @@ public class NullAttributeOverrideColumnAnnotation protected ColumnAnnotation addAnnotation() { return this.getAttributeOverrideAnnotation().addColumn(); } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumnAnnotation.java index 8adf3b2eef..477b7f8da0 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumnAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseColumnAnnotation.java @@ -27,7 +27,9 @@ public abstract class NullBaseColumnAnnotation } @Override - protected abstract BaseColumnAnnotation addAnnotation(); + protected BaseColumnAnnotation addAnnotation() { + return (BaseColumnAnnotation) super.addAnnotation(); + } // ***** table public String getTable() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTableAnnotation.java index 29babc3267..93160b0452 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTableAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBaseTableAnnotation.java @@ -10,12 +10,9 @@ package org.eclipse.jpt.core.internal.resource.java; import java.util.ListIterator; - import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.core.resource.java.Annotation; import org.eclipse.jpt.core.resource.java.BaseTableAnnotation; import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember.AnnotationInitializer; import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; @@ -32,10 +29,11 @@ public abstract class NullBaseTableAnnotation super(parent); } - protected abstract BaseTableAnnotation addAnnotation(); + @Override + protected BaseTableAnnotation addAnnotation() { + return (BaseTableAnnotation) super.addAnnotation(); + } - protected abstract Annotation addAnnotation(AnnotationInitializer initializer); - public boolean isSpecified() { return false; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasicAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasicAnnotation.java index 4eb37a88d7..0e16de1e07 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasicAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullBasicAnnotation.java @@ -25,44 +25,48 @@ public final class NullBasicAnnotation protected NullBasicAnnotation(JavaResourcePersistentAttribute parent) { super(parent); } - + + public String getAnnotationName() { return ANNOTATION_NAME; } - + @Override - protected BasicAnnotation setMappingAnnotation() { - return (BasicAnnotation) super.setMappingAnnotation(); + protected BasicAnnotation addAnnotation() { + return (BasicAnnotation) super.addAnnotation(); } - + + // ***** fetch + public FetchType getFetch() { return null; } - + public void setFetch(FetchType fetch) { if (fetch != null) { - this.setMappingAnnotation().setFetch(fetch); + this.addAnnotation().setFetch(fetch); } } - + public TextRange getFetchTextRange(CompilationUnit astRoot) { return null; } - + + // ***** optional + public Boolean getOptional() { return null; } - + public void setOptional(Boolean optional) { if (optional != null) { - this.setMappingAnnotation().setOptional(optional); + this.addAnnotation().setOptional(optional); } } - + public TextRange getOptionalTextRange(CompilationUnit astRoot) { return null; } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumnAnnotation.java index 927be6ef1c..3bf5452a0b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumnAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullColumnAnnotation.java @@ -31,7 +31,7 @@ public class NullColumnAnnotation @Override protected ColumnAnnotation addAnnotation() { - return (ColumnAnnotation) this.addSupportingAnnotation(); + return (ColumnAnnotation) super.addAnnotation(); } // ***** length diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumnAnnotation.java index 038dc6ecf5..126ad60814 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumnAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorColumnAnnotation.java @@ -30,7 +30,7 @@ public final class NullDiscriminatorColumnAnnotation @Override protected DiscriminatorColumnAnnotation addAnnotation() { - return (DiscriminatorColumnAnnotation) this.addSupportingAnnotation(); + return (DiscriminatorColumnAnnotation) super.addAnnotation(); } // ***** discriminator type diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValueAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValueAnnotation.java index d8809ec50c..7a68d3d2dc 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValueAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullDiscriminatorValueAnnotation.java @@ -31,8 +31,8 @@ public final class NullDiscriminatorValueAnnotation } @Override - protected DiscriminatorValueAnnotation addSupportingAnnotation() { - return (DiscriminatorValueAnnotation) super.addSupportingAnnotation(); + protected DiscriminatorValueAnnotation addAnnotation() { + return (DiscriminatorValueAnnotation) super.addAnnotation(); } // ***** value @@ -42,7 +42,7 @@ public final class NullDiscriminatorValueAnnotation public void setValue(String value) { if (value != null) { - this.addSupportingAnnotation().setValue(value); + this.addAnnotation().setValue(value); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumeratedAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumeratedAnnotation.java index 76d961ae1c..1e45dd51a9 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumeratedAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullEnumeratedAnnotation.java @@ -31,8 +31,8 @@ public final class NullEnumeratedAnnotation } @Override - protected EnumeratedAnnotation addSupportingAnnotation() { - return (EnumeratedAnnotation) super.addSupportingAnnotation(); + protected EnumeratedAnnotation addAnnotation() { + return (EnumeratedAnnotation) super.addAnnotation(); } // ***** value @@ -42,7 +42,7 @@ public final class NullEnumeratedAnnotation public void setValue(EnumType value) { if (value != null) { - this.addSupportingAnnotation().setValue(value); + this.addAnnotation().setValue(value); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritanceAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritanceAnnotation.java index 5946de7915..a4130b1b6e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritanceAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullInheritanceAnnotation.java @@ -31,8 +31,8 @@ public final class NullInheritanceAnnotation } @Override - protected InheritanceAnnotation addSupportingAnnotation() { - return (InheritanceAnnotation) super.addSupportingAnnotation(); + protected InheritanceAnnotation addAnnotation() { + return (InheritanceAnnotation) super.addAnnotation(); } // ***** strategy @@ -42,7 +42,7 @@ public final class NullInheritanceAnnotation public void setStrategy(InheritanceType strategy) { if (strategy != null) { - this.addSupportingAnnotation().setStrategy(strategy); + this.addAnnotation().setStrategy(strategy); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTableAnnotation.java index 3a050497b0..f54c7aac97 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTableAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullJoinTableAnnotation.java @@ -35,12 +35,12 @@ public class NullJoinTableAnnotation @Override protected JoinTableAnnotation addAnnotation() { - return (JoinTableAnnotation) this.addSupportingAnnotation(); + return (JoinTableAnnotation) super.addAnnotation(); } @Override protected JoinColumnAnnotation addAnnotation(AnnotationInitializer initializer) { - return (JoinColumnAnnotation) this.addSupportingAnnotation(initializer); + return (JoinColumnAnnotation) super.addAnnotation(initializer); } // ***** join columns diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumnAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumnAnnotation.java index ae673da038..0ae2b8cf38 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumnAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullNamedColumnAnnotation.java @@ -31,9 +31,12 @@ public abstract class NullNamedColumnAnnotation public boolean isSpecified() { return false; } - - protected abstract NamedColumnAnnotation addAnnotation(); - + + @Override + protected NamedColumnAnnotation addAnnotation() { + return (NamedColumnAnnotation) super.addAnnotation(); + } + // ***** name public String getName() { return null; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToOneAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToOneAnnotation.java index c477cd8172..ce6374c71b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToOneAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOneToOneAnnotation.java @@ -30,8 +30,8 @@ public final class NullOneToOneAnnotation } @Override - protected OneToOneAnnotation setMappingAnnotation() { - return (OneToOneAnnotation) super.setMappingAnnotation(); + protected OneToOneAnnotation addAnnotation() { + return (OneToOneAnnotation) super.addAnnotation(); } // ***** optional @@ -41,7 +41,7 @@ public final class NullOneToOneAnnotation public void setOptional(Boolean optional) { if (optional != null) { - this.setMappingAnnotation().setOptional(optional); + this.addAnnotation().setOptional(optional); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOwnableRelationshipMappingAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOwnableRelationshipMappingAnnotation.java index a14c881e54..dd29a044d7 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOwnableRelationshipMappingAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullOwnableRelationshipMappingAnnotation.java @@ -26,113 +26,131 @@ public abstract class NullOwnableRelationshipMappingAnnotation protected NullOwnableRelationshipMappingAnnotation(JavaResourcePersistentAttribute parent) { super(parent); } - + + @Override - protected OwnableRelationshipMappingAnnotation setMappingAnnotation() { - return (OwnableRelationshipMappingAnnotation) super.setMappingAnnotation(); + protected OwnableRelationshipMappingAnnotation addAnnotation() { + return (OwnableRelationshipMappingAnnotation) super.addAnnotation(); } - + + // ***** target entity + public String getTargetEntity() { return null; } - + public void setTargetEntity(String targetEntity) { if (targetEntity != null) { - this.setMappingAnnotation().setTargetEntity(targetEntity); + this.addAnnotation().setTargetEntity(targetEntity); } } - + public TextRange getTargetEntityTextRange(CompilationUnit astRoot) { return null; } - + + // ***** fully-qualified target entity class name + public String getFullyQualifiedTargetEntityClassName() { return null; } - + + // ***** mapped by + public String getMappedBy() { return null; } - + public void setMappedBy(String mappedBy) { if (mappedBy != null) { - this.setMappingAnnotation().setMappedBy(mappedBy); + this.addAnnotation().setMappedBy(mappedBy); } } - + public TextRange getMappedByTextRange(CompilationUnit astRoot) { return null; } - + public boolean mappedByTouches(int pos, CompilationUnit astRoot) { return false; } - + + // ***** fetch + public FetchType getFetch() { return null; } - + public void setFetch(FetchType fetch) { if (fetch != null) { - this.setMappingAnnotation().setFetch(fetch); + this.addAnnotation().setFetch(fetch); } } - + public TextRange getFetchTextRange(CompilationUnit astRoot) { return null; } - + + // ***** cascade all + public boolean isCascadeAll() { return false; } - + public void setCascadeAll(boolean all) { - this.setMappingAnnotation().setCascadeAll(all); + this.addAnnotation().setCascadeAll(all); } - + + // ***** cascade merge + public boolean isCascadeMerge() { return false; } - + public void setCascadeMerge(boolean merge) { - this.setMappingAnnotation().setCascadeMerge(merge); + this.addAnnotation().setCascadeMerge(merge); } - + + // ***** cascade persist + public boolean isCascadePersist() { return false; } - + public void setCascadePersist(boolean persist) { - this.setMappingAnnotation().setCascadePersist(persist); + this.addAnnotation().setCascadePersist(persist); } - + + // ***** cascade refresh + public boolean isCascadeRefresh() { return false; } - + public void setCascadeRefresh(boolean refresh) { - this.setMappingAnnotation().setCascadeRefresh(refresh); + this.addAnnotation().setCascadeRefresh(refresh); } - + + // ***** cascade remove + public boolean isCascadeRemove() { return false; } - + public void setCascadeRemove(boolean remove) { - this.setMappingAnnotation().setCascadeRemove(remove); + this.addAnnotation().setCascadeRemove(remove); } - + public TextRange getCascadeTextRange(CompilationUnit astRoot) { return null; } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTableAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTableAnnotation.java index 86433bedf3..bc831e7093 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTableAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTableAnnotation.java @@ -26,12 +26,12 @@ public final class NullTableAnnotation @Override protected TableAnnotation addAnnotation() { - return (TableAnnotation) addSupportingAnnotation(); + return (TableAnnotation) super.addAnnotation(); } @Override protected TableAnnotation addAnnotation(AnnotationInitializer initializer) { - return (TableAnnotation) addSupportingAnnotation(initializer); + return (TableAnnotation) super.addAnnotation(initializer); } public String getAnnotationName() { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporalAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporalAnnotation.java index b661b3dc22..ec38b00a84 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporalAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/NullTemporalAnnotation.java @@ -31,8 +31,8 @@ public final class NullTemporalAnnotation } @Override - protected TemporalAnnotation addSupportingAnnotation() { - return (TemporalAnnotation) super.addSupportingAnnotation(); + protected TemporalAnnotation addAnnotation() { + return (TemporalAnnotation) super.addAnnotation(); } @@ -45,7 +45,7 @@ public final class NullTemporalAnnotation public void setValue(TemporalType value) { if (value != null) { - this.addSupportingAnnotation().setValue(value); + this.addAnnotation().setValue(value); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragment.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragment.java index 3b60ab685e..734439b56d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragment.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPackageFragment.java @@ -14,7 +14,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.IClassFile; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IPackageFragment; @@ -63,7 +62,7 @@ final class BinaryPackageFragment IType jdtType = jdtClassFile.getType(); if (BinaryPersistentType.typeIsPersistable(jdtType)) { JavaResourceClassFile classFile = new BinaryClassFile(this, jdtClassFile, jdtType); - if (classFile.getPersistentType().isPersisted()) { // we only hold annotated types + if (classFile.getPersistentType().isAnnotated()) { // we only hold annotated types result.add(classFile); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java index e305cebe2e..7d5c4d9725 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentAttribute.java @@ -17,7 +17,6 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jdt.core.IField; import org.eclipse.jdt.core.IJavaProject; @@ -107,51 +106,37 @@ final class BinaryPersistentAttribute // ********** BinaryPersistentMember implementation ********** - + private Adapter getAdapter() { return (Adapter) this.adapter; } - - @Override - Annotation buildMappingAnnotation(IAnnotation jdtAnnotation) { - return this.getAnnotationProvider().buildAttributeMappingAnnotation(this, jdtAnnotation); - } - + @Override - Annotation buildSupportingAnnotation(IAnnotation jdtAnnotation) { - return this.getAnnotationProvider().buildAttributeSupportingAnnotation(this, jdtAnnotation); - } - - @Override - Annotation buildNullSupportingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullAttributeSupportingAnnotation(this, annotationName); - } - - public Annotation getNullMappingAnnotation(String annotationName) { - return (annotationName == null) ? null : this.buildNullMappingAnnotation(annotationName); + Iterator<String> validAnnotationNames() { + return this.getAnnotationProvider().attributeAnnotationNames(); } - - private Annotation buildNullMappingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullAttributeMappingAnnotation(this, annotationName); - } - + @Override - ListIterator<String> validMappingAnnotationNames() { - return this.getAnnotationProvider().attributeMappingAnnotationNames(); + Annotation buildAnnotation(IAnnotation jdtAnnotation) { + return this.getAnnotationProvider().buildAttributeAnnotation(this, jdtAnnotation); } - + @Override - ListIterator<String> validSupportingAnnotationNames() { - return this.getAnnotationProvider().attributeSupportingAnnotationNames(); + Annotation buildNullAnnotation(String annotationName) { + return this.getAnnotationProvider().buildNullAttributeAnnotation(this, annotationName); } - - + + // ********** JavaResourcePersistentAttribute implementation ********** - + public String getName() { return this.getAdapter().getAttributeName(); } - + + public Annotation getNullAnnotation(String annotationName) { + return (annotationName == null) ? null : this.buildNullAnnotation(annotationName); + } + public boolean isField() { return this.getAdapter().isField(); } @@ -164,13 +149,8 @@ final class BinaryPersistentAttribute throw new UnsupportedOperationException(); } - public boolean hasAnyPersistenceAnnotations() { - return (this.mappingAnnotationsSize() > 0) - || (this.supportingAnnotationsSize() > 0); - } - public AccessType getSpecifiedAccess() { - Access2_0Annotation accessAnnotation = (Access2_0Annotation) this.getSupportingAnnotation(Access2_0Annotation.ANNOTATION_NAME); + Access2_0Annotation accessAnnotation = (Access2_0Annotation) this.getAnnotation(Access2_0Annotation.ANNOTATION_NAME); return accessAnnotation == null ? null : accessAnnotation.getValue(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java index 9d51125ed1..c8676f67c6 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java @@ -10,9 +10,7 @@ package org.eclipse.jpt.core.internal.resource.java.binary; import java.util.Iterator; -import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.JavaModelException; @@ -27,10 +25,9 @@ import org.eclipse.jpt.core.resource.java.NestableAnnotation; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterables.SnapshotCloneIterable; import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; +import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; /** * binary persistent member @@ -41,16 +38,13 @@ abstract class BinaryPersistentMember { /** JDT member adapter */ final Adapter adapter; - - /** mapping annotations */ - final Vector<Annotation> mappingAnnotations = new Vector<Annotation>(); - - /** supporting annotations */ - final Vector<Annotation> supportingAnnotations = new Vector<Annotation>(); - + + /** annotations */ + final Vector<Annotation> annotations = new Vector<Annotation>(); + boolean persistable; - - + + // ********** construction/initialization ********** public BinaryPersistentMember(JavaResourceNode parent, Adapter adapter) { @@ -67,121 +61,85 @@ abstract class BinaryPersistentMember } private void addAnnotation(IAnnotation jdtAnnotation) { - if (this.annotationIsValidSupportingAnnotation(jdtAnnotation)) { - this.supportingAnnotations.add(this.buildSupportingAnnotation(jdtAnnotation)); - } else if (this.annotationIsValidMappingAnnotation(jdtAnnotation)) { - this.mappingAnnotations.add(this.buildMappingAnnotation(jdtAnnotation)); + if (this.annotationIsValid(jdtAnnotation)) { + this.annotations.add(this.buildAnnotation(jdtAnnotation)); } } - - + + // ********** updating ********** - + @Override public void update() { super.update(); this.updateAnnotations(); this.setPersistable(this.buildPersistable()); } - + // TODO private void updateAnnotations() { throw new UnsupportedOperationException(); } - - - // ********** mapping annotations ********** - - public Iterator<Annotation> mappingAnnotations() { - return this.getMappingAnnotations().iterator(); - } - - private Iterable<Annotation> getMappingAnnotations() { - return new LiveCloneIterable<Annotation>(this.mappingAnnotations); - } - - public int mappingAnnotationsSize() { - return this.mappingAnnotations.size(); - } - - public Annotation getMappingAnnotation() { - Iterable<Annotation> annotations = new SnapshotCloneIterable<Annotation>(this.mappingAnnotations); - for (ListIterator<String> stream = this.validMappingAnnotationNames(); stream.hasNext();) { - Annotation annotation = this.selectAnnotationNamed(annotations, stream.next()); - if (annotation != null) { - return annotation; - } - } - return null; - } - - public Annotation getMappingAnnotation(String annotationName) { - return this.selectAnnotationNamed(this.getMappingAnnotations(), annotationName); - } - - private boolean annotationIsValidMappingAnnotation(IAnnotation jdtAnnotation) { - return CollectionTools.contains(this.validMappingAnnotationNames(), jdtAnnotation.getElementName()); - } - - abstract ListIterator<String> validMappingAnnotationNames(); - - abstract Annotation buildMappingAnnotation(IAnnotation jdtAnnotation); - - - // ********** supporting annotations ********** - - public Iterator<Annotation> supportingAnnotations() { - return this.getSupportingAnnotations().iterator(); - } - - private Iterable<Annotation> getSupportingAnnotations() { - return new LiveCloneIterable<Annotation>(this.supportingAnnotations); - } - - public int supportingAnnotationsSize() { - return this.supportingAnnotations.size(); - } - - public ListIterator<NestableAnnotation> supportingAnnotations(String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = this.getSupportingContainerAnnotation(containerAnnotationName); + + + // ********** annotations ********** + + public Iterator<Annotation> annotations() { + return this.getAnnotations().iterator(); + } + + private Iterable<Annotation> getAnnotations() { + return new LiveCloneIterable<Annotation>(this.annotations); + } + + public int annotationsSize() { + return this.annotations.size(); + } + + public Annotation getAnnotation(String annotationName) { + return this.selectAnnotationNamed(this.getAnnotations(), annotationName); + } + + public Annotation getNonNullAnnotation(String annotationName) { + Annotation annotation = this.getAnnotation(annotationName); + return (annotation != null) ? annotation : this.buildNullAnnotation(annotationName); + } + + public Iterator<NestableAnnotation> annotations( + String nestableAnnotationName, String containerAnnotationName) { + ContainerAnnotation<NestableAnnotation> containerAnnotation = + getContainerAnnotation(containerAnnotationName); if (containerAnnotation != null) { return containerAnnotation.nestedAnnotations(); } - NestableAnnotation nestableAnnotation = this.getSupportingNestableAnnotation(nestableAnnotationName); + NestableAnnotation nestableAnnotation = + getNestableAnnotation(nestableAnnotationName); return (nestableAnnotation == null) ? EmptyListIterator.<NestableAnnotation>instance() : - new SingleElementListIterator<NestableAnnotation>(nestableAnnotation); - } - - private NestableAnnotation getSupportingNestableAnnotation(String annotationName) { - return (NestableAnnotation) this.getSupportingAnnotation(annotationName); - } - - public Annotation getSupportingAnnotation(String annotationName) { - return this.selectAnnotationNamed(this.getSupportingAnnotations(), annotationName); - } - - public Annotation getNonNullSupportingAnnotation(String annotationName) { - Annotation annotation = this.getSupportingAnnotation(annotationName); - return (annotation != null) ? annotation : this.buildNullSupportingAnnotation(annotationName); + new SingleElementIterator<NestableAnnotation>(nestableAnnotation); } - - abstract Annotation buildNullSupportingAnnotation(String annotationName); - - abstract Annotation buildSupportingAnnotation(IAnnotation jdtAnnotation); - - private boolean annotationIsValidSupportingAnnotation(IAnnotation jdtAnnotation) { - return CollectionTools.contains(this.validSupportingAnnotationNames(), jdtAnnotation.getElementName()); + + private NestableAnnotation getNestableAnnotation(String annotationName) { + return (NestableAnnotation) this.getAnnotation(annotationName); } - - abstract ListIterator<String> validSupportingAnnotationNames(); - + @SuppressWarnings("unchecked") - private ContainerAnnotation<NestableAnnotation> getSupportingContainerAnnotation(String annotationName) { - return (ContainerAnnotation<NestableAnnotation>) this.getSupportingAnnotation(annotationName); - } - - + private ContainerAnnotation<NestableAnnotation> getContainerAnnotation(String annotationName) { + return (ContainerAnnotation<NestableAnnotation>) this.getAnnotation(annotationName); + } + + private boolean annotationIsValid(IAnnotation jdtAnnotation) { + return CollectionTools.contains( + this.validAnnotationNames(), jdtAnnotation.getElementName()); + } + + abstract Iterator<String> validAnnotationNames(); + + abstract Annotation buildAnnotation(IAnnotation jdtAnnotation); + + abstract Annotation buildNullAnnotation(String annotationName); + + // ********** simple state ********** public boolean isPersistable() { @@ -198,8 +156,8 @@ abstract class BinaryPersistentMember return this.adapter.isPersistable(); } - public boolean isPersisted() { - return this.getMappingAnnotation() != null; + public boolean isAnnotated() { + return ! this.annotations.isEmpty(); } @@ -278,45 +236,48 @@ abstract class BinaryPersistentMember // ********** unsupported JavaResourcePersistentMember implementation ********** - - public Annotation setMappingAnnotation(String annotationName) { + + public Annotation addAnnotation(String annotationName) { throw new UnsupportedOperationException(); } - - public Annotation addSupportingAnnotation(String annotationName) { + + public Annotation addAnnotation(String annotationName, AnnotationInitializer foo) { throw new UnsupportedOperationException(); } - - public Annotation addSupportingAnnotation(String annotationName, AnnotationInitializer foo) { + + public NestableAnnotation addAnnotation( + int index, String nestableAnnotationName, String containerAnnotationName) { throw new UnsupportedOperationException(); } - - public Annotation addSupportingAnnotation(int index, String nestableAnnotationName, String containerAnnotationName) { + + public void moveAnnotation( + int targetIndex, int sourceIndex, String containerAnnotationName) { throw new UnsupportedOperationException(); } - - public void moveSupportingAnnotation(int targetIndex, int sourceIndex, String containerAnnotationName) { + + public void removeAnnotation(String annotationName) { throw new UnsupportedOperationException(); } - - public void removeSupportingAnnotation(String annotationName) { + + public void removeAnnotation( + int index, String nestableAnnotationName, String containerAnnotationName) { throw new UnsupportedOperationException(); } - - public void removeSupportingAnnotation(int index, String nestableAnnotationName, String containerAnnotationName) { + + public Annotation setPrimaryAnnotation( + String primaryAnnotationName, String[] supportingAnnotationNames) { throw new UnsupportedOperationException(); } - + public TextRange getNameTextRange(CompilationUnit astRoot) { throw new UnsupportedOperationException(); } - + public void resolveTypes(CompilationUnit astRoot) { throw new UnsupportedOperationException(); } - + public boolean isFor(String memberName, int occurrence) { throw new UnsupportedOperationException(); } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java index 4f14df4511..6fa97b6b8c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java @@ -11,9 +11,7 @@ package org.eclipse.jpt.core.internal.resource.java.binary; import java.util.Collection; import java.util.Iterator; -import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jdt.core.IField; @@ -103,31 +101,21 @@ final class BinaryPersistentType // ********** BinaryPersistentMember implementation ********** @Override - Annotation buildMappingAnnotation(IAnnotation jdtAnnotation) { - return this.getAnnotationProvider().buildTypeMappingAnnotation(this, jdtAnnotation); + Annotation buildAnnotation(IAnnotation jdtAnnotation) { + return this.getAnnotationProvider().buildTypeAnnotation(this, jdtAnnotation); } @Override - Annotation buildSupportingAnnotation(IAnnotation jdtAnnotation) { - return this.getAnnotationProvider().buildTypeSupportingAnnotation(this, jdtAnnotation); + Annotation buildNullAnnotation(String annotationName) { + return this.getAnnotationProvider().buildNullTypeAnnotation(this, annotationName); } @Override - Annotation buildNullSupportingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullTypeSupportingAnnotation(this, annotationName); + Iterator<String> validAnnotationNames() { + return this.getAnnotationProvider().typeAnnotationNames(); } - @Override - ListIterator<String> validMappingAnnotationNames() { - return this.getAnnotationProvider().typeMappingAnnotationNames(); - } - @Override - ListIterator<String> validSupportingAnnotationNames() { - return this.getAnnotationProvider().typeSupportingAnnotationNames(); - } - - // ********** JavaResourcePersistentType implementation ********** // ***** name @@ -218,13 +206,13 @@ final class BinaryPersistentType private AccessType buildAccess() { return JPTTools.buildAccess(this); } - + /** * check only persistable attributes */ - public boolean hasAnyAttributePersistenceAnnotations() { + public boolean hasAnyAnnotatedAttributes() { for (Iterator<JavaResourcePersistentAttribute> stream = this.persistableAttributes(); stream.hasNext(); ) { - if (stream.next().hasAnyPersistenceAnnotations()) { + if (stream.next().isAnnotated()) { return true; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java index 0129138e8e..32901780c1 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentAttribute.java @@ -17,7 +17,6 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.ITypeBinding; @@ -150,69 +149,53 @@ final class SourcePersistentAttribute // ******** AbstractJavaResourcePersistentMember implementation ******** - - @Override - Annotation buildMappingAnnotation(String mappingAnnotationName) { - return this.getAnnotationProvider().buildAttributeMappingAnnotation(this, this.member, mappingAnnotationName); - } - - @Override - Annotation buildSupportingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildAttributeSupportingAnnotation(this, this.member, annotationName); - } - + @Override - Annotation buildNullSupportingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullAttributeSupportingAnnotation(this, annotationName); - } - - public Annotation getNullMappingAnnotation(String annotationName) { - return (annotationName == null) ? null : this.buildNullMappingAnnotation(annotationName); + Iterator<String> validAnnotationNames() { + return this.getAnnotationProvider().attributeAnnotationNames(); } - - private Annotation buildNullMappingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullAttributeMappingAnnotation(this, annotationName); - } - + @Override - ListIterator<String> validMappingAnnotationNames() { - return this.getAnnotationProvider().attributeMappingAnnotationNames(); + Annotation buildAnnotation(String annotationName) { + return this.getAnnotationProvider(). + buildAttributeAnnotation(this, this.member, annotationName); } - + @Override - ListIterator<String> validSupportingAnnotationNames() { - return this.getAnnotationProvider().attributeSupportingAnnotationNames(); + Annotation buildNullAnnotation(String annotationName) { + return this.getAnnotationProvider(). + buildNullAttributeAnnotation(this, annotationName); } - + public boolean isFor(MethodSignature signature, int occurrence) { return ((MethodAttribute) this.member).matches(signature, occurrence); } - - + + // ******** JavaResourcePersistentAttribute implementation ******** - + public String getName() { return this.member.getAttributeName(); } - + + public Annotation getNullAnnotation(String annotationName) { + return (annotationName == null) ? null : this.buildNullAnnotation(annotationName); + } + public boolean isField() { return this.member.isField(); } - + public boolean isProperty() { return ! this.isField(); } - - public boolean hasAnyPersistenceAnnotations() { - return (this.mappingAnnotationsSize() > 0) - || (this.supportingAnnotationsSize() > 0); - } - + public AccessType getSpecifiedAccess() { - Access2_0Annotation accessAnnotation = (Access2_0Annotation) this.getSupportingAnnotation(Access2_0Annotation.ANNOTATION_NAME); + Access2_0Annotation accessAnnotation = + (Access2_0Annotation) getAnnotation(Access2_0Annotation.ANNOTATION_NAME); return (accessAnnotation == null) ? null : accessAnnotation.getValue(); } - + public boolean typeIsSubTypeOf(String tn) { if (this.typeName == null) { return false; @@ -221,15 +204,16 @@ final class SourcePersistentAttribute || this.typeInterfaceNames.contains(tn) || this.typeSuperclassNames.contains(tn); } - + public boolean typeIsVariablePrimitive() { return (this.typeName != null) && ClassTools.classNamedIsVariablePrimitive(this.typeName); } - + private ITypeBinding getTypeBinding(CompilationUnit astRoot) { return this.member.getTypeBinding(astRoot); } - + + // ***** modifiers public int getModifiers() { return this.modifiers; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java index d780239ebb..c4bee2e3ce 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java @@ -9,15 +9,11 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.resource.java.source; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; -import java.util.ListIterator; import java.util.Set; import java.util.Vector; - import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.BodyDeclaration; @@ -36,10 +32,9 @@ import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.core.utility.jdt.Member; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterables.SnapshotCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.EmptyListIterator; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementListIterator; +import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; /** * Java source persistent member (annotations, "persistable") @@ -49,38 +44,31 @@ abstract class SourcePersistentMember<E extends Member> implements JavaResourcePersistentMember { final E member; - - /** - * mapping annotations; no duplicates (java compiler has an error for - * duplicates) - */ - final Vector<Annotation> mappingAnnotations = new Vector<Annotation>(); - + /** - * supporting annotations; no duplicates (java compiler has an error for - * duplicates) + * annotations; no duplicates (java compiler has an error for duplicates) */ - final Vector<Annotation> supportingAnnotations = new Vector<Annotation>(); - + final Vector<Annotation> annotations = new Vector<Annotation>(); + boolean persistable; - - + + // ********** construction/initialization ********** - + SourcePersistentMember(JavaResourceNode parent, E member) { super(parent); this.member = member; } - + public void initialize(CompilationUnit astRoot) { this.member.getBodyDeclaration(astRoot).accept(this.buildInitialAnnotationVisitor(astRoot)); this.persistable = this.buildPersistable(astRoot); } - + private ASTVisitor buildInitialAnnotationVisitor(CompilationUnit astRoot) { return new InitialAnnotationVisitor(astRoot, this.member.getBodyDeclaration(astRoot)); } - + /** * called from InitialAnnotationVisitor */ @@ -89,207 +77,82 @@ abstract class SourcePersistentMember<E extends Member> if (jdtAnnotationName == null) { return; } - if (this.annotationIsValidSupportingAnnotation(jdtAnnotationName)) { - if (this.selectAnnotationNamed(this.supportingAnnotations, jdtAnnotationName) == null) { // ignore duplicates - Annotation annotation = this.buildSupportingAnnotation(jdtAnnotationName); - annotation.initialize(astRoot); - this.supportingAnnotations.add(annotation); - } - } else if (this.annotationIsValidMappingAnnotation(jdtAnnotationName)) { - if (this.selectAnnotationNamed(this.mappingAnnotations, jdtAnnotationName) == null) { // ignore duplicates - Annotation annotation = this.buildMappingAnnotation(jdtAnnotationName); + if (this.annotationIsValid(jdtAnnotationName)) { + if (this.selectAnnotationNamed(this.annotations, jdtAnnotationName) == null) { // ignore duplicates + Annotation annotation = this.buildAnnotation(jdtAnnotationName); annotation.initialize(astRoot); - this.mappingAnnotations.add(annotation); + this.annotations.add(annotation); } } } - - - // ********** mapping annotations ********** - - public Iterator<Annotation> mappingAnnotations() { - return this.getMappingAnnotations().iterator(); + + + // ********** annotations ********** + + public Iterator<Annotation> annotations() { + return this.getAnnotations().iterator(); } - - private Iterable<Annotation> getMappingAnnotations() { - return new LiveCloneIterable<Annotation>(this.mappingAnnotations); + + private Iterable<Annotation> getAnnotations() { + return new LiveCloneIterable<Annotation>(this.annotations); } - - public int mappingAnnotationsSize() { - return this.mappingAnnotations.size(); + + public int annotationsSize() { + return this.annotations.size(); } - - // TODO need property change notification on this mappingAnnotation changing - // from the context model we don't really care if their are multiple mapping - // annotations, just which one we need to use - public Annotation getMappingAnnotation() { - Iterable<Annotation> annotations = new SnapshotCloneIterable<Annotation>(this.mappingAnnotations); - for (ListIterator<String> stream = this.validMappingAnnotationNames(); stream.hasNext();) { - Annotation annotation = this.selectAnnotationNamed(annotations, stream.next()); - if (annotation != null) { - return annotation; - } - } - return null; + + public Annotation getAnnotation(String annotationName) { + return this.selectAnnotationNamed(this.getAnnotations(), annotationName); } - - public Annotation getMappingAnnotation(String annotationName) { - return this.selectAnnotationNamed(this.getMappingAnnotations(), annotationName); + + public Annotation getNonNullAnnotation(String annotationName) { + Annotation annotation = this.getAnnotation(annotationName); + return (annotation != null) ? annotation : this.buildNullAnnotation(annotationName); } - - /** - * Remove all other *mapping* annotations that exist; not just the one - * returned by #getMappingAnnotation(). #getMappingAnnotation() returns the - * first mapping annotation found in the source. If there were multiple - * mapping annotations (which is a validation error) then calling this - * method would not work because the new mapping annotation would be added - * to the end of the list of annotations. - */ - public Annotation setMappingAnnotation(String annotationName) { - Collection<Annotation> removedAnnotations = null; - Annotation newMapping = null; - if (annotationName == null) { - removedAnnotations = this.removeMappingAnnotations(); - } else { - if (this.selectAnnotationNamed(this.mappingAnnotations, annotationName) != null) { - throw new IllegalStateException("duplicate mapping annotation: " + annotationName); //$NON-NLS-1$ - } - removedAnnotations = this.removeMappingAnnotations(); - - newMapping = this.buildMappingAnnotation(annotationName); - this.mappingAnnotations.add(newMapping); - newMapping.newAnnotation(); - this.fireItemAdded(MAPPING_ANNOTATIONS_COLLECTION, newMapping); + public Iterator<NestableAnnotation> annotations( + String nestableAnnotationName, String containerAnnotationName) { + ContainerAnnotation<NestableAnnotation> containerAnnotation = + this.getContainerAnnotation(containerAnnotationName); + if (containerAnnotation != null) { + return containerAnnotation.nestedAnnotations(); } - // hold change notifications until the end so a project update does not - // occur before we are finished removing the old mapping(s) and/or adding - // the new mapping - this.fireItemsRemoved(MAPPING_ANNOTATIONS_COLLECTION, removedAnnotations); - return newMapping; - } - - /** - * Remove all mapping annotations that already exist. No change notification - * is fired. Return the removed annotations. - */ - private Collection<Annotation> removeMappingAnnotations() { - ArrayList<Annotation> removedAnnotations = null; - for (String mappingAnnotationName : CollectionTools.iterable(this.validMappingAnnotationNames())) { - Annotation mappingAnnotation = this.selectAnnotationNamed(this.mappingAnnotations, mappingAnnotationName); - if (mappingAnnotation != null) { - // only need to delete one, since we do not hold duplicates - this.mappingAnnotations.remove(mappingAnnotation); - mappingAnnotation.removeAnnotation(); - if (removedAnnotations == null) { - removedAnnotations = new ArrayList<Annotation>(); - } - removedAnnotations.add(mappingAnnotation); - } + NestableAnnotation nestableAnnotation = + getNestableAnnotation(nestableAnnotationName); + if (nestableAnnotation != null) { + return new SingleElementIterator<NestableAnnotation>(nestableAnnotation); } - return (removedAnnotations != null) ? removedAnnotations : Collections.<Annotation>emptySet(); - } - - abstract Annotation buildMappingAnnotation(String mappingAnnotationName); - - private boolean annotationIsValidMappingAnnotation(String annotationName) { - return CollectionTools.contains(this.validMappingAnnotationNames(), annotationName); + return EmptyIterator.instance(); } - - abstract ListIterator<String> validMappingAnnotationNames(); - - - // ********** supporting annotations ********** - - public Iterator<Annotation> supportingAnnotations() { - return this.getSupportingAnnotations().iterator(); - } - - private Iterable<Annotation> getSupportingAnnotations() { - return new LiveCloneIterable<Annotation>(this.supportingAnnotations); - } - - public int supportingAnnotationsSize() { - return this.supportingAnnotations.size(); - } - - public Annotation getSupportingAnnotation(String annotationName) { - return this.selectAnnotationNamed(this.getSupportingAnnotations(), annotationName); + + // minimize scope of suppressed warnings + @SuppressWarnings("unchecked") + private ContainerAnnotation<NestableAnnotation> getContainerAnnotation(String annotationName) { + return (ContainerAnnotation<NestableAnnotation>) getAnnotation(annotationName); } - - public Annotation getNonNullSupportingAnnotation(String annotationName) { - Annotation annotation = this.getSupportingAnnotation(annotationName); - return (annotation != null) ? annotation : this.buildNullSupportingAnnotation(annotationName); + + private NestableAnnotation getNestableAnnotation(String annotationName) { + return (NestableAnnotation) this.getAnnotation(annotationName); } - - abstract Annotation buildNullSupportingAnnotation(String annotationName); - - public Annotation addSupportingAnnotation(String annotationName) { - Annotation annotation = this.buildSupportingAnnotation(annotationName); - this.supportingAnnotations.add(annotation); + + public Annotation addAnnotation(String annotationName) { + Annotation annotation = this.buildAnnotation(annotationName); + this.annotations.add(annotation); annotation.newAnnotation(); - this.fireItemAdded(SUPPORTING_ANNOTATIONS_COLLECTION, annotation); + this.fireItemAdded(ANNOTATIONS_COLLECTION, annotation); return annotation; } - - public Annotation addSupportingAnnotation(String annotationName, AnnotationInitializer annotationInitializer) { - Annotation annotation = this.buildSupportingAnnotation(annotationName); - this.supportingAnnotations.add(annotation); + + public Annotation addAnnotation(String annotationName, AnnotationInitializer annotationInitializer) { + Annotation annotation = this.buildAnnotation(annotationName); + this.annotations.add(annotation); annotation.newAnnotation(); Annotation nestedAnnotation = annotationInitializer.initializeAnnotation(annotation); nestedAnnotation.newAnnotation(); - this.fireItemAdded(SUPPORTING_ANNOTATIONS_COLLECTION, annotation); + this.fireItemAdded(ANNOTATIONS_COLLECTION, annotation); return nestedAnnotation; } - - abstract Annotation buildSupportingAnnotation(String annotationName); - - public void removeSupportingAnnotation(String annotationName) { - Annotation annotation = this.getSupportingAnnotation(annotationName); - if (annotation != null) { - this.removeSupportingAnnotation(annotation); - } - } - - private void removeSupportingAnnotation(Annotation annotation) { - this.supportingAnnotations.remove(annotation); - annotation.removeAnnotation(); - this.fireItemRemoved(SUPPORTING_ANNOTATIONS_COLLECTION, annotation); - } - - private boolean annotationIsValidSupportingAnnotation(String annotationName) { - return CollectionTools.contains(this.validSupportingAnnotationNames(), annotationName); - } - - abstract ListIterator<String> validSupportingAnnotationNames(); - - - // ********** supporting "combo" annotations ********** - - public ListIterator<NestableAnnotation> supportingAnnotations(String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = this.getSupportingContainerAnnotation(containerAnnotationName); - if (containerAnnotation != null) { - return containerAnnotation.nestedAnnotations(); - } - - NestableAnnotation nestableAnnotation = this.getSupportingNestableAnnotation(nestableAnnotationName); - if (nestableAnnotation != null) { - return new SingleElementListIterator<NestableAnnotation>(nestableAnnotation); - } - - return EmptyListIterator.instance(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private ContainerAnnotation<NestableAnnotation> getSupportingContainerAnnotation(String annotationName) { - return (ContainerAnnotation<NestableAnnotation>) this.getSupportingAnnotation(annotationName); - } - - private NestableAnnotation getSupportingNestableAnnotation(String annotationName) { - return (NestableAnnotation) this.getSupportingAnnotation(annotationName); - } - + /** * 1. check for a container annotation; * if it is present, add a nested annotation to it @@ -299,19 +162,20 @@ abstract class SourcePersistentMember<E extends Member> * add a container annotation and move the stand-alone nested annotation to it * and add a new nested annotation to it also */ - public NestableAnnotation addSupportingAnnotation(int index, String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = this.getSupportingContainerAnnotation(containerAnnotationName); + public NestableAnnotation addAnnotation( + int index, String nestableAnnotationName, String containerAnnotationName) { + ContainerAnnotation<NestableAnnotation> containerAnnotation = + getContainerAnnotation(containerAnnotationName); if (containerAnnotation != null) { // ignore any stand-alone nestable annotations and just add to the container annotation return AnnotationContainerTools.addNestedAnnotation(index, containerAnnotation); } - - NestableAnnotation standAloneAnnotation = this.getSupportingNestableAnnotation(nestableAnnotationName); + NestableAnnotation standAloneAnnotation = + getNestableAnnotation(nestableAnnotationName); if (standAloneAnnotation == null) { // add a stand-alone nestable annotation since neither the nestable nor the container exist - return (NestableAnnotation) this.addSupportingAnnotation(nestableAnnotationName); + return (NestableAnnotation) this.addAnnotation(nestableAnnotationName); } - // move the stand-alone nestable annotation to a container and add another nestable return this.addSecondNestedAnnotation(index, containerAnnotationName, standAloneAnnotation); } @@ -325,21 +189,20 @@ abstract class SourcePersistentMember<E extends Member> * place when the context model gets an "update" and looks at the resource * model to determine what has changed */ - private NestableAnnotation addSecondNestedAnnotation(int index, String containerAnnotationName, NestableAnnotation standAloneAnnotation) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = this.buildSupportingContainerAnnotation(containerAnnotationName); - this.supportingAnnotations.add(containerAnnotation); + private NestableAnnotation addSecondNestedAnnotation( + int index, String containerAnnotationName, NestableAnnotation standAloneAnnotation) { + ContainerAnnotation<NestableAnnotation> containerAnnotation = + buildContainerAnnotation(containerAnnotationName); + this.annotations.add(containerAnnotation); containerAnnotation.newAnnotation(); - + NestableAnnotation nestedAnnotation0 = containerAnnotation.addNestedAnnotationInternal(); nestedAnnotation0.newAnnotation(); - NestableAnnotation nestedAnnotation1 = containerAnnotation.addNestedAnnotationInternal(); nestedAnnotation1.newAnnotation(); - - this.removeSupportingAnnotation(standAloneAnnotation); - - this.fireItemAdded(SUPPORTING_ANNOTATIONS_COLLECTION, containerAnnotation); - + this.removeAnnotation(standAloneAnnotation); + this.fireItemAdded(ANNOTATIONS_COLLECTION, containerAnnotation); + if (index == 0) { // adding new annotation at 0, so stand-alone is "copied" to slot 1 nestedAnnotation1.initializeFrom(standAloneAnnotation); @@ -347,43 +210,57 @@ abstract class SourcePersistentMember<E extends Member> // adding new annotation at 1, so stand-alone is "copied" to slot 0 nestedAnnotation0.initializeFrom(standAloneAnnotation); } - + return (index == 0) ? nestedAnnotation0 : nestedAnnotation1; } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private ContainerAnnotation<NestableAnnotation> buildSupportingContainerAnnotation(String annotationName) { - return (ContainerAnnotation<NestableAnnotation>) this.buildSupportingAnnotation(annotationName); - } - - public void moveSupportingAnnotation(int targetIndex, int sourceIndex, String containerAnnotationName) { - this.moveAnnotation(targetIndex, sourceIndex, this.getSupportingContainerAnnotation(containerAnnotationName)); + + public void moveAnnotation( + int targetIndex, int sourceIndex, String containerAnnotationName) { + moveAnnotation(targetIndex, sourceIndex, getContainerAnnotation(containerAnnotationName)); } - - private void moveAnnotation(int targetIndex, int sourceIndex, ContainerAnnotation<NestableAnnotation> containerAnnotation) { + + private void moveAnnotation( + int targetIndex, int sourceIndex, + ContainerAnnotation<NestableAnnotation> containerAnnotation) { AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex, containerAnnotation); } - public void removeSupportingAnnotation(int index, String nestableAnnotationName, String containerAnnotationName) { - ContainerAnnotation<NestableAnnotation> containerAnnotation = this.getSupportingContainerAnnotation(containerAnnotationName); + public void removeAnnotation(String annotationName) { + Annotation annotation = getAnnotation(annotationName); + if (annotation != null) { + this.removeAnnotation(annotation); + } + } + + private void removeAnnotation(Annotation annotation) { + this.annotations.remove(annotation); + annotation.removeAnnotation(); + this.fireItemRemoved(ANNOTATIONS_COLLECTION, annotation); + } + + public void removeAnnotation( + int index, String nestableAnnotationName, String containerAnnotationName) { + ContainerAnnotation<NestableAnnotation> containerAnnotation = + getContainerAnnotation(containerAnnotationName); if (containerAnnotation == null) { // assume the index is 0 - this.removeSupportingAnnotation(this.getSupportingAnnotation(nestableAnnotationName)); - } else { - this.removeSupportingAnnotation(index, containerAnnotation); + removeAnnotation(getAnnotation(nestableAnnotationName)); + } + else { + removeAnnotation(index, containerAnnotation); } } - + /** * after we remove the nested annotation, check to see whether we need to * either remove the container (if it is empty) or convert the last nested * annotation to a stand-alone annotation */ - private void removeSupportingAnnotation(int index, ContainerAnnotation<NestableAnnotation> containerAnnotation) { + private void removeAnnotation( + int index, ContainerAnnotation<NestableAnnotation> containerAnnotation) { AnnotationContainerTools.removeNestedAnnotation(index, containerAnnotation); switch (containerAnnotation.nestedAnnotationsSize()) { case 0: - this.removeSupportingAnnotation(containerAnnotation); + this.removeAnnotation(containerAnnotation); break; case 1: this.convertLastNestedAnnotation(containerAnnotation); @@ -402,128 +279,163 @@ abstract class SourcePersistentMember<E extends Member> * place when the context model gets an "update" and looks at the resource * model to determine what has changed */ - private void convertLastNestedAnnotation(ContainerAnnotation<NestableAnnotation> containerAnnotation) { + private void convertLastNestedAnnotation( + ContainerAnnotation<NestableAnnotation> containerAnnotation) { NestableAnnotation lastNestedAnnotation = containerAnnotation.nestedAnnotations().next(); - this.supportingAnnotations.remove(containerAnnotation); + annotations.remove(containerAnnotation); containerAnnotation.removeAnnotation(); - - NestableAnnotation standAloneAnnotation = (NestableAnnotation) this.buildSupportingAnnotation(lastNestedAnnotation.getAnnotationName()); - this.supportingAnnotations.add(standAloneAnnotation); + + NestableAnnotation standAloneAnnotation = + buildNestableAnnotation(lastNestedAnnotation.getAnnotationName()); + this.annotations.add(standAloneAnnotation); standAloneAnnotation.newAnnotation(); - this.fireItemRemoved(SUPPORTING_ANNOTATIONS_COLLECTION, containerAnnotation); - this.fireItemAdded(SUPPORTING_ANNOTATIONS_COLLECTION, standAloneAnnotation); + this.fireItemRemoved(ANNOTATIONS_COLLECTION, containerAnnotation); + this.fireItemAdded(ANNOTATIONS_COLLECTION, standAloneAnnotation); standAloneAnnotation.initializeFrom(lastNestedAnnotation); } - - + + public Annotation setPrimaryAnnotation( + String primaryAnnotationName, String[] supportingAnnotationNames) { + Annotation newPrimaryAnnotation = null; + String[] annotationNamesToKeep = supportingAnnotationNames; + if (primaryAnnotationName != null) { + annotationNamesToKeep = CollectionTools.add(supportingAnnotationNames, primaryAnnotationName); + } + for (Annotation existingAnnotation : getAnnotations()) { + if (! CollectionTools.contains(annotationNamesToKeep, existingAnnotation.getAnnotationName())) { + this.annotations.remove(existingAnnotation); + existingAnnotation.removeAnnotation(); + } + } + if (primaryAnnotationName != null && getAnnotation(primaryAnnotationName) == null) { + newPrimaryAnnotation = buildAnnotation(primaryAnnotationName); + this.annotations.add(newPrimaryAnnotation); + newPrimaryAnnotation.newAnnotation(); + } + // fire collection change event after all annotation changes are done + fireCollectionChanged(ANNOTATIONS_COLLECTION, Collections.unmodifiableCollection(this.annotations)); + return newPrimaryAnnotation; + } + + private boolean annotationIsValid(String annotationName) { + return CollectionTools.contains(this.validAnnotationNames(), annotationName); + } + + abstract Iterator<String> validAnnotationNames(); + + abstract Annotation buildAnnotation(String mappingAnnotationName); + + abstract Annotation buildNullAnnotation(String annotationName); + + // minimize scope of suppressed warnings + @SuppressWarnings("unchecked") + private ContainerAnnotation<NestableAnnotation> buildContainerAnnotation(String annotationName) { + return (ContainerAnnotation<NestableAnnotation>) buildAnnotation(annotationName); + } + + @SuppressWarnings("unchecked") + private NestableAnnotation buildNestableAnnotation(String annotationName) { + return (NestableAnnotation) buildAnnotation(annotationName); + } + + // ********** simple state ********** - + public boolean isPersistable() { return this.persistable; } - + private void setPersistable(boolean persistable) { boolean old = this.persistable; this.persistable = persistable; this.firePropertyChanged(PERSISTABLE_PROPERTY, old, persistable); } - + private boolean buildPersistable(CompilationUnit astRoot) { return this.member.isPersistable(astRoot); } - - public boolean isPersisted() { - return this.getMappingAnnotation() != null; + + public boolean isAnnotated() { + return ! this.annotations.isEmpty(); } - + public boolean isFor(String memberName, int occurrence) { return this.member.matches(memberName, occurrence); } - + public TextRange getTextRange(CompilationUnit astRoot) { return this.fullTextRange(astRoot); } - + private TextRange fullTextRange(CompilationUnit astRoot) { return this.buildTextRange(this.member.getBodyDeclaration(astRoot)); } - + public TextRange getNameTextRange(CompilationUnit astRoot) { return this.member.getNameTextRange(astRoot); } - - + + // ********** update ********** - + public void update(CompilationUnit astRoot) { this.updateAnnotations(astRoot); this.setPersistable(this.buildPersistable(astRoot)); } - + private void updateAnnotations(CompilationUnit astRoot) { - HashSet<Annotation> mappingAnnotationsToRemove = new HashSet<Annotation>(this.mappingAnnotations); - HashSet<Annotation> supportingAnnotationsToRemove = new HashSet<Annotation>(this.supportingAnnotations); - - this.member.getBodyDeclaration(astRoot).accept(this.buildUpdateAnnotationVisitor(astRoot, mappingAnnotationsToRemove, supportingAnnotationsToRemove)); - - for (Annotation annotation : mappingAnnotationsToRemove) { - this.removeItemFromCollection(annotation, this.mappingAnnotations, MAPPING_ANNOTATIONS_COLLECTION); - } - for (Annotation annotation : supportingAnnotationsToRemove) { - this.removeItemFromCollection(annotation, this.supportingAnnotations, SUPPORTING_ANNOTATIONS_COLLECTION); + HashSet<Annotation> annotationsToRemove = + new HashSet<Annotation>(this.annotations); + + this.member.getBodyDeclaration(astRoot).accept( + this.buildUpdateAnnotationVisitor(astRoot, annotationsToRemove)); + + for (Annotation annotation : annotationsToRemove) { + this.removeItemFromCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); } } - - private ASTVisitor buildUpdateAnnotationVisitor(CompilationUnit astRoot, Set<Annotation> mappingAnnotationsToRemove, Set<Annotation> supportingAnnotationsToRemove) { - return new UpdateAnnotationVisitor(astRoot, this.member.getBodyDeclaration(astRoot), mappingAnnotationsToRemove, supportingAnnotationsToRemove); + + private ASTVisitor buildUpdateAnnotationVisitor( + CompilationUnit astRoot, Set<Annotation> annotationsToRemove) { + return new UpdateAnnotationVisitor( + astRoot, this.member.getBodyDeclaration(astRoot), annotationsToRemove); } - - void addOrUpdateAnnotation(org.eclipse.jdt.core.dom.Annotation node, CompilationUnit astRoot, Set<Annotation> mappingAnnotationsToRemove, Set<Annotation> supportingAnnotationsToRemove) { + + void addOrUpdateAnnotation( + org.eclipse.jdt.core.dom.Annotation node, CompilationUnit astRoot, + Set<Annotation> annotationsToRemove) { String jdtAnnotationName = JDTTools.resolveAnnotation(node); if (jdtAnnotationName == null) { return; } - if (this.annotationIsValidSupportingAnnotation(jdtAnnotationName)) { - this.addOrUpdateSupportingAnnotation(jdtAnnotationName, astRoot, supportingAnnotationsToRemove); - return; - } - if (this.annotationIsValidMappingAnnotation(jdtAnnotationName)) { - this.addOrUpdateMappingAnnotation(jdtAnnotationName, astRoot, mappingAnnotationsToRemove); + if (this.annotationIsValid(jdtAnnotationName)) { + this.addOrUpdateAnnotation(jdtAnnotationName, astRoot, annotationsToRemove); return; } } - - private void addOrUpdateSupportingAnnotation(String jdtAnnotationName, CompilationUnit astRoot, Set<Annotation> supportingAnnotationsToRemove) { - Annotation annotation = this.selectAnnotationNamed(supportingAnnotationsToRemove, jdtAnnotationName); + + private void addOrUpdateAnnotation( + String jdtAnnotationName, CompilationUnit astRoot, + Set<Annotation> annotationsToRemove) { + Annotation annotation = this.selectAnnotationNamed(annotationsToRemove, jdtAnnotationName); if (annotation != null) { annotation.update(astRoot); - supportingAnnotationsToRemove.remove(annotation); - } else { - annotation = this.buildSupportingAnnotation(jdtAnnotationName); - annotation.initialize(astRoot); - this.addItemToCollection(annotation, this.supportingAnnotations, SUPPORTING_ANNOTATIONS_COLLECTION); + annotationsToRemove.remove(annotation); } - } - - private void addOrUpdateMappingAnnotation(String jdtAnnotationName, CompilationUnit astRoot, Set<Annotation> mappingAnnotationsToRemove) { - Annotation annotation = this.selectAnnotationNamed(mappingAnnotationsToRemove, jdtAnnotationName); - if (annotation != null) { - annotation.update(astRoot); - mappingAnnotationsToRemove.remove(annotation); - } else { - annotation = this.buildMappingAnnotation(jdtAnnotationName); + else { + annotation = this.buildAnnotation(jdtAnnotationName); annotation.initialize(astRoot); - this.addItemToCollection(annotation, this.mappingAnnotations, MAPPING_ANNOTATIONS_COLLECTION); + this.addItemToCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); } } - - + + // ********** miscellaneous ********** - + public void resolveTypes(CompilationUnit astRoot) { this.setPersistable(this.buildPersistable(astRoot)); } - + private Annotation selectAnnotationNamed(Iterable<Annotation> annotations, String annotationName) { for (Annotation annotation : annotations) { if (annotation.getAnnotationName().equals(annotationName)) { @@ -532,11 +444,11 @@ abstract class SourcePersistentMember<E extends Member> } return null; } - + private TextRange buildTextRange(ASTNode astNode) { return (astNode == null) ? null : new ASTNodeTextRange(astNode); } - + /** * convenience method */ @@ -548,38 +460,40 @@ abstract class SourcePersistentMember<E extends Member> } }; } - - + + // ********** AST visitors ********** - + /** * annotation visitor */ - protected static abstract class AnnotationVisitor extends ASTVisitor { + protected static abstract class AnnotationVisitor + extends ASTVisitor + { protected final CompilationUnit astRoot; protected final BodyDeclaration bodyDeclaration; - + protected AnnotationVisitor(CompilationUnit astRoot, BodyDeclaration bodyDeclaration) { super(); this.astRoot = astRoot; this.bodyDeclaration = bodyDeclaration; } - + @Override public boolean visit(SingleMemberAnnotation node) { return visit_(node); } - + @Override public boolean visit(NormalAnnotation node) { return visit_(node); } - + @Override public boolean visit(MarkerAnnotation node) { return visit_(node); } - + protected boolean visit_(org.eclipse.jdt.core.dom.Annotation node) { // ignore annotations for child members, only this member if (node.getParent() == this.bodyDeclaration) { @@ -587,45 +501,47 @@ abstract class SourcePersistentMember<E extends Member> } return false; } - + protected abstract void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node); - } - + + /** * initial annotation visitor */ - protected class InitialAnnotationVisitor extends AnnotationVisitor { - + protected class InitialAnnotationVisitor + extends AnnotationVisitor + { protected InitialAnnotationVisitor(CompilationUnit astRoot, BodyDeclaration bodyDeclaration) { super(astRoot, bodyDeclaration); } - + @Override protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { SourcePersistentMember.this.addInitialAnnotation(node, this.astRoot); } - } - + + /** * update annotation visitor */ - protected class UpdateAnnotationVisitor extends AnnotationVisitor { - protected final Set<Annotation> mappingAnnotationsToRemove; - protected final Set<Annotation> supportingAnnotationsToRemove; - - protected UpdateAnnotationVisitor(CompilationUnit astRoot, BodyDeclaration bodyDeclaration, Set<Annotation> mappingAnnotationsToRemove, Set<Annotation> supportingAnnotationsToRemove) { + protected class UpdateAnnotationVisitor + extends AnnotationVisitor + { + protected final Set<Annotation> annotationsToRemove; + + protected UpdateAnnotationVisitor( + CompilationUnit astRoot, BodyDeclaration bodyDeclaration, + Set<Annotation> annotationsToRemove) { super(astRoot, bodyDeclaration); - this.mappingAnnotationsToRemove = mappingAnnotationsToRemove; - this.supportingAnnotationsToRemove = supportingAnnotationsToRemove; + this.annotationsToRemove = annotationsToRemove; } - + @Override protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - SourcePersistentMember.this.addOrUpdateAnnotation(node, this.astRoot, this.mappingAnnotationsToRemove, this.supportingAnnotationsToRemove); - } - + SourcePersistentMember.this.addOrUpdateAnnotation( + node, this.astRoot, this.annotationsToRemove); + } } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java index 0daad1e8c2..7273060c85 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java @@ -14,9 +14,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.ITypeBinding; @@ -36,7 +34,6 @@ import org.eclipse.jpt.core.utility.jdt.Type; import org.eclipse.jpt.utility.MethodSignature; import org.eclipse.jpt.utility.internal.Counter; import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; import org.eclipse.jpt.utility.internal.iterators.TreeIterator; @@ -160,48 +157,40 @@ final class SourcePersistentType // ********** AbstractJavaResourcePersistentMember implementation ********** - - @Override - Annotation buildMappingAnnotation(String mappingAnnotationName) { - return this.getAnnotationProvider().buildTypeMappingAnnotation(this, this.member, mappingAnnotationName); - } @Override - Annotation buildSupportingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildTypeSupportingAnnotation(this, this.member, annotationName); + Iterator<String> validAnnotationNames() { + return this.getAnnotationProvider().typeAnnotationNames(); } @Override - Annotation buildNullSupportingAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullTypeSupportingAnnotation(this, annotationName); + Annotation buildAnnotation(String mappingAnnotationName) { + return this.getAnnotationProvider(). + buildTypeAnnotation(this, this.member, mappingAnnotationName); } @Override - ListIterator<String> validMappingAnnotationNames() { - return this.getAnnotationProvider().typeMappingAnnotationNames(); - } - - @Override - ListIterator<String> validSupportingAnnotationNames() { - return this.getAnnotationProvider().typeSupportingAnnotationNames(); + Annotation buildNullAnnotation(String annotationName) { + return this.getAnnotationProvider(). + buildNullTypeAnnotation(this, annotationName); } @Override public void resolveTypes(CompilationUnit astRoot) { super.resolveTypes(astRoot); - + this.setSuperclassQualifiedName(this.buildSuperclassQualifiedName(astRoot)); - + for (JavaResourcePersistentAttribute field : this.getFields()) { field.resolveTypes(astRoot); } - + // a new type can trigger a method parameter type to be a resolved, // fully-qualified name, so we need to rebuild our list of methods: // "setFoo(Foo)" is not the same as "setFoo(com.bar.Foo)" // and, vice-versa, a removed type can "unresolve" a parameter type this.updateMethods(astRoot); - + for (JavaResourcePersistentAttribute method : this.getMethods()) { method.resolveTypes(astRoot); } @@ -209,13 +198,13 @@ final class SourcePersistentType type.resolveTypes(astRoot); } } - + @Override public void toString(StringBuilder sb) { sb.append(this.name); } - - + + // ******** JavaResourcePersistentType implementation ******** // ***** name @@ -311,9 +300,10 @@ final class SourcePersistentType /** * check only persistable attributes */ - public boolean hasAnyAttributePersistenceAnnotations() { - for (Iterator<JavaResourcePersistentAttribute> stream = this.persistableAttributes(); stream.hasNext(); ) { - if (stream.next().hasAnyPersistenceAnnotations()) { + public boolean hasAnyAnnotatedAttributes() { + for (Iterator<JavaResourcePersistentAttribute> stream = + this.persistableAttributes(); stream.hasNext(); ) { + if (stream.next().isAnnotated()) { return true; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java index 8a41aeab7a..4ab0e88d3d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.core.internal.utility.jdt; import java.lang.reflect.Modifier; import java.util.Iterator; - import org.eclipse.jpt.core.resource.java.AccessType; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; @@ -308,7 +307,7 @@ public class JPTTools { boolean hasPersistableFields = false; for (Iterator<JavaResourcePersistentAttribute> stream = jrpType.persistableFields(); stream.hasNext(); ) { hasPersistableFields = true; - if (stream.next().hasAnyPersistenceAnnotations()) { + if (stream.next().isAnnotated()) { // any field is annotated => FIELD return AccessType.FIELD; } @@ -317,7 +316,7 @@ public class JPTTools { boolean hasPersistableProperties = false; for (Iterator<JavaResourcePersistentAttribute> stream = jrpType.persistableProperties(); stream.hasNext(); ) { hasPersistableProperties = true; - if (stream.next().hasAnyPersistenceAnnotations()) { + if (stream.next().isAnnotated()) { // none of the fields are annotated and a getter is annotated => PROPERTY return AccessType.PROPERTY; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/DerivedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/DerivedId2_0.java new file mode 100644 index 0000000000..83406099a7 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/DerivedId2_0.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context; + +import org.eclipse.jpt.core.context.JpaContextNode; + +/** + * 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 DerivedId2_0 + extends JpaContextNode +{ + /** + * String associated with changes to the derived id property of this object + */ + public static final String DERIVED_ID_PROPERTY = "derivedId"; //$NON-NLS-1$ + + /** + * Return whether this object uses a derived id + */ + boolean isDerivedId(); + + /** + * Set whether this object uses a derived id + */ + void setDerivedId(boolean newValue); +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/ManyToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/ManyToOneMapping2_0.java new file mode 100644 index 0000000000..a1ff3ce550 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/ManyToOneMapping2_0.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context; + +import org.eclipse.jpt.core.context.ManyToOneMapping; + +public interface ManyToOneMapping2_0 + extends ManyToOneMapping, SingleRelationshipMapping2_0 +{} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToOneMapping2_0.java new file mode 100644 index 0000000000..eef30eaed1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/OneToOneMapping2_0.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context; + +import org.eclipse.jpt.core.context.OneToOneMapping; + +public interface OneToOneMapping2_0 + extends OneToOneMapping, SingleRelationshipMapping2_0 +{} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/SingleRelationshipMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/SingleRelationshipMapping2_0.java new file mode 100644 index 0000000000..3aa991d89d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/SingleRelationshipMapping2_0.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context; + +import org.eclipse.jpt.core.context.SingleRelationshipMapping; + +/** + * 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. + */ +public interface SingleRelationshipMapping2_0 + extends SingleRelationshipMapping +{ + // **************** Derived id ******************************************** + + DerivedId2_0 getDerivedId(); +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaDerivedId2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaDerivedId2_0.java new file mode 100644 index 0000000000..6c0db486dd --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaDerivedId2_0.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaJpaContextNode; +import org.eclipse.jpt.core.jpa2.context.DerivedId2_0; + +/** + * 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. + */ +public interface JavaDerivedId2_0 + extends JavaJpaContextNode, DerivedId2_0 +{ + /** + * Initialize model without throwing any events + */ + void initialize(); + + /** + * Update model, throwing events as necessary + */ + void update(); +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaManyToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaManyToOneMapping2_0.java new file mode 100644 index 0000000000..e028c94f1e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaManyToOneMapping2_0.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; + +/** + * 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. + */ +public interface JavaManyToOneMapping2_0 + extends JavaManyToOneMapping, JavaSingleRelationshipMapping2_0 +{} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToOneMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToOneMapping2_0.java new file mode 100644 index 0000000000..9231347811 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaOneToOneMapping2_0.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; + +/** + * 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. + */ +public interface JavaOneToOneMapping2_0 + extends JavaOneToOneMapping, JavaSingleRelationshipMapping2_0 +{} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaSingleRelationshipMapping2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaSingleRelationshipMapping2_0.java new file mode 100644 index 0000000000..a37ab2ea0b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/context/java/JavaSingleRelationshipMapping2_0.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2009 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.core.jpa2.context.java; + +import org.eclipse.jpt.core.context.java.JavaSingleRelationshipMapping; +import org.eclipse.jpt.core.jpa2.context.SingleRelationshipMapping2_0; + +/** + * 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. + */ +public interface JavaSingleRelationshipMapping2_0 + extends JavaSingleRelationshipMapping, SingleRelationshipMapping2_0 +{} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/Access2_0Annotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/Access2_0Annotation.java index 9afb602a4a..0d247d9c1c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/Access2_0Annotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/Access2_0Annotation.java @@ -31,7 +31,7 @@ public interface Access2_0Annotation extends Annotation { - String ANNOTATION_NAME = JPA.ACCESS; + String ANNOTATION_NAME = JPA2_0.ACCESS; /** * Corresponds to the 'value' element of the Access annotation. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/JPA.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/JPA2_0.java index 96e65a286c..d16c355f2d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/JPA.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/jpa2/resource/java/JPA2_0.java @@ -10,7 +10,7 @@ package org.eclipse.jpt.core.jpa2.resource.java; /** - * JPA Java-related stuff (annotations etc.) + * JPA 2.0 Java-related stuff (annotations etc.) * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching @@ -19,7 +19,7 @@ package org.eclipse.jpt.core.jpa2.resource.java; * will almost certainly be broken (repeatedly) as the API evolves. */ @SuppressWarnings("nls") -public interface JPA { +public interface JPA2_0 { // JPA package String PACKAGE = "javax.persistence"; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentAttribute.java index 1ede2a0471..386fdd36ed 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentAttribute.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.core.resource.java; import java.util.Iterator; import java.util.ListIterator; - import org.eclipse.jpt.utility.MethodSignature; /** @@ -33,16 +32,16 @@ public interface JavaResourcePersistentAttribute * The Java resource persistent attribute's name does not change. */ String getName(); - + /** - * Return a null mapping annotation with the specified name. + * Return a null annotation for the specified annotation name. * Return null if the specified annotation name is null. * The corresponding AnnotationDefinition must implement #buildNullAnnotation() * {@link AnnotationDefinition#buildNullAnnotation(JavaResourcePersistentMember, * org.eclipse.jpt.core.utility.jdt.Member)} */ - Annotation getNullMappingAnnotation(String annotationName); - + Annotation getNullAnnotation(String annotationName); + /** * Whether the Java resource persistent attribute is a field does not change. */ @@ -54,12 +53,6 @@ public interface JavaResourcePersistentAttribute boolean isProperty(); /** - * Return whether the attribute has any mapping or non-mapping annotations - * (of course only persistence-related annotations). - */ - boolean hasAnyPersistenceAnnotations(); - - /** * Return the access type explicitly specified by the javax.persistence.Access annotation. * Return null if the Access annotation is not present. * For JPA 1.0 this is always going to return null; Access annotation is not supported in 1.0. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java index 1df750182b..d4a00cf74b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java @@ -10,8 +10,6 @@ package org.eclipse.jpt.core.resource.java; import java.util.Iterator; -import java.util.ListIterator; - import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.utility.TextRange; @@ -27,94 +25,64 @@ import org.eclipse.jpt.core.utility.TextRange; public interface JavaResourcePersistentMember extends JavaResourceNode { - - // ********** mapping annotations ********** - + // ********** annotations ********** + /** - * Return the member's mapping annotations. - * Do not return duplicate annotations as this error is handled by the Java - * compiler. - * @see #supportingAnnotations() + * String associated with changes to the "annotations" collection */ - Iterator<Annotation> mappingAnnotations(); - String MAPPING_ANNOTATIONS_COLLECTION = "mappingAnnotations"; //$NON-NLS-1$ - + String ANNOTATIONS_COLLECTION = "annotations"; //$NON-NLS-1$ + /** - * Return the number of mapping annotations. + * Return the member's annotations in the order that they appear. + * Do not return duplicate annotations as this error is handled by the Java + * compiler. */ - int mappingAnnotationsSize(); - + Iterator<Annotation> annotations(); + /** - * Return the member's mapping annotation. + * Return the number of annotations. */ - Annotation getMappingAnnotation(); - + int annotationsSize(); + /** - * Return the mapping annotation with the specified name. + * Return the annotation with the specified name. * Return the first if there are duplicates in the source code. */ - Annotation getMappingAnnotation(String annotationName); - - /** - * Change the mapping annotation. Remove any other existing mapping - * annotations. Do not remove any supporting (non-mapping) annotations. - */ - Annotation setMappingAnnotation(String annotationName); - - - // ********** supporting annotations ********** - - /** - * Return the member's supporting annotations. - * Do not return duplicate annotations as this error is handled by the Java - * compiler. Do not return any mapping annotations. - * @see #mappingAnnotations() - */ - Iterator<Annotation> supportingAnnotations(); - String SUPPORTING_ANNOTATIONS_COLLECTION = "supportingAnnotations"; //$NON-NLS-1$ - + Annotation getAnnotation(String annotationName); + /** - * Return the number of supporting annotations. + * Return the specified annotation. + * Return the first if there are duplicates in the source code. + * Do not return null, but a Null Object instead if no annotation + * with the specified name exists in the source code. */ - int supportingAnnotationsSize(); - + Annotation getNonNullAnnotation(String annotationName); + /** - * Return the specified supporting nested annotations. - * If both the nestable and container annotations are specified on the + * Return the nestable annotations with the specified name in the order that + * they appear. + * If nestable and container annotations are both specified on the * member directly, return only the nestable annotations specified within * the container annotation. */ // TODO tie the singular and plural annotations together so we can generate // a validation error when both are specified - ListIterator<NestableAnnotation> supportingAnnotations(String nestableAnnotationName, String containerAnnotationName); - - /** - * Return the specified supporting annotation. - * Return the first if there are duplicates in the source code. - */ - Annotation getSupportingAnnotation(String annotationName); - - /** - * Return the specified supporting annotation. - * Return the first if there are duplicates in the source code. - * Do not return null, but a Null Object instead if no annotation - * with the specified name exists in the source code. - */ - Annotation getNonNullSupportingAnnotation(String annotationName); - + Iterator<NestableAnnotation> annotations( + String nestableAnnotationName, String containerAnnotationName); + /** - * Add a supporting annotation with the specified name. + * Add an annotation with the specified name. * Return the newly-created annotation. */ - Annotation addSupportingAnnotation(String annotationName); - + Annotation addAnnotation(String annotationName); + /** - * Add a supporting annotation with the specified name. + * Add an annotation with the specified name. * Initialize the newly-created annotation with the specified annotation initializer. * Return the annotation returned by the annotation initializer. */ - Annotation addSupportingAnnotation(String annotationName, AnnotationInitializer annotationInitializer); - + Annotation addAnnotation(String annotationName, AnnotationInitializer annotationInitializer); + /** * Callback that allows clients to initialize an annotation added to the * member before the member fires a change event. The initializer should @@ -127,14 +95,9 @@ public interface JavaResourcePersistentMember */ Annotation initializeAnnotation(Annotation supportingAnnotation); } - - /** - * Remove the specified supporting annotation. - */ - void removeSupportingAnnotation(String annotationName); - + /** - * Add a new supporting nestable annotation with the specified name. + * Add a new nestable annotation with the specified name. * Create a new container annotation if necessary and add the nestable * annotation to it. * If both the nestable annotation and the container annotation already @@ -145,22 +108,41 @@ public interface JavaResourcePersistentMember * the new one. If neither annotation exists, then create a new nestable * annotation. */ - Annotation addSupportingAnnotation(int index, String nestableAnnotationName, String containerAnnotationName); - + NestableAnnotation addAnnotation( + int index, String nestableAnnotationName, String containerAnnotationName); + /** - * Move the supporting nestable annotation found in the specified container + * Move the nestable annotation found in the specified container * annotation at the specified source index to the specified target index. */ - void moveSupportingAnnotation(int targetIndex, int sourceIndex, String containerAnnotationName); + void moveAnnotation( + int targetIndex, int sourceIndex, String containerAnnotationName); /** - * Remove the specified supporting nestable annotation. + * Remove the specified annotation. */ - void removeSupportingAnnotation(int index, String nestableAnnotationName, String containerAnnotationName); + void removeAnnotation(String annotationName); + + /** + * Remove the specified nestable annotation from the container annotation at the specified + * index. + * If there is no container, assume the index is zero and this does the same as + * {@link #removeAnnotation(String)} + */ + void removeAnnotation( + int index, String nestableAnnotationName, String containerAnnotationName); + + /** + * Sets the specified primary annotation as the first annotation, and removes all known + * annotations (i.e. does not remove non-persistence annotations) which are not included + * in the supporting annotations. + */ + Annotation setPrimaryAnnotation( + String primaryAnnotationName, String[] supportingAnnotationNames); + - // ********** queries ********** - + /** * Return whether the underlying JDT member is persistable according to * the JPA spec. @@ -169,29 +151,28 @@ public interface JavaResourcePersistentMember String PERSISTABLE_PROPERTY = "persistable"; //$NON-NLS-1$ /** - * Return whether the underlying JDT member is currently annotated as being - * persistent (equivalent to "is mapped"). + * Return whether the underlying JDT member is currently annotated with any recognized + * annotations. */ - boolean isPersisted(); - + boolean isAnnotated(); + /** * Return whether the Java resource persistent member is for the specified * member. */ boolean isFor(String memberName, int occurrence); - + /** * Return the text range for the member's name. */ TextRange getNameTextRange(CompilationUnit astRoot); - + // ********** behavior ********** - + /** * Resolve type information that could be dependent on changes elsewhere * in the workspace. */ void resolveTypes(CompilationUnit astRoot); - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java index 3e0089d1bc..408e1650fb 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java @@ -57,7 +57,7 @@ public interface JavaResourcePersistentType * Return whether the type has any attributes that have * JPA annotations on them. */ - boolean hasAnyAttributePersistenceAnnotations(); + boolean hasAnyAnnotatedAttributes(); // ********** types ********** |