Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2011-08-25 20:29:29 +0000
committerkmoore2011-08-25 20:29:29 +0000
commitbcfb8e678efc6ae9004a0feb73b0843114c002c2 (patch)
tree22ae1c59b74536a6d746349f513ad0c77e0b595d /jpa/plugins/org.eclipse.jpt.jpa.core
parentfb5b6fb42d48464f74691828c0ad32825e428ff9 (diff)
downloadwebtools.dali-bcfb8e678efc6ae9004a0feb73b0843114c002c2.tar.gz
webtools.dali-bcfb8e678efc6ae9004a0feb73b0843114c002c2.tar.xz
webtools.dali-bcfb8e678efc6ae9004a0feb73b0843114c002c2.zip
bug 354444 - Invalid ORM ElementCollection target-class validation with package element
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java9
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/AbstractOrmElementCollectionMapping2_0.java47
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) {

Back to the top