Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2011-08-25 20:29:52 +0000
committerkmoore2011-08-25 20:29:52 +0000
commitbbf1de6e8b570f688ad8e6aaccaad117d7e80c81 (patch)
tree70e19986cf6231dffbbe1b3482cad6a663283182
parent5ef5a2b951c0bc69ccad3063fdd1547d37e8e233 (diff)
downloadwebtools.dali-bbf1de6e8b570f688ad8e6aaccaad117d7e80c81.tar.gz
webtools.dali-bbf1de6e8b570f688ad8e6aaccaad117d7e80c81.tar.xz
webtools.dali-bbf1de6e8b570f688ad8e6aaccaad117d7e80c81.zip
cleaning up target-entity validation for consistency with target-class map-key-class, etc
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaRelationshipMapping.java47
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java26
2 files changed, 48 insertions, 25 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaRelationshipMapping.java
index aece5971f3..c5d376a0bc 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaRelationshipMapping.java
@@ -10,7 +10,9 @@
package org.eclipse.jpt.jpa.core.internal.context.java;
import java.util.List;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.common.core.internal.utility.JDTTools;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.Filter;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
@@ -325,27 +327,30 @@ public abstract class AbstractJavaRelationshipMapping<A extends RelationshipMapp
);
return;
}
- if (this.getResolvedTargetEntity() == null) {
- if (this.getPersistentAttribute().isVirtual()) {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY,
- new String[] {this.getName(), this.getTargetEntity()},
- this,
- this.getValidationTextRange(astRoot)
- )
- );
- } else {
- messages.add(
- DefaultJpaValidationMessages.buildMessage(
- IMessage.HIGH_SEVERITY,
- JpaValidationMessages.TARGET_ENTITY_IS_NOT_AN_ENTITY,
- new String[] {this.getTargetEntity(), this.getName()},
- this,
- this.getTargetEntityTextRange(astRoot)
- )
- );
+ IJavaProject javaProject = this.getJpaProject().getJavaProject();
+ if (JDTTools.findType(javaProject, getFullyQualifiedTargetEntity()) != null) {
+ if (this.getResolvedTargetEntity() == null) {
+ if (this.getPersistentAttribute().isVirtual()) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.VIRTUAL_ATTRIBUTE_TARGET_ENTITY_IS_NOT_AN_ENTITY,
+ new String[] {this.getName(), this.getFullyQualifiedTargetEntity()},
+ this,
+ this.getValidationTextRange(astRoot)
+ )
+ );
+ } else {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.TARGET_ENTITY_IS_NOT_AN_ENTITY,
+ new String[] {this.getFullyQualifiedTargetEntity()},
+ this,
+ this.getTargetEntityTextRange(astRoot)
+ )
+ );
+ }
}
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java
index 156abf1809..26bef62ea3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmRelationshipMapping.java
@@ -13,6 +13,7 @@ import java.util.List;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.common.core.utility.TextRange;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
@@ -351,14 +352,26 @@ public abstract class AbstractOrmRelationshipMapping<X extends AbstractXmlRelati
}
protected void validateTargetEntity(List<IMessage> messages) {
- if (this.getTargetEntity() == null) {
+ if (StringTools.stringIsEmpty(this.getTargetEntity())) {
messages.add(
DefaultJpaValidationMessages.buildMessage(
IMessage.HIGH_SEVERITY,
JpaValidationMessages.TARGET_ENTITY_NOT_DEFINED,
- new String[] {this.name},
+ EMPTY_STRING_ARRAY,
this,
- this.getValidationTextRange()
+ this.getTargetEntityTextRange()
+ )
+ );
+ return;
+ }
+ if ( ! this.targetEntityExists()) {
+ messages.add(
+ DefaultJpaValidationMessages.buildMessage(
+ IMessage.HIGH_SEVERITY,
+ JpaValidationMessages.TARGET_ENTITY_NOT_EXIST,
+ EMPTY_STRING_ARRAY,
+ this,
+ this.getTargetEntityTextRange()
)
);
return;
@@ -368,7 +381,7 @@ public abstract class AbstractOrmRelationshipMapping<X extends AbstractXmlRelati
DefaultJpaValidationMessages.buildMessage(
IMessage.HIGH_SEVERITY,
JpaValidationMessages.TARGET_ENTITY_IS_NOT_AN_ENTITY,
- new String[] {this.getTargetEntity(), this.name},
+ new String[] {this.getTargetEntity()},
this,
this.getTargetEntityTextRange()
)
@@ -376,6 +389,11 @@ public abstract class AbstractOrmRelationshipMapping<X extends AbstractXmlRelati
}
}
+ protected boolean targetEntityExists() {
+ return getEntityMappings().resolveJdtType(this.getTargetEntity()) != null;
+ }
+
+
protected TextRange getTargetEntityTextRange() {
return this.getValidationTextRange(this.xmlAttributeMapping.getTargetEntityTextRange());
}

Back to the top