diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core')
3 files changed, 58 insertions, 12 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java index 0e77913758..5d7e79ee68 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java @@ -165,6 +165,15 @@ public interface EntityMappings */ PersistentType resolvePersistentType(String className); + /** + * Return the JDT IType resource type for the specified class name + * found in the Java project. First look for one with the specified + * name (since it might be fully qualified). If not found, prepend the + * default package name and try again. + * + * @see #getPackage() + */ + IType resolveJdtType(String className); // ********** refactoring ********** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java index e9837e6ba5..c9ccff5522 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java @@ -13,8 +13,10 @@ import java.util.Comparator; import java.util.List; import java.util.Vector; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; +import org.eclipse.jpt.common.core.internal.utility.JDTTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.CollectionTools; @@ -476,6 +478,10 @@ public abstract class AbstractEntityMappings return (JavaResourceAbstractType) this.resolveType(RESOURCE_TYPE_LOOKUP_ADAPTER, className); } + public IType resolveJdtType(String className) { + return (IType) this.resolveType(JDT_TYPE_LOOKUP_ADAPTER, className); + } + protected Object resolveType(TypeLookupAdapter adapter, String className) { if (className == null) { return null; @@ -515,6 +521,14 @@ public abstract class AbstractEntityMappings } }; + protected static final TypeLookupAdapter JDT_TYPE_LOOKUP_ADAPTER = + new TypeLookupAdapter() { + public Object resolveType(EntityMappings entityMappings, String className) { + IJavaProject javaProject = entityMappings.getJpaProject().getJavaProject(); + return JDTTools.findType(javaProject, className); + } + }; + /** * We have to calculate the new persistent type's index. * We will use the type's short name if the entity mappings's diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java index 6f51f64c73..effcfd80c6 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java @@ -1450,40 +1450,37 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen } protected void validateTargetClass(List<IMessage> messages) { - String targetClass = this.getTargetClass(); - if (StringTools.stringIsEmpty(targetClass)) { + if (StringTools.stringIsEmpty(this.getTargetClass())) { messages.add( DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.ELEMENT_COLLECTION_TARGET_CLASS_NOT_DEFINED, EMPTY_STRING_ARRAY, this, - this.getValidationTextRange() + this.getTargetClassTextRange() ) ); return; } - - IJavaProject javaProject = this.getJpaProject().getJavaProject(); - if (JDTTools.findType(javaProject, targetClass) == null) { + if ( ! this.targetClassExists()) { messages.add( DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.ELEMENT_COLLECTION_TARGET_CLASS_DOES_NOT_EXIST, - new String[] {this.name}, + EMPTY_STRING_ARRAY, this, this.getTargetClassTextRange() ) ); return; } - - if ( ! JDTTools.typeIsBasic(javaProject, targetClass) && (this.getResolvedTargetEmbeddable() == null)) { + IJavaProject javaProject = this.getJpaProject().getJavaProject(); + if ( ! JDTTools.typeIsBasic(javaProject, this.getTargetClass()) && (this.getResolvedTargetEmbeddable() == null)) { messages.add( DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.ELEMENT_COLLECTION_TARGET_CLASS_MUST_BE_EMBEDDABLE_OR_BASIC_TYPE, - new String[] {this.getTargetClass(), this.name}, + new String[] {this.getTargetClass()}, this, this.getTargetClassTextRange() ) @@ -1491,6 +1488,10 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen } } + protected boolean targetClassExists() { + return getEntityMappings().resolveJdtType(this.getTargetClass()) != null; + } + protected TextRange getTargetClassTextRange() { return this.getValidationTextRange(this.xmlAttributeMapping.getTargetClassTextRange()); } @@ -1503,17 +1504,39 @@ public abstract class AbstractOrmElementCollectionMapping2_0<X extends XmlElemen } protected void validateMapKeyClass_(List<IMessage> messages) { - if (this.getMapKeyClass() == null) { + if (StringTools.stringIsEmpty(getMapKeyClass())) { messages.add( DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, - JpaValidationMessages.ELEMENT_COLLECTION_MAP_KEY_CLASS_NOT_DEFINED, + JpaValidationMessages.MAP_KEY_CLASS_NOT_DEFINED, EMPTY_STRING_ARRAY, this, this.getValidationTextRange() ) ); + return; } + + if ( ! this.mapKeyClassExists()) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.MAP_KEY_CLASS_NOT_EXIST, + EMPTY_STRING_ARRAY, + this, + this.getMapKeyClassTextRange() + ) + ); + return; + } + } + + protected boolean mapKeyClassExists() { + return getEntityMappings().resolveJdtType(this.getMapKeyClass()) != null; + } + + protected TextRange getMapKeyClassTextRange() { + return this.getValidationTextRange(this.xmlAttributeMapping.getMapKeyClassTextRange()); } public void validateValue(List<IMessage> messages, IReporter reporter) { |