Author: dgeraskov
Date: 2011-02-28 04:02:34 -0500 (Mon, 28 Feb 2011)
New Revision: 29379
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainer.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainerImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDef.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDefImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotationImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotationImpl.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaParameter.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotationImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java
Log:
https://issues.jboss.org/browse/JBIDE-8239
support @TypeDef and @TypeDefs
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -1,6 +1,7 @@
package org.jboss.tools.hibernate.jpt.core.internal;
import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.context.JpaContextNode;
import org.eclipse.jpt.core.context.java.JavaBaseColumn;
import org.eclipse.jpt.core.context.java.JavaBasicMapping;
import org.eclipse.jpt.core.context.java.JavaColumn;
@@ -37,6 +38,8 @@
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaSecondaryTableImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaTable;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaTableImpl;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaTypeDefContainer;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaTypeDefContainerImpl;
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateNamedNativeQueryImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateNamedQueryImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.IndexImpl;
@@ -47,6 +50,8 @@
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaIndex;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaParameter;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaType;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaTypeDef;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaTypeDefImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.TypeImpl;
public abstract class HibernateAbstractJpaFactory extends AbstractJpaFactory {
@@ -71,6 +76,10 @@
return new JavaGenericGeneratorImpl(parent);
}
+ public JavaTypeDef buildJavaTypeDef(JavaJpaContextNode parent) {
+ return new JavaTypeDefImpl(parent);
+ }
+
@Override
public JavaDiscriminatorColumn buildJavaDiscriminatorColumn(
JavaEntity parent,
@@ -86,8 +95,8 @@
return new HibernateNamedNativeQueryImpl(parent);
}
- public JavaParameter buildJavaParameter(JavaGenericGeneratorImpl
javaGenericGeneratorImpl) {
- return new HibernateJavaParameter(javaGenericGeneratorImpl);
+ public JavaParameter buildJavaParameter(JpaContextNode parent) {
+ return new HibernateJavaParameter(parent);
}
public JavaDiscriminatorFormula buildJavaDiscriminatorFormula(
@@ -142,6 +151,10 @@
public JavaGeneratorContainer buildJavaGeneratorContainer(JavaJpaContextNode parent) {
return new HibernateJavaGeneratorContainerImpl(parent);
}
+
+ public HibernateJavaTypeDefContainer buildJavaTypeDefContainer(JavaJpaContextNode
parent) {
+ return new HibernateJavaTypeDefContainerImpl(parent);
+ }
public JavaIndex buildIndex(JavaJpaContextNode parent) {
return new IndexImpl(parent);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -26,6 +26,8 @@
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.IndexAnnotationImpl.IndexAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.SourceGenericGeneratorsAnnotation.GenericGeneratorsAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotationImpl.TypeAnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefAnnotationImpl.TypeDefAnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefsAnnotationImpl.TypeDefsAnnotationDefinition;
/**
* @author Dmitry Geraskov
@@ -54,6 +56,8 @@
protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition>
definitions) {
definitions.add(GenericGeneratorAnnotationDefinition.instance());
definitions.add(GenericGeneratorsAnnotationDefinition.instance());
+ definitions.add(TypeDefAnnotationDefinition.instance());
+ definitions.add(TypeDefsAnnotationDefinition.instance());
definitions.add(HibernateNamedQueryAnnotationDefinition.instance());
definitions.add(HibernateNamedQueriesAnnotationDefinition.instance());
definitions.add(HibernateNamedNativeQueryAnnotationDefinition.instance());
@@ -66,6 +70,8 @@
protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition>
definitions) {
definitions.add(GenericGeneratorAnnotationDefinition.instance());
definitions.add(GeneratedAnnotationDefinition.instance());
+ definitions.add(TypeDefAnnotationDefinition.instance());
+ definitions.add(TypeDefsAnnotationDefinition.instance());
definitions.add(IndexAnnotationDefinition.instance());
definitions.add(TypeAnnotationDefinition.instance());
definitions.add(ForeignKeyAnnotationDefinition.instance());
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -11,7 +11,12 @@
package org.jboss.tools.hibernate.jpt.core.internal.context;
import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+import java.util.Vector;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
@@ -24,6 +29,7 @@
import org.eclipse.jpt.core.context.persistence.Persistence;
import org.eclipse.jpt.core.internal.context.persistence.AbstractPersistenceUnit;
import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
+import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
@@ -31,6 +37,7 @@
import
org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
import
org.jboss.tools.hibernate.jpt.core.internal.context.basic.HibernatePersistenceUnitProperties;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaTypeDef;
import
org.jboss.tools.hibernate.jpt.core.internal.context.persistence.HibernatePersistenceUnitPropertiesBuilder;
/**
@@ -40,7 +47,12 @@
public class HibernatePersistenceUnit extends AbstractPersistenceUnit
implements Messages, Hibernate {
+ public String TYPE_DEF_LIST = "typeDefs"; //$NON-NLS-1$
+
private HibernatePersistenceUnitProperties hibernateProperties;
+
+ /* global type def definitions, defined elsewhere in model */
+ protected final Vector<JavaTypeDef> typeDefs = new Vector<JavaTypeDef>();
/**
* @param parent
@@ -51,7 +63,19 @@
super(parent, persistenceUnit);
}
+ protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) {
+ super.addNonUpdateAspectNamesTo(nonUpdateAspectNames);
+ nonUpdateAspectNames.add(TYPE_DEF_LIST);
+ }
+
@Override
+ public void update(XmlPersistenceUnit xpu) {
+ this.typeDefs.clear();
+ super.update(xpu);
+ this.fireListChanged(TYPE_DEF_LIST, this.typeDefs);
+ }
+
+ @Override
protected void initializeProperties() {
super.initializeProperties();
this.hibernateProperties =
((HibernatePersistenceUnitPropertiesBuilder)this.getContextNodeFactory())
@@ -74,7 +98,46 @@
public HibernatePersistenceUnitProperties getHibernatePersistenceUnitProperties() {
return this.hibernateProperties;
}
+
+ // ******** Type Def *********
+ public ListIterator<JavaTypeDef> typeDefs() {
+ return new CloneListIterator<JavaTypeDef>(this.typeDefs);
+ }
+
+ public int typeDefsSize() {
+ return this.typeDefs.size();
+ }
+
+ public void addTypeDef(JavaTypeDef typeDef) {
+ this.typeDefs.add(typeDef);
+ }
+
+ public String[] uniqueTypeDefNames() {
+ HashSet<String> names = new HashSet<String>(this.typeDefs.size());
+ this.addNonNullTypeDefNamesTo(names);
+ return names.toArray(new String[names.size()]);
+ }
+
+ public boolean hasTypeDef(String name) {
+ for (Iterator<JavaTypeDef> stream = this.typeDefs(); stream.hasNext(); ) {
+ String typeDefName = stream.next().getName();
+ if (name.equals(typeDefName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected void addNonNullTypeDefNamesTo(Set<String> names) {
+ for (Iterator<JavaTypeDef> stream = this.typeDefs(); stream.hasNext(); ) {
+ String typeDefName = stream.next().getName();
+ if (typeDefName != null) {
+ names.add(typeDefName);
+ }
+ }
+ }
+
// ********** Validation ***********************************************
@Override
public void validate(List<IMessage> messages, IReporter reporter) {
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -35,5 +35,7 @@
String TYPE_CANT_BE_EMPTY = "TYPE_CANT_BE_EMPTY"; //$NON-NLS-1$
String USER_TYPE_INTERFACE = "USER_TYPE_INTERFACE"; //$NON-NLS-1$
+
+ String TYPE_CLASS_NOT_FOUND = "TYPE_CLASS_NOT_FOUND"; //$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties 2011-02-28
09:02:34 UTC (rev 29379)
@@ -7,4 +7,5 @@
UNRESOLVED_FOREIGN_KEY_NAME = Foreign key \"{0}\" not found in the table
\"{1}\".
CC_NOT_EXISTS= Console configuration \"{0}\" does not exist.
TYPE_CANT_BE_EMPTY=Type could not be empty.
-USER_TYPE_INTERFACE = Type class \"{0}\" should implement interface
\"org.hibernate.usertype.UserType\".
\ No newline at end of file
+USER_TYPE_INTERFACE = Type class \"{0}\" should implement interface
\"org.hibernate.usertype.UserType\".
+TYPE_CLASS_NOT_FOUND = Type class \"{0}\" could not be found.
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -108,4 +108,13 @@
String TYPE = PACKAGE_ + "Type"; //$NON-NLS-1$
String TYPE__TYPE = "type"; //$NON-NLS-1$
+
+ String TYPE_DEF = PACKAGE_ + "TypeDef"; //$NON-NLS-1$
+ String TYPE_DEF__NAME = "name"; //$NON-NLS-1$
+ String TYPE_DEF__DEF_FOR_TYPE = "defaultForType"; //$NON-NLS-1$
+ String TYPE_DEF__TYPE_CLASS = "typeClass"; //$NON-NLS-1$
+ String TYPE_DEF__PARAMETERS = "parameters"; //$NON-NLS-1$
+
+ String TYPE_DEFS = PACKAGE_ + "TypeDefs"; //$NON-NLS-1$
+ String TYPE_DEFS__VALUE = "value"; //$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -22,6 +22,8 @@
HibernateEntity, ForeignKeyHolder{
HibernateJavaGeneratorContainer getGeneratorContainer();
+
+ HibernateJavaTypeDefContainer getTypeDefContainer();
JavaDiscriminatorFormula getDiscriminatorFormula();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -28,6 +28,7 @@
import org.eclipse.jpt.core.jpa2.context.persistence.PersistenceUnit2_0;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.utility.Filter;
import org.eclipse.jpt.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
@@ -52,6 +53,8 @@
public class HibernateJavaEntityImpl extends AbstractJavaEntity
implements HibernateJavaEntity {
+ protected final HibernateJavaTypeDefContainer typeDefContainer;
+
protected JavaDiscriminatorFormula discriminatorFormula;
protected JavaCacheable2_0 cachable;
@@ -60,6 +63,7 @@
public HibernateJavaEntityImpl(JavaPersistentType parent) {
super(parent);
+ this.typeDefContainer = getJpaFactory().buildJavaTypeDefContainer(parent);
this.cachable = buildJavaCachable();
}
@@ -70,6 +74,7 @@
@Override
public void initialize(JavaResourcePersistentType resourcePersistentType) {
super.initialize(resourcePersistentType);
+ this.typeDefContainer.initialize(resourcePersistentType);
this.initializeDiscriminatorFormula();
this.initializeForeignKey();
}
@@ -77,6 +82,7 @@
@Override
public void update(JavaResourcePersistentType resourcePersistentType) {
super.update(resourcePersistentType);
+ this.typeDefContainer.update(resourcePersistentType);
this.updateDiscriminatorFormula();
this.updateForeignKey();
}
@@ -90,15 +96,21 @@
return (HibernateJpaProject) super.getJpaProject();
}
+ public HibernateJavaTypeDefContainer getTypeDefContainer() {
+ return this.typeDefContainer;
+ }
+
protected static final String[] SUPPORTING_ANNOTATION_NAMES_ARRAY2 = new String[] {
Hibernate.GENERIC_GENERATOR,
- Hibernate.GENERIC_GENERATORS,
+ Hibernate.GENERIC_GENERATORS,
+ Hibernate.TYPE_DEF,
+ Hibernate.TYPE_DEFS,
Hibernate.NAMED_QUERY,
Hibernate.NAMED_QUERIES,
Hibernate.NAMED_NATIVE_QUERY,
Hibernate.NAMED_NATIVE_QUERIES,
Hibernate.DISCRIMINATOR_FORMULA,
- Hibernate.FOREIGN_KEY
+ Hibernate.FOREIGN_KEY,
};
protected static final Iterable<String> SUPPORTING_ANNOTATION_NAMES2 = new
ArrayIterable<String>(SUPPORTING_ANNOTATION_NAMES_ARRAY2);
@@ -262,6 +274,7 @@
@Override
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit
astRoot) {
super.validate(messages, reporter, astRoot);
+ getTypeDefContainer().validate(messages, reporter, astRoot);
this.validateForeignKey(messages, astRoot);
}
@@ -423,6 +436,23 @@
return ((PersistenceUnit2_0) getPersistenceUnit()).calculateDefaultCacheable();
}
+ /* (non-Javadoc)
+ * @see
org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity#javaCompletionProposals(int,
org.eclipse.jpt.utility.Filter, org.eclipse.jdt.core.dom.CompilationUnit)
+ */
+ @Override
+ public Iterator<String> javaCompletionProposals(int pos,
+ Filter<String> filter, CompilationUnit astRoot) {
+ Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ result = this.getTypeDefContainer().javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ return null;
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -23,5 +23,7 @@
public interface HibernateJavaIdMapping extends JavaIdMapping, IndexHolder,
HibernateIdMapping, TypeHolder {
HibernateJavaGeneratorContainer getGeneratorContainer();
+
+ HibernateJavaTypeDefContainer getTypeDefContainer();
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -10,12 +10,14 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaIdMapping;
+import org.eclipse.jpt.utility.Filter;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.jboss.tools.hibernate.jpt.core.internal.HibernateAbstractJpaFactory;
@@ -30,6 +32,8 @@
public class HibernateJavaIdMappingImpl extends AbstractJavaIdMapping
implements HibernateJavaIdMapping {
+ protected final HibernateJavaTypeDefContainer typeDefContainer;
+
protected JavaIndex index;
protected JavaType type;
@@ -39,6 +43,7 @@
*/
public HibernateJavaIdMappingImpl(JavaPersistentAttribute parent) {
super(parent);
+ this.typeDefContainer = getJpaFactory().buildJavaTypeDefContainer(parent);
}
@Override
@@ -61,6 +66,7 @@
@Override
protected void initialize() {
super.initialize();
+ this.typeDefContainer.initialize(this.getResourcePersistentAttribute());
this.initializeIndex();
this.initializeType();
}
@@ -68,6 +74,7 @@
@Override
public void update() {
super.update();
+ this.typeDefContainer.update(this.getResourcePersistentAttribute());
this.updateIndex();
this.updateType();
}
@@ -82,6 +89,10 @@
return this.getColumn().getDBColumnName();
}
+ public HibernateJavaTypeDefContainer getTypeDefContainer() {
+ return this.typeDefContainer;
+ }
+
// *** index
protected void initializeIndex() {
@@ -220,6 +231,7 @@
public void validate(List<IMessage> messages, IReporter reporter,
CompilationUnit astRoot) {
super.validate(messages, reporter, astRoot);
+ this.typeDefContainer.validate(messages, reporter, astRoot);
if (this.index != null){
this.index.validate(messages, reporter, astRoot);
}
@@ -227,5 +239,22 @@
this.type.validate(messages, reporter, astRoot);
}
}
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jpt.core.internal.context.java.AbstractJavaIdMapping#javaCompletionProposals(int,
org.eclipse.jpt.utility.Filter, org.eclipse.jdt.core.dom.CompilationUnit)
+ */
+ @Override
+ public Iterator<String> javaCompletionProposals(int pos,
+ Filter<String> filter, CompilationUnit astRoot) {
+ Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ result = this.getTypeDefContainer().javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ return null;
+ }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaParameter.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaParameter.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaParameter.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -11,6 +11,7 @@
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.JpaContextNode;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
import org.eclipse.jpt.core.utility.TextRange;
import org.jboss.tools.hibernate.jpt.core.internal.context.Parameter;
@@ -28,7 +29,7 @@
protected ParameterAnnotation resourceParameter;
- public HibernateJavaParameter(JavaGenericGenerator parent) {
+ public HibernateJavaParameter(JpaContextNode parent) {
super(parent);
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainer.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainer.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainer.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import java.util.ListIterator;
+
+import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface HibernateJavaTypeDefContainer extends JavaJpaContextNode {
+
+ //******************** typeDef *****************
+
+ String TYPE_DEFS_LIST = "typeDefs"; //$NON-NLS-1$
+
+ /**
+ * Return a list iterator of the typeDefs.
+ * This will not be null.
+ */
+ ListIterator<? extends JavaTypeDef> typeDefs();
+
+ /**
+ * Return the number of typeDefs.
+ */
+ int typeDefsSize();
+
+ /**
+ * Add a typeDef to the entity return the object representing it.
+ */
+ JavaTypeDef addTypeDef(int index);
+
+ /**
+ * Remove the typeDef at the index from the entity.
+ */
+ void removeTypeDef(int index);
+
+ /**
+ * Remove the typeDef from the entity.
+ */
+ void removeTypeDef(JavaTypeDef typeDef);
+
+ /**
+ * Move the typeDef from the source index to the target index.
+ */
+ void moveTypeDef(int targetIndex, int sourceIndex);
+
+ void initialize(JavaResourcePersistentMember jrpm);
+
+ /**
+ * Update the JavaGeneratorContainer context model object to match the
JavaResourcePersistentMember
+ * resource model object. see {@link org.eclipse.jpt.core.JpaProject#update()}
+ */
+ void update(JavaResourcePersistentMember jrpm);
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainerImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainerImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaTypeDefContainerImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.utility.Filter;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.hibernate.jpt.core.internal.HibernateAbstractJpaFactory;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefsAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateJavaTypeDefContainerImpl extends
+ AbstractJavaJpaContextNode implements HibernateJavaTypeDefContainer {
+
+ protected JavaResourcePersistentMember javaResourcePersistentMember;
+
+ protected final List<JavaTypeDef> typeDefs;
+
+ public HibernateJavaTypeDefContainerImpl(JavaJpaContextNode parent) {
+ super(parent);
+ this.typeDefs = new ArrayList<JavaTypeDef>();
+ }
+
+ public HibernateAbstractJpaFactory getJpaFactory(){
+ return (HibernateAbstractJpaFactory)super.getJpaFactory();
+ }
+
+ public void initialize(JavaResourcePersistentMember jrpm) {
+ this.javaResourcePersistentMember = jrpm;
+ this.initializeTypeDefs();
+ }
+
+ public void update(JavaResourcePersistentMember jrpm) {
+ this.javaResourcePersistentMember = jrpm;
+ this.updateTypeDefs();
+ }
+
+ public JavaTypeDef addTypeDef(int index) {
+ JavaTypeDef newTypeDef = getJpaFactory().buildJavaTypeDef(this);
+ this.typeDefs.add(index, newTypeDef);
+ TypeDefAnnotation typeDefAnnotation =
(TypeDefAnnotation)this.javaResourcePersistentMember
+ .addAnnotation(index, TypeDefAnnotation.ANNOTATION_NAME,
TypeDefsAnnotation.ANNOTATION_NAME);
+ newTypeDef.initialize(typeDefAnnotation);
+ fireItemAdded(TYPE_DEFS_LIST, index, newTypeDef);
+ return newTypeDef;
+ }
+
+ protected void addTypeDef(JavaTypeDef typeDef) {
+ this.addTypeDef(typeDefsSize(), typeDef);
+ }
+
+ protected void addTypeDef(int index, JavaTypeDef typeDef) {
+ addItemToList(index, typeDef, this.typeDefs, TYPE_DEFS_LIST);
+ }
+
+ public ListIterator<JavaTypeDef> typeDefs() {
+ return new CloneListIterator<JavaTypeDef>(typeDefs);
+ }
+
+ public int typeDefsSize() {
+ return this.typeDefs.size();
+ }
+
+ public void moveTypeDef(int targetIndex, int sourceIndex) {
+ CollectionTools.move(this.typeDefs, targetIndex, sourceIndex);
+ this.javaResourcePersistentMember.moveAnnotation(targetIndex, sourceIndex,
TypeDefsAnnotation.ANNOTATION_NAME);
+ fireItemMoved(TYPE_DEFS_LIST, targetIndex, sourceIndex);
+ }
+
+ public void removeTypeDef(int index) {
+ JavaTypeDef removedTypeDef = this.typeDefs.remove(index);
+ this.javaResourcePersistentMember.removeAnnotation(index,
TypeDefAnnotation.ANNOTATION_NAME, TypeDefsAnnotation.ANNOTATION_NAME);
+ fireItemRemoved(TYPE_DEFS_LIST, index, removedTypeDef);
+ }
+
+ public void removeTypeDef(JavaTypeDef typeDef) {
+ removeTypeDef(this.typeDefs.indexOf(typeDef));
+ }
+
+ protected void removeTypeDef_(JavaTypeDef typeDef) {
+ removeItemFromList(typeDef, this.typeDefs, TYPE_DEFS_LIST);
+ }
+
+ protected void initializeTypeDefs() {
+ for (Iterator<NestableAnnotation> stream =
this.javaResourcePersistentMember.annotations(
+ TypeDefAnnotation.ANNOTATION_NAME,
+ TypeDefsAnnotation.ANNOTATION_NAME);
+ stream.hasNext(); ) {
+ this.typeDefs.add(buildTypeDef((TypeDefAnnotation) stream.next()));
+ }
+ }
+
+ protected JavaTypeDef buildTypeDef(TypeDefAnnotation typeDefResource) {
+ JavaTypeDef typeDef = getJpaFactory().buildJavaTypeDef(this);
+ typeDef.initialize(typeDefResource);
+ return typeDef;
+ }
+
+ protected void addTypeDefsTo(ArrayList<JavaTypeDef> typeDefs) {
+ for (JavaTypeDef typeDef : typeDefs) {
+ typeDefs.add(typeDef);
+ }
+ }
+
+ protected void updateTypeDefs() {
+ ListIterator<JavaTypeDef> typeDefs = typeDefs();
+ Iterator<NestableAnnotation> resourceTypeDefs =
+ this.javaResourcePersistentMember.annotations(
+ TypeDefAnnotation.ANNOTATION_NAME,
+ TypeDefsAnnotation.ANNOTATION_NAME);
+
+ while (typeDefs.hasNext()) {
+ JavaTypeDef typeDef = typeDefs.next();
+ if (resourceTypeDefs.hasNext()) {
+ typeDef.update((TypeDefAnnotation) resourceTypeDefs.next());
+ }
+ else {
+ removeTypeDef_(typeDef);
+ }
+ }
+
+ while (resourceTypeDefs.hasNext()) {
+ addTypeDef(buildTypeDef((TypeDefAnnotation) resourceTypeDefs.next()));
+ }
+ }
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ this.validateTypeDefs(messages, reporter, astRoot);
+ }
+
+
+ protected void validateTypeDefs(List<IMessage> messages, IReporter reporter,
CompilationUnit astRoot) {
+ ListIterator<JavaTypeDef> typeDefs = typeDefs();
+ while (typeDefs.hasNext()) {
+ typeDefs.next().validate(messages, reporter, astRoot);
+ }
+ }
+
+ @Override
+ public Iterator<String> javaCompletionProposals(int pos, Filter<String>
filter,
+ CompilationUnit astRoot) {
+ Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ ListIterator<JavaTypeDef> typeDefs = typeDefs();
+ while (typeDefs.hasNext()) {
+ result = typeDefs.next()
+ .javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ public TextRange getValidationTextRange(CompilationUnit astRoot) {
+ return this.javaResourcePersistentMember.getTextRange(astRoot);
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -10,7 +10,9 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.utility.TextRange;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotation;
/**
@@ -26,5 +28,7 @@
public void initialize(TypeAnnotation typeResource);
public void update(TypeAnnotation typeResource);
+
+ public TextRange getTypeTextRange(CompilationUnit astRoot);
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDef.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDef.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDef.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import java.util.ListIterator;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Parameter;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface JavaTypeDef extends JavaJpaContextNode {
+
+ String getName();
+ void setName(String name);
+ String TYPE_DEF_NAME = "name"; //$NON-NLS-1$
+
+ // **************** defaultForType class **************************************
+
+ String getDefaultForType();
+
+ String getSpecifiedDefaultForType();
+ void setSpecifiedDefaultForType(String value);
+ String SPECIFIED_DEF_FOR_TYPE_PROPERTY = "specifiedDefaultForTypeClass";
//$NON-NLS-1$
+
+ String getDefaultDefaultForType();
+ String DEFAULT_DEF_FOR_TYPE_PROPERTY = "defaultDefaultForTypeClass";
//$NON-NLS-1$
+
+ /**
+ * If the DefaultForType class is specified, this will return it fully qualified. If
not
+ * specified, it returns the default for type class, which is always fully qualified
+ */
+ String getFullyQualifiedDefaultForType();
+ String FULLY_QUALIFIED_DEF_FOR_TYPE_PROPERTY =
"fullyQualifiedDefaultForTypeClass"; //$NON-NLS-1$
+
+
+ // **************** type class **************************************
+
+ String getTypeClass();
+
+ String getSpecifiedTypeClass();
+ void setSpecifiedTypeClass(String value);
+ String SPECIFIED_TYPE_CLASS_PROPERTY = "specifiedTypeClass"; //$NON-NLS-1$
+
+ String getDefaultTypeClass();
+ String DEFAULT_TYPE_CLASS_PROPERTY = "defaultTypeClass"; //$NON-NLS-1$
+
+ /**
+ * If the type class is specified, this will return it fully qualified. If not
+ * specified, it returns the default type class, which is always fully qualified
+ */
+ String getFullyQualifiedTypeClass();
+ String FULLY_QUALIFIED_TYPE_CLASS_PROPERTY = "fullyQualifiedTypeClass";
//$NON-NLS-1$
+
+ //************************ parameters ***********************
+
+ String PARAMETERS_LIST = "parameters"; //$NON-NLS-1$
+
+ /**
+ * Return a list iterator of the parameters. This will not be null.
+ */
+ <T extends Parameter> ListIterator<T> parameters();
+
+ /**
+ * Return the number of parameters.
+ */
+ int parametersSize();
+
+ /**
+ * Add a parameter to the generator and return the object representing it.
+ */
+ Parameter addParameter(int index);
+
+ /**
+ * Remove the parameter from the generator.
+ */
+ void removeParameter(int index);
+
+ /**
+ * Remove the parameter at the index from the query.
+ */
+ void removeParameter(Parameter queryParameter);
+
+ /**
+ * Move the parameter from the source index to the target index.
+ */
+ void moveParameter(int targetIndex, int sourceIndex);
+
+ // **************** validation *********************************************
+
+ TextRange getNameTextRange(CompilationUnit astRoot);
+
+ void initialize(TypeDefAnnotation generator);
+
+ void update(TypeDefAnnotation generator);
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDefImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDefImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaTypeDefImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,387 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.Embeddable;
+import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.PersistentType;
+import org.eclipse.jpt.core.context.TypeMapping;
+import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.jboss.tools.hibernate.jpt.core.internal.HibernateAbstractJpaFactory;
+import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Parameter;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.ParameterAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class JavaTypeDefImpl extends AbstractJavaJpaContextNode implements JavaTypeDef {
+
+ protected TypeDefAnnotation typeDefAnnotation;
+
+ protected String name;
+
+ protected String specifiedTypeClass;
+ protected String defaultTypeClass;
+ protected String fullyQualifiedTypeClass;
+ protected PersistentType resolvedTypeType;
+
+ protected String specifiedDefaultForType;
+ protected String defaultDefaultForType;
+ protected String fullyQualifiedDefaultForType;
+ protected PersistentType resolvedTargetType;
+
+ protected final List<JavaParameter> parameters;
+
+
+ public JavaTypeDefImpl(JavaJpaContextNode parent) {
+ super(parent);
+ this.parameters = new ArrayList<JavaParameter>();
+ }
+
+ public HibernatePersistenceUnit getPersistenceUnit() {
+ return (HibernatePersistenceUnit)this.getParent().getPersistenceUnit();
+ }
+
+ public void initialize(TypeDefAnnotation typeDefAnnotation) {
+ this.typeDefAnnotation = typeDefAnnotation;
+
+ this.name = typeDefAnnotation.getName();
+
+ this.defaultTypeClass = this.buildDefaultTypeClass();
+ this.specifiedTypeClass = this.getResourceTypeClass();
+ this.fullyQualifiedTypeClass = this.buildFullyQualifiedTypeClass();
+ this.resolvedTypeType = this.buildResolvedTypeType();
+
+ this.defaultDefaultForType = this.buildDefaultDefaultForType();
+ this.specifiedDefaultForType = this.getResourceDefaultForType();
+ this.fullyQualifiedDefaultForType = this.buildFullyQualifiedDefaultForType();
+ this.resolvedTargetType = this.buildResolvedTargetType();
+
+ this.initializeParameters();
+ }
+
+ public void update(TypeDefAnnotation typeDefAnnotation) {
+ this.typeDefAnnotation = typeDefAnnotation;
+
+ this.setName_(typeDefAnnotation.getName());
+
+ this.setDefaultTypeClass(this.buildDefaultTypeClass());
+ this.setSpecifiedTypeClass_(this.getResourceTypeClass());
+ this.setFullyQualifiedTypeClass(this.buildFullyQualifiedTypeClass());
+ this.resolvedTypeType = this.buildResolvedTypeType();
+
+ this.setDefaultDefaultForType(this.buildDefaultDefaultForType());
+ this.setSpecifiedDefaultForType_(this.getResourceDefaultForType());
+ this.setFullyQualifiedDefaultForType(this.buildFullyQualifiedDefaultForType());
+ this.resolvedTargetType = this.buildResolvedTargetType();
+
+ this.updateParameters();
+
+ this.getPersistenceUnit().addTypeDef(this);
+ }
+
+ protected IMessage creatErrorMessage(String strmessage, String[] params, int lineNum){
+ IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
+ strmessage, params, getResource());
+ message.setLineNo(lineNum);
+ return message;
+ }
+
+ @Override
+ protected HibernateAbstractJpaFactory getJpaFactory() {
+ return (HibernateAbstractJpaFactory) super.getJpaFactory();
+ }
+
+ // ********** name **********
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ String old = this.name;
+ this.name = name;
+ this.typeDefAnnotation.setName(name);
+ this.firePropertyChanged(TYPE_DEF_NAME, old, name);
+ }
+
+ protected void setName_(String name) {
+ String old = this.name;
+ this.name = name;
+ this.firePropertyChanged(TYPE_DEF_NAME, old, name);
+ }
+
+
+ // ********** type class **********
+
+ public String getTypeClass() {
+ return (this.specifiedTypeClass != null) ? this.specifiedTypeClass :
this.defaultTypeClass;
+ }
+
+ public String getSpecifiedTypeClass() {
+ return this.specifiedTypeClass;
+ }
+
+ public void setSpecifiedTypeClass(String typeClass) {
+ String old = this.specifiedTypeClass;
+ this.specifiedTypeClass = typeClass;
+ this.typeDefAnnotation.setTypeClass(typeClass);
+ this.firePropertyChanged(SPECIFIED_TYPE_CLASS_PROPERTY, old, typeClass);
+ }
+
+ protected void setSpecifiedTypeClass_(String typeClass) {
+ String old = this.specifiedTypeClass;
+ this.specifiedTypeClass = typeClass;
+ this.firePropertyChanged(SPECIFIED_TYPE_CLASS_PROPERTY, old, typeClass);
+ }
+
+ protected String getResourceTypeClass() {
+ return this.typeDefAnnotation.getTypeClass();
+ }
+
+ public String getDefaultTypeClass() {
+ return this.defaultTypeClass;
+ }
+
+ protected void setDefaultTypeClass(String typeClass) {
+ String old = this.defaultTypeClass;
+ this.defaultTypeClass = typeClass;
+ this.firePropertyChanged(DEFAULT_TYPE_CLASS_PROPERTY, old, typeClass);
+ }
+
+ protected String buildDefaultTypeClass() {
+ return null;
+ }
+
+ public String getFullyQualifiedTypeClass() {
+ return this.fullyQualifiedTypeClass;
+ }
+
+ protected void setFullyQualifiedTypeClass(String typeClass) {
+ String old = this.fullyQualifiedTypeClass;
+ this.fullyQualifiedTypeClass = typeClass;
+ this.firePropertyChanged(FULLY_QUALIFIED_TYPE_CLASS_PROPERTY, old, typeClass);
+ }
+
+ protected String buildFullyQualifiedTypeClass() {
+ return (this.specifiedTypeClass == null) ?
+ this.defaultTypeClass :
+ this.typeDefAnnotation.getFullyQualifiedTypeClassName();
+ }
+
+ public PersistentType getResolvedTypeType() {
+ return this.resolvedTypeType;
+ }
+
+ protected PersistentType buildResolvedTypeType() {
+ return (this.fullyQualifiedTypeClass == null) ? null :
this.getPersistenceUnit().getPersistentType(this.fullyQualifiedTypeClass);
+ }
+
+ public char getTypeClassEnclosingTypeSeparator() {
+ return '.';
+ }
+
+
+ // ********** target class **********
+
+ public String getDefaultForType() {
+ return (this.specifiedDefaultForType != null) ? this.specifiedDefaultForType :
this.defaultDefaultForType;
+ }
+
+ public String getSpecifiedDefaultForType() {
+ return this.specifiedDefaultForType;
+ }
+
+ public void setSpecifiedDefaultForType(String defaultForType) {
+ String old = this.specifiedDefaultForType;
+ this.specifiedDefaultForType = defaultForType;
+ this.typeDefAnnotation.setDefaultForType(defaultForType);
+ this.firePropertyChanged(SPECIFIED_DEF_FOR_TYPE_PROPERTY, old, defaultForType);
+ }
+
+ protected void setSpecifiedDefaultForType_(String defaultForType) {
+ String old = this.specifiedDefaultForType;
+ this.specifiedDefaultForType = defaultForType;
+ this.firePropertyChanged(SPECIFIED_DEF_FOR_TYPE_PROPERTY, old, defaultForType);
+ }
+
+ protected String getResourceDefaultForType() {
+ return this.typeDefAnnotation.getDefaultForType();
+ }
+
+ public String getDefaultDefaultForType() {
+ return this.defaultDefaultForType;
+ }
+
+ protected void setDefaultDefaultForType(String defaultForType) {
+ String old = this.defaultDefaultForType;
+ this.defaultDefaultForType = defaultForType;
+ this.firePropertyChanged(DEFAULT_DEF_FOR_TYPE_PROPERTY, old, defaultForType);
+ }
+
+ protected String buildDefaultDefaultForType() {
+ return void.class.getName();
+ }
+
+ public String getFullyQualifiedDefaultForType() {
+ return this.fullyQualifiedDefaultForType;
+ }
+
+ protected void setFullyQualifiedDefaultForType(String defaultForType) {
+ String old = this.fullyQualifiedDefaultForType;
+ this.fullyQualifiedDefaultForType = defaultForType;
+ this.firePropertyChanged(FULLY_QUALIFIED_DEF_FOR_TYPE_PROPERTY, old, defaultForType);
+ }
+
+ protected String buildFullyQualifiedDefaultForType() {
+ return (this.specifiedDefaultForType == null) ?
+ this.defaultDefaultForType :
+ this.typeDefAnnotation.getFullyQualifiedDefaultForTypeClassName();
+ }
+
+
+ public PersistentType getResolvedTargetType() {
+ return this.resolvedTargetType;
+ }
+
+ protected PersistentType buildResolvedTargetType() {
+ return (this.fullyQualifiedDefaultForType == null) ? null :
this.getPersistenceUnit().getPersistentType(this.fullyQualifiedDefaultForType);
+ }
+
+ protected Embeddable buildResolvedTargetEmbeddable() {
+ if (this.resolvedTargetType == null) {
+ return null;
+ }
+ TypeMapping typeMapping = this.resolvedTargetType.getMapping();
+ return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null;
+ }
+
+ protected Entity buildResolvedTargetEntity() {
+ if (this.resolvedTargetType == null) {
+ return null;
+ }
+ TypeMapping typeMapping = this.resolvedTargetType.getMapping();
+ return (typeMapping instanceof Entity) ? (Entity) typeMapping : null;
+ }
+
+
+ public char getDefaultForTypeEnclosingTypeSeparator() {
+ return '.';
+ }
+
+ //************************ parameters ***********************
+
+ public JavaParameter addParameter(int index) {
+ JavaParameter parameter = getJpaFactory().buildJavaParameter(this);
+ this.parameters.add(index, parameter);
+ this.typeDefAnnotation.addParameter(index);
+ this.fireItemAdded(JavaTypeDef.PARAMETERS_LIST, index, parameter);
+ return parameter;
+ }
+
+ protected void addParameter(int index, JavaParameter parameter) {
+ addItemToList(index, parameter, this.parameters, JavaTypeDef.PARAMETERS_LIST);
+ }
+
+ protected void addParameter(JavaParameter parameter) {
+ addParameter(this.parameters.size(), parameter);
+ }
+
+ public void removeParameter(Parameter parameter) {
+ removeParameter(this.parameters.indexOf(parameter));
+ }
+
+ public void removeParameter(int index) {
+ JavaParameter removedParameter = this.parameters.remove(index);
+ this.typeDefAnnotation.removeParameter(index);
+ fireItemRemoved(JavaTypeDef.PARAMETERS_LIST, index, removedParameter);
+ }
+
+ protected void removeParameter_(JavaParameter parameter) {
+ removeItemFromList(parameter, this.parameters, JavaTypeDef.PARAMETERS_LIST);
+ }
+
+ public void moveParameter(int targetIndex, int sourceIndex) {
+ CollectionTools.move(this.parameters, targetIndex, sourceIndex);
+ this.typeDefAnnotation.moveParameter(targetIndex, sourceIndex);
+ fireItemMoved(JavaTypeDef.PARAMETERS_LIST, targetIndex, sourceIndex);
+ }
+
+ public ListIterator<JavaParameter> parameters() {
+ return new CloneListIterator<JavaParameter>(this.parameters);
+ }
+
+ public int parametersSize() {
+ return parameters.size();
+ }
+
+ protected void initializeParameters() {
+ ListIterator<ParameterAnnotation> resourceParameters =
this.typeDefAnnotation.parameters();
+
+ while(resourceParameters.hasNext()) {
+ this.parameters.add(createParameter(resourceParameters.next()));
+ }
+ }
+
+ protected void updateParameters() {
+ ListIterator<JavaParameter> contextParameters = parameters();
+ ListIterator<ParameterAnnotation> resourceParameters =
this.typeDefAnnotation.parameters();
+
+ while (contextParameters.hasNext()) {
+ JavaParameter parameter = contextParameters.next();
+ if (resourceParameters.hasNext()) {
+ parameter.update(resourceParameters.next());
+ }
+ else {
+ removeParameter_(parameter);
+ }
+ }
+
+ while (resourceParameters.hasNext()) {
+ addParameter(createParameter(resourceParameters.next()));
+ }
+ }
+
+ protected JavaParameter createParameter(ParameterAnnotation resourceParameter) {
+ JavaParameter parameter = getJpaFactory().buildJavaParameter(this);
+ parameter.initialize(resourceParameter);
+ return parameter;
+ }
+
+ // ********** text ranges **********
+
+ public TextRange getValidationTextRange(CompilationUnit astRoot) {
+ return this.getSelectionTextRange(astRoot);
+ }
+
+ public TextRange getSelectionTextRange(CompilationUnit astRoot) {
+ return this.typeDefAnnotation.getTextRange(astRoot);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.typeDefAnnotation.getNameTextRange(astRoot);
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -32,16 +32,28 @@
if (type == null) return false;
String[] interfaces = type.getSuperInterfaceNames();
for (String interface_ : interfaces) {
- if (interfaceName.equals(interface_))
- return true;
+ String[][] resolvedInterfaces = type.resolveType(interface_);
+ if (resolvedInterfaces != null){
+ for (String[] parts : resolvedInterfaces) {
+ String fullName = parts[0].length() > 0 ? parts[0] + '.' + parts[1] :
parts[1];
+ if (interfaceName.equals(fullName))
+ return true;
+ }
+ }
}
if (type.getSuperclassName() != null){
- IType parentType = javaProject.findType(type.getSuperclassName());
- if (parentType != null){
- if (isTypeImplementsInterface(javaProject, parentType, interfaceName)){
+ String[][] resolvedSuperClass = type.resolveType(type.getSuperclassName());
+ if (resolvedSuperClass != null){
+ String fullName = resolvedSuperClass[0][0].length() > 0 ? resolvedSuperClass[0][0]
+ '.' + resolvedSuperClass[0][1] : resolvedSuperClass[0][1];
+ if (interfaceName.equals(fullName))
return true;
+ IType parentType = javaProject.findType(fullName);
+ if (parentType != null){
+ if (isTypeImplementsInterface(javaProject, parentType, interfaceName)){
+ return true;
+ }
}
- }
+ }
}
for (String interface_ : interfaces) {
IType parentInterface = javaProject.findType(interface_);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -12,12 +12,15 @@
import java.util.List;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotation;
@@ -79,6 +82,14 @@
super.validate(messages, reporter, astRoot);
validateType(messages, reporter, astRoot);
}
+
+ public HibernatePersistenceUnit getPersistenceUnit() {
+ return (HibernatePersistenceUnit) this.getParent().getPersistenceUnit();
+ }
+
+ public TextRange getTypeTextRange(CompilationUnit astRoot) {
+ return this.typeResource.getTypeTextRange(astRoot);
+ }
/**
* @param messages
@@ -87,33 +98,35 @@
*/
protected void validateType(List<IMessage> messages, IReporter reporter,
CompilationUnit astRoot) {
- //TODO implement TypeDefs first as type could be a TypeDef
- /*if (type != null) {
- int lineNum = getValidationTextRange(astRoot) == null ? 0 :
getValidationTextRange(astRoot).getLineNumber();
+ //TODO implement TypeDefs package-level support
+ if (type != null) {
+ TextRange range = getTypeTextRange(astRoot) == null ? TextRange.Empty.instance() :
getTypeTextRange(astRoot);
if (type.trim().length() == 0) {
- messages.add(creatErrorMessage(TYPE_CANT_BE_EMPTY, new String[]{}, lineNum));
- } else if (!persistentUnit.hasTypeDef(contains(type))) {
+ messages.add(creatErrorMessage(TYPE_CANT_BE_EMPTY, new String[]{}, range));
+ } else if (!getPersistenceUnit().hasTypeDef(type)) {
IType lwType = null;
try {
lwType = getJpaProject().getJavaProject().findType(type);
if (lwType == null || !lwType.isClass()){
- messages.add(creatErrorMessage(STRATEGY_CLASS_NOT_FOUND, new String[]{type},
lineNum));
+ messages.add(creatErrorMessage(TYPE_CLASS_NOT_FOUND, new String[]{type}, range));
} else {
if (!JpaUtil.isTypeImplementsInterface(getJpaProject().getJavaProject(), lwType,
"org.hibernate.usertype.UserType")){//$NON-NLS-1$
- messages.add(creatErrorMessage(USER_TYPE_INTERFACE, new String[]{type},
lineNum));
+ messages.add(creatErrorMessage(USER_TYPE_INTERFACE, new String[]{type}, range));
}
}
} catch (JavaModelException e) {
// just ignore it!
}
}
- }*/
+ }
}
- protected IMessage creatErrorMessage(String strmessage, String[] params, int lineNum){
+ protected IMessage creatErrorMessage(String strmessage, String[] params, TextRange
range){
IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
strmessage, params, getResource());
- message.setLineNo(lineNum);
+ message.setLineNo(range.getLineNumber());
+ message.setOffset(range.getOffset());
+ message.setLength(range.getLength());
return message;
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -26,6 +26,8 @@
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.IndexAnnotationImpl.IndexAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.SourceGenericGeneratorsAnnotation.GenericGeneratorsAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotationImpl.TypeAnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefAnnotationImpl.TypeDefAnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeDefsAnnotationImpl.TypeDefsAnnotationDefinition;
/**
* @author Dmitry Geraskov
@@ -54,6 +56,8 @@
protected void addTypeAnnotationDefinitionsTo(List<AnnotationDefinition>
definitions) {
definitions.add(GenericGeneratorAnnotationDefinition.instance());
definitions.add(GenericGeneratorsAnnotationDefinition.instance());
+ definitions.add(TypeDefAnnotationDefinition.instance());
+ definitions.add(TypeDefsAnnotationDefinition.instance());
definitions.add(HibernateNamedQueryAnnotationDefinition.instance());
definitions.add(HibernateNamedQueriesAnnotationDefinition.instance());
definitions.add(HibernateNamedNativeQueryAnnotationDefinition.instance());
@@ -66,6 +70,8 @@
protected void addAttributeAnnotationDefinitionsTo(List<AnnotationDefinition>
definitions) {
definitions.add(GenericGeneratorAnnotationDefinition.instance());
definitions.add(GeneratedAnnotationDefinition.instance());
+ definitions.add(TypeDefAnnotationDefinition.instance());
+ definitions.add(TypeDefsAnnotationDefinition.instance());
definitions.add(IndexAnnotationDefinition.instance());
definitions.add(TypeAnnotationDefinition.instance());
definitions.add(ForeignKeyAnnotationDefinition.instance());
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotationImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotationImpl.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotationImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -180,7 +180,7 @@
}
NestableParameterAnnotation buildParameter(int index) {
- return SourceParameterAnnotation.createGenericGeneratorParameter(this, this.member,
this.daa, index);
+ return SourceParameterAnnotation.createParameter(this, this.member, this.daa,
Hibernate.GENERIC_GENERATOR__PARAMETERS, index);
}
Iterable<NestableParameterAnnotation> nestableParameters() {
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java 2011-02-28
05:49:56 UTC (rev 29378)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -156,12 +156,12 @@
// ********** static methods **********
- public static SourceParameterAnnotation createGenericGeneratorParameter(JavaResourceNode
parent, Member member, DeclarationAnnotationAdapter genericGeneratorAdapter, int index)
{
- return new SourceParameterAnnotation(parent, member,
buildGenericGeneratorParameterAnnotationAdapter(genericGeneratorAdapter, index));
+ public static SourceParameterAnnotation createParameter(JavaResourceNode parent, Member
member, DeclarationAnnotationAdapter annotationAdapter, String elementName, int index) {
+ return new SourceParameterAnnotation(parent, member,
buildParameterAnnotationAdapter(annotationAdapter, elementName, index));
}
- private static IndexedDeclarationAnnotationAdapter
buildGenericGeneratorParameterAnnotationAdapter(DeclarationAnnotationAdapter
genericGeneratorAdapter, int index) {
- return new NestedIndexedDeclarationAnnotationAdapter(genericGeneratorAdapter,
Hibernate.GENERIC_GENERATOR__PARAMETERS, index, Hibernate.PARAMETER);
+ private static IndexedDeclarationAnnotationAdapter
buildParameterAnnotationAdapter(DeclarationAnnotationAdapter annotationAdapter, String
elementName, int index) {
+ return new NestedIndexedDeclarationAnnotationAdapter(annotationAdapter, elementName,
index, Hibernate.PARAMETER);
}
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotation.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotation.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.resource.java;
+
+import java.util.ListIterator;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface TypeDefAnnotation extends NestableAnnotation {
+
+ String ANNOTATION_NAME = Hibernate.TYPE_DEF;
+
+ /**
+ * Corresponds to the 'name' element of the *TypeDef annotation.
+ * Return null if the element does not exist in Java.
+ */
+ String getName();
+ String NAME_PROPERTY = "name"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'name' element of the *TypeDef annotation.
+ * Set to null to remove the element. If no other elements exist
+ * the *Generator annotation will be removed as well.
+ */
+ void setName(String name);
+
+ /**
+ * Return the {@link TextRange} for the 'name' element. If the element
+ * does not exist return the {@link TextRange} for the *TypeDef annotation.
+ */
+ TextRange getNameTextRange(CompilationUnit astRoot);
+
+ /**
+ * Corresponds to the 'defaultForType' element of the *TypeDef annotation.
+ * Return null if the element does not exist in Java.
+ * Return the portion of the value preceding ".class".
+ * <pre>
+ * @TypeDef(defaultForType=Employee.class)
+ * </pre>
+ * will return "Employee"
+ */
+ String getDefaultForType();
+ String DEF_FOR_TYPE_PROPERTY = "defaultForType"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'defaultForType' element of the *TypeDef annotation.
+ * Set to null to remove the element.
+ */
+ void setDefaultForType(String defaultForType);
+
+ /**
+ * Return the {@link TextRange} for the 'defaultForType' element. If the element
+ * does not exist return the {@link TextRange} for the element collection annotation.
+ */
+ TextRange getDefaultForTypeTextRange(CompilationUnit astRoot);
+
+ /**
+ * Return the fully-qualified default for type class name as resolved by the AST's
bindings.
+ * <pre>
+ * @TypeDef(targetClass=Employee.class)
+ * </pre>
+ * will return "model.Employee" if there is an import for model.Employee.
+ * @return
+ */
+ String getFullyQualifiedDefaultForTypeClassName();
+ String FULLY_QUALIFIED_DEFAULT_FOR_TYPE_CLASS_NAME_PROPERTY =
"fullyQualifiedDefaultForTypeClassName"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'typeClass' element of the *TypeDef annotation.
+ * Return null if the element does not exist in Java.
+ * Return the portion of the value preceding ".class".
+ * <pre>
+ * @TypeDef(typeClass=Employee.class)
+ * </pre>
+ * will return "Employee"
+ */
+ String getTypeClass();
+ String TYPE_CLASS_PROPERTY = "typeClass"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'typeClass' element of the *TypeDef annotation.
+ * Set to null to remove the element.
+ */
+ void setTypeClass(String typeClass);
+
+ /**
+ * Return the {@link TextRange} for the 'typeClass' element. If the element
+ * does not exist return the {@link TextRange} for the element collection annotation.
+ */
+ TextRange getTypeClassTextRange(CompilationUnit astRoot);
+
+
+ /**
+ * Return the fully-qualified type class name as resolved by the AST's bindings.
+ * <pre>
+ * @TypeDef(targetClass=Employee.class)
+ * </pre>
+ * will return "model.Employee" if there is an import for model.Employee.
+ * @return
+ */
+ String getFullyQualifiedTypeClassName();
+ String FULLY_QUALIFIED_TYPE_CLASS_NAME_PROPERTY =
"fullyQualifiedTypeClassName"; //$NON-NLS-1$
+
+
+ /**
+ * Return an empty iterator if the element does not exist in Java.
+ */
+ ListIterator<ParameterAnnotation> parameters();
+ String PARAMETERS_LIST = "parameters"; //$NON-NLS-1$
+
+ /**
+ * Corresponds to the 'parameters' element of the *TypeDef annotation.
+ */
+ int parametersSize();
+
+ /**
+ * Corresponds to the 'parameters' element of the *TypeDef annotation.
+ */
+ ParameterAnnotation parameterAt(int index);
+
+ /**
+ * Corresponds to the 'parameters' element of the *TypeDef annotation.
+ */
+ int indexOfParameter(ParameterAnnotation parameter);
+
+ /**
+ * Corresponds to the 'parameters' element of the *TypeDef annotation.
+ */
+ ParameterAnnotation addParameter(int index);
+
+ /**
+ * Corresponds to the 'parameters' element of the *TypeDef annotation.
+ */
+ void moveParameter(int targetIndex, int sourceIndex);
+
+ /**
+ * Corresponds to the 'parameters' element of the *TypeDef annotation.
+ */
+ void removeParameter(int index);
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotationImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotationImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefAnnotationImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,450 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.resource.java;
+
+import java.util.ListIterator;
+import java.util.Vector;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.AnnotationContainerTools;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ASTTools;
+import
org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter;
+import
org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationContainer;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.ExpressionConverter;
+import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class TypeDefAnnotationImpl extends SourceAnnotation<Member>
+ implements TypeDefAnnotation {
+
+ private static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new
SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter;
+ private final AnnotationElementAdapter<String> nameAdapter;
+ private String name;
+
+ private static final DeclarationAnnotationElementAdapter<String>
TYPE_CLASS_ADAPTER = buildTypeClassAdapter();
+ private final AnnotationElementAdapter<String> typeClassAdapter;
+ private String typeClass;
+
+ String fullyQualifiedTypeClassName;
+
+ private static final DeclarationAnnotationElementAdapter<String>
DEF_FOR_TYPE_ADAPTER = buildDefForTypeAdapter();
+ private final AnnotationElementAdapter<String> defaultForTypeAdapter;
+ private String defaultForType;
+
+ String fullyQualifiedDefaultForTypeClassName;
+
+ final Vector<NestableParameterAnnotation> parameters = new
Vector<NestableParameterAnnotation>();
+ final ParametersAnnotationContainer parametersContainer = new
ParametersAnnotationContainer();
+
+ /**
+ * @param parent
+ * @param member
+ */
+ public TypeDefAnnotationImpl(JavaResourceNode parent, Member member,
+ DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
+ super(parent, member, daa, annotationAdapter);
+ this.nameDeclarationAdapter = this.buildNameAdapter(daa);
+ this.nameAdapter = new ShortCircuitAnnotationElementAdapter<String>(member,
nameDeclarationAdapter);
+ this.typeClassAdapter = new MemberAnnotationElementAdapter<String>(member,
TYPE_CLASS_ADAPTER);
+ this.defaultForTypeAdapter = new MemberAnnotationElementAdapter<String>(member,
DEF_FOR_TYPE_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.name = this.buildName(astRoot);
+ this.typeClass = this.buildTypeClass(astRoot);
+ this.fullyQualifiedTypeClassName = this.buildFullyQualifiedTypeClassName(astRoot);
+ this.defaultForType = this.buildDefaultForType(astRoot);
+ this.fullyQualifiedDefaultForTypeClassName =
this.buildFullyQualifiedDefaultForTypeClassName(astRoot);
+ AnnotationContainerTools.initialize(this.parametersContainer, astRoot);
+ }
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ this.syncName(this.buildName(astRoot));
+ this.syncTypeClass(this.buildTypeClass(astRoot));
+ this.syncFullyQualifiedTypeClassName(this.buildFullyQualifiedTypeClassName(astRoot));
+ this.syncDefaultForType(this.buildDefaultForType(astRoot));
+ this.syncFullyQualifiedDefaultForTypeClassName(this.buildFullyQualifiedDefaultForTypeClassName(astRoot));
+ AnnotationContainerTools.synchronize(this.parametersContainer, astRoot);
+ }
+
+ // ********** TypeDefAnnotation implementation **********
+
+ // ***** name
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ if (this.attributeValueHasChanged(this.name, name)) {
+ this.name = name;
+ this.nameAdapter.setValue(name);
+ }
+ }
+
+ private void syncName(String astName) {
+ String old = this.name;
+ this.name = astName;
+ this.firePropertyChanged(NAME_PROPERTY, old, astName);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(nameDeclarationAdapter, astRoot);
+ }
+
+ protected String buildName(CompilationUnit astRoot) {
+ return this.nameAdapter.getValue(astRoot);
+ }
+
+ // ***** type class
+ public String getTypeClass() {
+ return this.typeClass;
+ }
+
+ public void setTypeClass(String typeClass) {
+ if (this.attributeValueHasChanged(this.typeClass, typeClass)) {
+ this.typeClass = typeClass;
+ this.typeClassAdapter.setValue(typeClass);
+ }
+ }
+
+ private void syncTypeClass(String astTypeClass) {
+ String old = this.typeClass;
+ this.typeClass = astTypeClass;
+ this.firePropertyChanged(TYPE_CLASS_PROPERTY, old, astTypeClass);
+ }
+
+ private String buildTypeClass(CompilationUnit astRoot) {
+ return this.typeClassAdapter.getValue(astRoot);
+ }
+
+ public TextRange getTypeClassTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(TYPE_CLASS_ADAPTER, astRoot);
+ }
+
+ // ***** fully-qualified type entity class name
+ public String getFullyQualifiedTypeClassName() {
+ return this.fullyQualifiedTypeClassName;
+ }
+
+ private void syncFullyQualifiedTypeClassName(String name) {
+ String old = this.fullyQualifiedTypeClassName;
+ this.fullyQualifiedTypeClassName = name;
+ this.firePropertyChanged(FULLY_QUALIFIED_TYPE_CLASS_NAME_PROPERTY, old, name);
+ }
+
+ private String buildFullyQualifiedTypeClassName(CompilationUnit astRoot) {
+ return (this.typeClass == null) ? null :
ASTTools.resolveFullyQualifiedName(this.typeClassAdapter.getExpression(astRoot));
+ }
+
+ // ***** default for type class
+ public String getDefaultForType() {
+ return this.defaultForType;
+ }
+
+ public void setDefaultForType(String defaultForType) {
+ if (this.attributeValueHasChanged(this.defaultForType, defaultForType)) {
+ this.defaultForType = defaultForType;
+ this.defaultForTypeAdapter.setValue(defaultForType);
+ }
+ }
+
+ private void syncDefaultForType(String astDefaultForType) {
+ String old = this.defaultForType;
+ this.defaultForType = astDefaultForType;
+ this.firePropertyChanged(DEF_FOR_TYPE_PROPERTY, old, astDefaultForType);
+ }
+
+ private String buildDefaultForType(CompilationUnit astRoot) {
+ return this.defaultForTypeAdapter.getValue(astRoot);
+ }
+
+ public TextRange getDefaultForTypeTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(DEF_FOR_TYPE_ADAPTER, astRoot);
+ }
+
+ // ***** fully-qualified default for type entity class name
+ public String getFullyQualifiedDefaultForTypeClassName() {
+ return this.fullyQualifiedDefaultForTypeClassName;
+ }
+
+ private void syncFullyQualifiedDefaultForTypeClassName(String name) {
+ String old = this.fullyQualifiedDefaultForTypeClassName;
+ this.fullyQualifiedDefaultForTypeClassName = name;
+ this.firePropertyChanged(FULLY_QUALIFIED_DEFAULT_FOR_TYPE_CLASS_NAME_PROPERTY, old,
name);
+ }
+
+ private String buildFullyQualifiedDefaultForTypeClassName(CompilationUnit astRoot) {
+ return (this.defaultForType == null) ? null :
ASTTools.resolveFullyQualifiedName(this.defaultForTypeAdapter.getExpression(astRoot));
+ }
+ //************************ parameters ***********************
+
+ public NestableParameterAnnotation addParameter(int index) {
+ return (NestableParameterAnnotation)
AnnotationContainerTools.addNestedAnnotation(index, this.parametersContainer);
+ }
+
+ NestableParameterAnnotation addParameter_() {
+ NestableParameterAnnotation parameter = this.buildParameter(this.parameters.size());
+ this.parameters.add(parameter);
+ return parameter;
+ }
+
+ NestableParameterAnnotation buildParameter(int index) {
+ return SourceParameterAnnotation.createParameter(this, this.member, this.daa,
Hibernate.TYPE_DEF__PARAMETERS, index);
+ }
+
+ Iterable<NestableParameterAnnotation> nestableParameters() {
+ return this.parameters;
+ }
+
+ void syncAddParameterAnnotation(org.eclipse.jdt.core.dom.Annotation nestedAnnotation) {
+ NestableParameterAnnotation parameter = this.addParameter_();
+ parameter.initialize((CompilationUnit) nestedAnnotation.getRoot());
+ this.fireItemAdded(PARAMETERS_LIST, parametersSize() - 1, parameter);
+ }
+
+ NestableParameterAnnotation moveParameter_(int targetIndex, int sourceIndex) {
+ return CollectionTools.move(this.parameters, targetIndex,
sourceIndex).get(targetIndex);
+ }
+
+ void parameterMoved(int targetIndex, int sourceIndex) {
+ this.fireItemMoved(PARAMETERS_LIST, targetIndex, sourceIndex);
+ }
+
+ public int indexOfParameter(ParameterAnnotation parameter) {
+ return this.parameters.indexOf(parameter);
+ }
+
+ public void moveParameter(int targetIndex, int sourceIndex) {
+ AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex,
this.parametersContainer);
+ }
+
+ public ParameterAnnotation parameterAt(int index) {
+ return this.parameters.get(index);
+ }
+
+ public ListIterator<ParameterAnnotation> parameters() {
+ return new CloneListIterator<ParameterAnnotation>(this.parameters);
+ }
+
+ public int parametersSize() {
+ return parameters.size();
+ }
+
+ public void removeParameter(int index) {
+ AnnotationContainerTools.removeNestedAnnotation(index, this.parametersContainer);
+ }
+
+ NestableParameterAnnotation removeParameter_(int index) {
+ return this.parameters.remove(index);
+ }
+
+ void parameterRemoved(int index) {
+ this.removeItemsFromList(index, this.parameters, PARAMETERS_LIST);
+ }
+
+ // ********** NestableAnnotation implementation **********
+ public void initializeFrom(NestableAnnotation oldAnnotation) {
+ TypeDefAnnotation oldTypeDef = (TypeDefAnnotation) oldAnnotation;
+ this.setName(oldTypeDef.getName());
+ this.setTypeClass(oldTypeDef.getTypeClass());
+
+ for (ParameterAnnotation oldParameter :
CollectionTools.iterable(oldTypeDef.parameters())) {
+ NestableParameterAnnotation newParameter =
this.addParameter(oldTypeDef.indexOfParameter(oldParameter));
+ newParameter.initializeFrom((NestableParameterAnnotation) oldParameter);
+ }
+ }
+
+
+ /**
+ * convenience implementation of method from NestableAnnotation interface
+ * for subclasses
+ */
+ public void moveAnnotation(int newIndex) {
+ this.getIndexedAnnotationAdapter().moveAnnotation(newIndex);
+ }
+
+ private IndexedAnnotationAdapter getIndexedAnnotationAdapter() {
+ return (IndexedAnnotationAdapter) this.annotationAdapter;
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ super.toString(sb);
+ sb.append(name);
+ }
+
+ private DeclarationAnnotationElementAdapter<String>
buildNameAdapter(DeclarationAnnotationAdapter daa) {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(daa,
Hibernate.TYPE_DEF__NAME, false);
+ }
+
+ /**
+ * adapt the AnnotationContainer interface to the override's join columns
+ */
+ class ParametersAnnotationContainer
+ implements AnnotationContainer<NestableParameterAnnotation>
+ {
+ public String getContainerAnnotationName() {
+ return TypeDefAnnotationImpl.this.getAnnotationName();
+ }
+
+ public org.eclipse.jdt.core.dom.Annotation getAstAnnotation(CompilationUnit astRoot) {
+ return TypeDefAnnotationImpl.this.getAstAnnotation(astRoot);
+ }
+
+ public String getElementName() {
+ return Hibernate.TYPE_DEF__PARAMETERS;
+ }
+
+ public String getNestedAnnotationName() {
+ return ParameterAnnotation.ANNOTATION_NAME;
+ }
+
+ public Iterable<NestableParameterAnnotation> getNestedAnnotations() {
+ return TypeDefAnnotationImpl.this.nestableParameters();
+ }
+
+ public int getNestedAnnotationsSize() {
+ return TypeDefAnnotationImpl.this.parametersSize();
+ }
+
+ public NestableParameterAnnotation addNestedAnnotation() {
+ return TypeDefAnnotationImpl.this.addParameter_();
+ }
+
+ public void syncAddNestedAnnotation(org.eclipse.jdt.core.dom.Annotation
nestedAnnotation) {
+ TypeDefAnnotationImpl.this.syncAddParameterAnnotation(nestedAnnotation);
+ }
+
+ public NestableParameterAnnotation moveNestedAnnotation(int targetIndex, int
sourceIndex) {
+ return TypeDefAnnotationImpl.this.moveParameter_(targetIndex, sourceIndex);
+ }
+
+ public NestableParameterAnnotation removeNestedAnnotation(int index) {
+ return TypeDefAnnotationImpl.this.removeParameter_(index);
+ }
+
+ public void syncRemoveNestedAnnotations(int index) {
+ TypeDefAnnotationImpl.this.parameterRemoved(index);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this);
+ }
+
+ }
+
+ public static TypeDefAnnotation createNestedTypeDef(
+ JavaResourceNode parent, Member member,
+ int index, DeclarationAnnotationAdapter attributeOverridesAdapter) {
+ IndexedDeclarationAnnotationAdapter idaa =
buildNestedHibernateDeclarationAnnotationAdapter(index, attributeOverridesAdapter);
+ IndexedAnnotationAdapter annotationAdapter = new MemberIndexedAnnotationAdapter(member,
idaa);
+ return new TypeDefAnnotationImpl(parent, member, idaa, annotationAdapter);
+ }
+
+ private static IndexedDeclarationAnnotationAdapter
buildNestedHibernateDeclarationAnnotationAdapter(int index, DeclarationAnnotationAdapter
hibernateTypeDefsAdapter) {
+ return new NestedIndexedDeclarationAnnotationAdapter(hibernateTypeDefsAdapter, index,
Hibernate.TYPE_DEF);
+ }
+
+ // ********** static methods **********
+
+ private static DeclarationAnnotationElementAdapter<String> buildTypeClassAdapter()
{
+ return buildTypeClassAdapter(DECLARATION_ANNOTATION_ADAPTER,
Hibernate.TYPE_DEF__TYPE_CLASS);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String>
buildDefForTypeAdapter() {
+ return buildTypeClassAdapter(DECLARATION_ANNOTATION_ADAPTER,
Hibernate.TYPE_DEF__DEF_FOR_TYPE);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String>
buildTypeClassAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName)
{
+ // TODO what about QualifiedType?
+ return buildAnnotationElementAdapter(annotationAdapter, elementName,
SimpleTypeStringExpressionConverter.instance());
+ }
+
+ private static DeclarationAnnotationElementAdapter<String>
buildAnnotationElementAdapter(DeclarationAnnotationAdapter annotationAdapter, String
elementName, ExpressionConverter<String> converter) {
+ return new
ConversionDeclarationAnnotationElementAdapter<String>(annotationAdapter,
elementName, false, converter);
+ }
+
+ public static class TypeDefAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final TypeDefAnnotationDefinition INSTANCE = new
TypeDefAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private TypeDefAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member)
{
+ return new TypeDefAnnotationImpl(parent, member,
+ DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member,
DECLARATION_ANNOTATION_ADAPTER));
+ }
+
+ public String getAnnotationName() {
+ return TypeDefAnnotation.ANNOTATION_NAME;
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember arg0,
+ IAnnotation arg1) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember arg0) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotation.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotation.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.resource.java;
+
+import org.eclipse.jpt.core.resource.java.ContainerAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface TypeDefsAnnotation extends
+ ContainerAnnotation<TypeDefAnnotation> {
+
+ String ANNOTATION_NAME = Hibernate.TYPE_DEFS;
+
+ String TYPE_DEFS_LIST = "typeDefs"; //$NON-NLS-1$
+
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotationImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotationImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeDefsAnnotationImpl.java 2011-02-28
09:02:34 UTC (rev 29379)
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.resource.java;
+
+import java.util.Vector;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.AnnotationContainerTools;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+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.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class TypeDefsAnnotationImpl extends SourceAnnotation<Member> implements
+ TypeDefsAnnotation {
+
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new
SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private final Vector<TypeDefAnnotation> typeDefs = new
Vector<TypeDefAnnotation>();
+
+
+ public TypeDefsAnnotationImpl(JavaResourceNode parent, Member member) {
+ super(parent, member, DECLARATION_ANNOTATION_ADAPTER);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ AnnotationContainerTools.initialize(this, astRoot);
+ }
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ AnnotationContainerTools.synchronize(this, astRoot);
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.typeDefs);
+ }
+
+ // ********** AnnotationContainer implementation **********
+
+ public String getContainerAnnotationName() {
+ return this.getAnnotationName();
+ }
+
+ public String getElementName() {
+ return Hibernate.TYPE_DEFS__VALUE;
+ }
+
+ public String getNestedAnnotationName() {
+ return TypeDefAnnotation.ANNOTATION_NAME;
+ }
+
+ public Iterable<TypeDefAnnotation> getNestedAnnotations() {
+ return new LiveCloneIterable<TypeDefAnnotation>(this.typeDefs);
+ }
+
+ public int getNestedAnnotationsSize() {
+ return this.typeDefs.size();
+ }
+
+ public TypeDefAnnotation addNestedAnnotation() {
+ return this.addNestedAnnotation(this.typeDefs.size());
+ }
+
+ private TypeDefAnnotation addNestedAnnotation(int index) {
+ TypeDefAnnotation typeDef = this.buildTypeDef(index);
+ this.typeDefs.add(typeDef);
+ return typeDef;
+ }
+
+ public void syncAddNestedAnnotation(org.eclipse.jdt.core.dom.Annotation astAnnotation)
{
+ int index = this.typeDefs.size();
+ TypeDefAnnotation typeDef = this.addNestedAnnotation(index);
+ typeDef.initialize((CompilationUnit) astAnnotation.getRoot());
+ this.fireItemAdded(TYPE_DEFS_LIST, index, typeDef);
+ }
+
+ private TypeDefAnnotation buildTypeDef(int index) {
+ return TypeDefAnnotationImpl.createNestedTypeDef(this, member, index, this.daa);
+ }
+
+ public TypeDefAnnotation moveNestedAnnotation(int targetIndex, int sourceIndex) {
+ return CollectionTools.move(this.typeDefs, targetIndex, sourceIndex).get(targetIndex);
+ }
+
+ public TypeDefAnnotation removeNestedAnnotation(int index) {
+ return this.typeDefs.remove(index);
+ }
+
+ public void syncRemoveNestedAnnotations(int index) {
+ this.removeItemsFromList(index, this.typeDefs, TYPE_DEFS_LIST);
+ }
+
+ public static class TypeDefsAnnotationDefinition implements AnnotationDefinition {
+
+ // singleton
+ private static final AnnotationDefinition INSTANCE = new
TypeDefsAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private TypeDefsAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member)
{
+ return new TypeDefsAnnotationImpl(parent, member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation
jdtAnnotation) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getAnnotationName() {
+ return TypeDefsAnnotation.ANNOTATION_NAME;
+ }
+
+ }
+
+}