diff options
author | kmoore | 2010-08-24 19:26:34 +0000 |
---|---|---|
committer | kmoore | 2010-08-24 19:26:34 +0000 |
commit | 3959074e70db1f75079132e998106a68859a1e54 (patch) | |
tree | fe9c59610ac5948796b21b2c5730f767df8764a7 /jpa | |
parent | d846e24ca6f6d33a339d61cca210261a533b41f9 (diff) | |
download | webtools.dali-3959074e70db1f75079132e998106a68859a1e54.tar.gz webtools.dali-3959074e70db1f75079132e998106a68859a1e54.tar.xz webtools.dali-3959074e70db1f75079132e998106a68859a1e54.zip |
132216 - Adding entity class related validation errors
Diffstat (limited to 'jpa')
46 files changed, 1003 insertions, 160 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties index 9f6aa31ff2..f75f6c0dfe 100644 --- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties +++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties @@ -56,17 +56,22 @@ TYPE_MAPPING_ID_CLASS_ATTRIBUTE_TYPE_DOES_NOT_AGREE=The attribute matching the I ENTITY_NON_ROOT_ID_CLASS_SPECIFIED=An ID class should only be defined on the root entity or a mapped superclass ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED=A primary key attribute should only be defined on the root entity or a mapped superclass ENTITY_NO_PK=The entity has no primary key attribute defined +ENTITY_FINAL_CLASS=The java class for entity \"{0}\" is final +ENTITY_MEMBER_CLASS=The java class for entity \"{0}\" is a member type +ENTITY_CLASS_MISSING_NO_ARG_CONSTRUCTOR=The java class for entity \"{0}\" has no no-arg constructor defined +ENTITY_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR=The java class for entity \"{0}\" has a private no-arg constructor; it must be public or protected. ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE=No table should be defined for non-root entity \"{0}\" using single-table inheritance ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE=No table should be defined for abstract entity \"{0}\" using table-per-concrete-class inheritance -ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED = No discriminator value should be defined for abstract entity \"{0}\" -ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED = No discriminator value should be defined for entity \"{0}\" using table-per-concrete-class inheritance -ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED =No discriminator column should be defined for non-root entity \"{0}\" -ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED = No discriminator column should be defined for entity \"{0}\" using table-per-concrete-class inheritance +ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED=No discriminator value should be defined for abstract entity \"{0}\" +ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_VALUE_DEFINED=No discriminator value should be defined for entity \"{0}\" using table-per-concrete-class inheritance +ENTITY_NON_ROOT_DISCRIMINATOR_COLUMN_DEFINED=No discriminator column should be defined for non-root entity \"{0}\" +ENTITY_TABLE_PER_CLASS_DISCRIMINATOR_COLUMN_DEFINED=No discriminator column should be defined for entity \"{0}\" using table-per-concrete-class inheritance PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME=Unspecified name PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME=Attribute \"{0}\" in class \"{1}\" cannot be resolved PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED=Attribute \"{0}\" is inherited; referring to inherited attributes in the orm.xml may not be supported by all persistence providers PERSISTENT_ATTRIBUTE_INVALID_MAPPING=Attribute \"{0}\" has invalid mapping type in this context PERSISTENT_ATTRIBUTE_FINAL_FIELD=The java field for attribute \"{0}\" is final +PERSISTENT_ATTRIBUTE_FINAL_GETTER=The get method for attribute \"{0}\" is final PERSISTENT_ATTRIBUTE_PUBLIC_FIELD=The java field for attribute \"{0}\" is public MAPPING_UNRESOLVED_MAPPED_BY=In {0}, the "mapped by" value ''{1}'' cannot be resolved to an attribute on the target entity. MAPPING_INVALID_MAPPED_BY=In {0}, the "mapped by" attribute ''{1}'' has an invalid mapping type for this relationship. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JptValidator.java index c4e0a6c9fe..92e96e5d77 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PrimaryKeyValidator.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/JptValidator.java @@ -14,7 +14,7 @@ import java.util.List; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; -public interface PrimaryKeyValidator +public interface JptValidator { void validate(List<IMessage> messages, IReporter reporter); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributeTextRangeResolver.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributeTextRangeResolver.java new file mode 100644 index 0000000000..d8cd272018 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/PersistentAttributeTextRangeResolver.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.context; + +import org.eclipse.jpt.core.utility.TextRange; + +/** + * Interface to resolve text ranges on persistent type mappings that can define primary keys + */ +public interface PersistentAttributeTextRangeResolver +{ + TextRange getAttributeTextRange(); +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java index 0e0f414c74..014d5f0076 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaEntity.java @@ -48,9 +48,9 @@ import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; import org.eclipse.jpt.core.context.java.JavaQueryContainer; import org.eclipse.jpt.core.context.java.JavaSecondaryTable; import org.eclipse.jpt.core.context.java.JavaTable; +import org.eclipse.jpt.core.internal.context.EntityTextRangeResolver; import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.jpa1.context.GenericEntityPrimaryKeyValidator; import org.eclipse.jpt.core.internal.resource.java.NullPrimaryKeyJoinColumnAnnotation; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; @@ -903,6 +903,27 @@ public abstract class AbstractJavaEntity protected boolean isAbstract() { return this.javaResourcePersistentType.isAbstract(); } + + /** + * Return whether the type is final. + */ + protected boolean isFinal() { + return this.javaResourcePersistentType.isFinal(); + } + + /** + * Return whether the type is a top-level type. + */ + protected boolean isMember() { + return this.javaResourcePersistentType.isMemberType(); + } + + /** + * Return whether the type is static. + */ + protected boolean isStatic() { + return this.javaResourcePersistentType.isStatic(); + } public String getPrimaryKeyColumnName() { return getPrimaryKeyColumnName(this); @@ -1328,6 +1349,7 @@ public abstract class AbstractJavaEntity public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { super.validate(messages, reporter, astRoot); + validateType(messages, reporter, astRoot); validatePrimaryKey(messages, reporter, astRoot); validateTable(messages, reporter, astRoot); for (Iterator<JavaSecondaryTable> stream = this.specifiedSecondaryTables(); stream.hasNext();) { @@ -1344,14 +1366,20 @@ public abstract class AbstractJavaEntity buildPrimaryKeyValidator(astRoot).validate(messages, reporter); } - protected PrimaryKeyValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { + protected JptValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { return new GenericEntityPrimaryKeyValidator(this, buildTextRangeResolver(astRoot)); } - protected PrimaryKeyTextRangeResolver buildTextRangeResolver(CompilationUnit astRoot) { + protected EntityTextRangeResolver buildTextRangeResolver(CompilationUnit astRoot) { return new JavaEntityTextRangeResolver(this, astRoot); } + protected void validateType(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + this.buildEntityValidator(astRoot).validate(messages, reporter); + } + + protected abstract JptValidator buildEntityValidator(CompilationUnit astRoot); + protected void validateTable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { if (isAbstractTablePerClass()) { if (this.table.isResourceSpecified()) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java index 1896ae1ebc..01400a3313 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaMappedSuperclass.java @@ -16,7 +16,7 @@ import org.eclipse.jpt.core.context.java.JavaIdClassReference; import org.eclipse.jpt.core.context.java.JavaMappedSuperclass; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.jpa1.context.GenericMappedSuperclassPrimaryKeyValidator; import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; @@ -118,7 +118,7 @@ public abstract class AbstractJavaMappedSuperclass extends AbstractJavaTypeMappi buildPrimaryKeyValidator(astRoot).validate(messages, reporter); } - protected PrimaryKeyValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { + protected JptValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { return new GenericMappedSuperclassPrimaryKeyValidator(this, buildTextRangeResolver(astRoot)); // TODO - JPA 2.0 validation } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java index a4dbea281d..c222107a15 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentAttribute.java @@ -14,7 +14,6 @@ import java.util.List; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.CollectionMapping; import org.eclipse.jpt.core.context.Embeddable; @@ -23,8 +22,8 @@ import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaAttributeMappingDefinition; import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; +import org.eclipse.jpt.core.internal.context.PersistentAttributeTextRangeResolver; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.jpa2.context.MetamodelField; import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; import org.eclipse.jpt.core.jpa2.resource.java.JPA2_0; @@ -523,7 +522,7 @@ public abstract class AbstractJavaPersistentAttribute public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { super.validate(messages, reporter, astRoot); - this.validateModifiers(messages, astRoot); + this.validateAttribute(messages, reporter, astRoot); if (this.specifiedMapping != null) { this.specifiedMapping.validate(messages, reporter, astRoot); @@ -533,30 +532,14 @@ public abstract class AbstractJavaPersistentAttribute } } - - protected void validateModifiers(List<IMessage> messages, CompilationUnit astRoot) { - if (this.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - - if (this.isField()) { - if (this.isFinal()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, astRoot)); - } - if (this.isPublic()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, astRoot)); - } - } + protected void validateAttribute(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + this.buildAttibuteValidator(astRoot).validate(messages, reporter); } - protected IMessage buildAttributeMessage(String msgID, CompilationUnit astRoot) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - msgID, - new String[] {getName()}, - this, - this.getValidationTextRange(astRoot) - ); + protected abstract JptValidator buildAttibuteValidator(CompilationUnit astRoot); + + protected PersistentAttributeTextRangeResolver buildTextRangeResolver(CompilationUnit astRoot) { + return new JavaPersistentAttributeTextRangeResolver(this, astRoot); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityTextRangeResolver.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityTextRangeResolver.java index 29b3308447..944789b3fa 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityTextRangeResolver.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaEntityTextRangeResolver.java @@ -12,11 +12,11 @@ package org.eclipse.jpt.core.internal.context.java; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; +import org.eclipse.jpt.core.internal.context.EntityTextRangeResolver; import org.eclipse.jpt.core.utility.TextRange; public class JavaEntityTextRangeResolver - implements PrimaryKeyTextRangeResolver + implements EntityTextRangeResolver { private JavaEntity entity; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaPersistentAttributeTextRangeResolver.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaPersistentAttributeTextRangeResolver.java new file mode 100644 index 0000000000..4b9da4bce3 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/JavaPersistentAttributeTextRangeResolver.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.context.java; + +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.PersistentAttributeTextRangeResolver; +import org.eclipse.jpt.core.utility.TextRange; + +public class JavaPersistentAttributeTextRangeResolver + implements PersistentAttributeTextRangeResolver +{ + private JavaPersistentAttribute javaPersistentAttribute; + + private CompilationUnit astRoot; + + public JavaPersistentAttributeTextRangeResolver(JavaPersistentAttribute javaPersistentAttribute, CompilationUnit astRoot) { + this.javaPersistentAttribute = javaPersistentAttribute; + this.astRoot = astRoot; + } + + public TextRange getAttributeTextRange() { + return this.javaPersistentAttribute.getValidationTextRange(this.astRoot); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java index ed1b29ec4d..f7ec68b615 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmEntity.java @@ -60,9 +60,9 @@ import org.eclipse.jpt.core.context.orm.OrmQueryContainer; import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; import org.eclipse.jpt.core.context.orm.OrmTable; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.internal.context.EntityTextRangeResolver; import org.eclipse.jpt.core.internal.context.MappingTools; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity; import org.eclipse.jpt.core.internal.jpa1.context.GenericEntityPrimaryKeyValidator; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; @@ -1061,6 +1061,30 @@ public abstract class AbstractOrmEntity return javaResourcePersistentType == null ? false : javaResourcePersistentType.isAbstract(); } + /** + * Return whether the type is abstract, false if no java type exists. + */ + protected boolean isFinal() { + JavaResourcePersistentType javaResourcePersistentType = getJavaResourcePersistentType(); + return javaResourcePersistentType == null ? false : javaResourcePersistentType.isFinal(); + } + + /** + * Return whether the type is a top-level type. + */ + protected boolean isMember() { + JavaResourcePersistentType javaResourcePersistentType = getJavaResourcePersistentType(); + return javaResourcePersistentType == null ? false : javaResourcePersistentType.isMemberType(); + } + + /** + * Return whether the type is static. + */ + protected boolean isStatic() { + JavaResourcePersistentType javaResourcePersistentType = getJavaResourcePersistentType(); + return javaResourcePersistentType == null ? false : javaResourcePersistentType.isStatic(); + } + // public String primaryKeyColumnName() { // String pkColumnName = null; // for (Iterator<IPersistentAttribute> stream = getPersistentType().allAttributes(); stream.hasNext();) { @@ -1610,6 +1634,7 @@ public abstract class AbstractOrmEntity public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); + validateType(messages, reporter); validatePrimaryKey(messages, reporter); validateTable(messages, reporter); for (Iterator<OrmSecondaryTable> stream = this.secondaryTables(); stream.hasNext(); ) { @@ -1626,15 +1651,21 @@ public abstract class AbstractOrmEntity buildPrimaryKeyValidator().validate(messages, reporter); } - protected PrimaryKeyValidator buildPrimaryKeyValidator() { + protected JptValidator buildPrimaryKeyValidator() { return new GenericEntityPrimaryKeyValidator(this, buildTextRangeResolver()); // TODO - JPA 2.0 validation } - protected PrimaryKeyTextRangeResolver buildTextRangeResolver() { + protected EntityTextRangeResolver buildTextRangeResolver() { return new OrmEntityTextRangeResolver(this); } + protected void validateType(List<IMessage> messages, IReporter reporter) { + this.buildEntityValidator().validate(messages, reporter); + } + + protected abstract JptValidator buildEntityValidator(); + protected void validateTable(List<IMessage> messages, IReporter reporter) { if (isAbstractTablePerClass()) { if (this.table.isResourceSpecified()) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java index c129ea2f84..f8a238a3c3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMappedSuperclass.java @@ -22,7 +22,7 @@ import org.eclipse.jpt.core.context.orm.OrmIdClassReference; import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.jpa1.context.GenericMappedSuperclassPrimaryKeyValidator; import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; @@ -183,7 +183,7 @@ public abstract class AbstractOrmMappedSuperclass extends AbstractOrmTypeMapping buildPrimaryKeyValidator().validate(messages, reporter); } - protected PrimaryKeyValidator buildPrimaryKeyValidator() { + protected JptValidator buildPrimaryKeyValidator() { return new GenericMappedSuperclassPrimaryKeyValidator(this, buildTextRangeResolver()); // TODO - JPA 2.0 validation } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java index f74216de9b..995652fe54 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmPersistentAttribute.java @@ -22,6 +22,8 @@ import org.eclipse.jpt.core.context.orm.OrmAttributeMappingDefinition; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmStructureNodes; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.internal.context.PersistentAttributeTextRangeResolver; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.jpa2.context.MetamodelField; @@ -253,12 +255,11 @@ public abstract class AbstractOrmPersistentAttribute @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - this.validateAttribute(messages); - this.validateModifiers(messages); + this.validateAttribute(messages, reporter); this.attributeMapping.validate(messages, reporter); } - protected void validateAttribute(List<IMessage> messages) { + protected void validateAttribute(List<IMessage> messages, IReporter reporter) { if (this.javaPersistentAttribute == null) { messages.add( DefaultJpaValidationMessages.buildMessage( @@ -270,38 +271,16 @@ public abstract class AbstractOrmPersistentAttribute ) ); } + else { + this.buildAttibuteValidator().validate(messages, reporter); + } } - protected void validateModifiers(List<IMessage> messages) { - if (this.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { - return; - } - if (this.javaPersistentAttribute == null) { - return; - } - - if (this.javaPersistentAttribute.isField()) { - if (this.javaPersistentAttribute.isFinal()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD)); - } - if (this.javaPersistentAttribute.isPublic()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD)); - } - } else { - //TODO validation : need to have a validation message for final methods as well. - //From the JPA spec : No methods or persistent instance variables of the entity class may be final. - } + protected PersistentAttributeTextRangeResolver buildTextRangeResolver() { + return new OrmPersistentAttributeTextRangeResolver(this); } - protected IMessage buildAttributeMessage(String msgID) { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - msgID, - new String[] {this.getName()}, - this, - getValidationTextRange() - ); - } + protected abstract JptValidator buildAttibuteValidator(); public TextRange getValidationTextRange() { if (isVirtual()) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityTextRangeResolver.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityTextRangeResolver.java index 76f6fada2b..9ef18175bf 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityTextRangeResolver.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityTextRangeResolver.java @@ -11,11 +11,11 @@ package org.eclipse.jpt.core.internal.context.orm; import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; +import org.eclipse.jpt.core.internal.context.EntityTextRangeResolver; import org.eclipse.jpt.core.utility.TextRange; public class OrmEntityTextRangeResolver - implements PrimaryKeyTextRangeResolver + implements EntityTextRangeResolver { private OrmEntity entity; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmPersistentAttributeTextRangeResolver.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmPersistentAttributeTextRangeResolver.java new file mode 100644 index 0000000000..78414a97d6 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmPersistentAttributeTextRangeResolver.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.context.orm; + +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.internal.context.PersistentAttributeTextRangeResolver; +import org.eclipse.jpt.core.utility.TextRange; + +public class OrmPersistentAttributeTextRangeResolver + implements PersistentAttributeTextRangeResolver +{ + private OrmPersistentAttribute persistentAttribute; + + public OrmPersistentAttributeTextRangeResolver(OrmPersistentAttribute persistentAttribute) { + this.persistentAttribute = persistentAttribute; + } + + public TextRange getAttributeTextRange() { + return this.persistentAttribute.getValidationTextRange(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractEntityValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractEntityValidator.java new file mode 100644 index 0000000000..8e09d71718 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractEntityValidator.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa1.context; + +import java.util.List; +import org.eclipse.jpt.core.context.Entity; +import org.eclipse.jpt.core.internal.context.EntityTextRangeResolver; +import org.eclipse.jpt.core.internal.context.JptValidator; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + +public abstract class AbstractEntityValidator + implements JptValidator +{ + protected Entity entity; + + protected JavaResourcePersistentType jrpt; + + protected EntityTextRangeResolver textRangeResolver; + + + protected AbstractEntityValidator( + Entity entity, JavaResourcePersistentType jrpt, EntityTextRangeResolver textRangeResolver) { + this.entity = entity; + this.jrpt = jrpt; + this.textRangeResolver = textRangeResolver; + } + + + public void validate(List<IMessage> messages, IReporter reporter) { + this.validateType(messages); + } + + protected abstract void validateType(List<IMessage> messages); + + protected boolean isMemberType() { + if (this.jrpt == null) { + return false; + } + return this.jrpt.isMemberType(); + } + + protected boolean isStaticType() { + if (this.jrpt == null) { + return false; + } + return this.jrpt.isStatic(); + } + + protected boolean isFinalType() { + if (this.jrpt == null) { + return false; + } + return this.jrpt.isFinal(); + } + + protected boolean hasPrivateNoArgConstructor() { + if (this.jrpt == null) { + return false; + } + return this.jrpt.hasPrivateNoArgConstructor(); + } + + protected boolean hasNoArgConstructor() { + if (this.jrpt == null) { + return false; + } + return this.jrpt.hasNoArgConstructor(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractPersistentAttributeValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractPersistentAttributeValidator.java new file mode 100644 index 0000000000..32259ee98b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractPersistentAttributeValidator.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa1.context; + +import java.util.List; +import org.eclipse.jpt.core.context.PersistentAttribute; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.PersistentAttributeTextRangeResolver; +import org.eclipse.jpt.core.internal.context.JptValidator; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + +public abstract class AbstractPersistentAttributeValidator + implements JptValidator +{ + protected PersistentAttribute persistentAttribute; + + protected JavaPersistentAttribute javaPersistentAttribute; + + protected PersistentAttributeTextRangeResolver textRangeResolver; + + + protected AbstractPersistentAttributeValidator( + PersistentAttribute persistentAttribute, JavaPersistentAttribute javaPersistentAttribute, PersistentAttributeTextRangeResolver textRangeResolver) { + this.persistentAttribute = persistentAttribute; + this.javaPersistentAttribute = javaPersistentAttribute; + this.textRangeResolver = textRangeResolver; + } + + + public void validate(List<IMessage> messages, IReporter reporter) { + this.validateAttribute(messages); + } + + protected abstract void validateAttribute(List<IMessage> messages); + + protected boolean isFieldAttribute() { + if (this.javaPersistentAttribute == null) { + return false; + } + return this.javaPersistentAttribute.isField(); + } + + protected boolean isPropertyAttribute() { + if (this.javaPersistentAttribute == null) { + return false; + } + return this.javaPersistentAttribute.isProperty(); + } + + protected boolean isFinalAttribute() { + if (this.javaPersistentAttribute == null) { + return false; + } + return this.javaPersistentAttribute.isFinal(); + } + + protected boolean isPublicAttribute() { + if (this.javaPersistentAttribute == null) { + return false; + } + return this.javaPersistentAttribute.isPublic(); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java index b39e362915..90089ab050 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/AbstractPrimaryKeyValidator.java @@ -24,7 +24,7 @@ import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.internal.context.PrimaryKeyTextRangeResolver; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.jpa2.context.SingleRelationshipMapping2_0; @@ -39,7 +39,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractPrimaryKeyValidator - implements PrimaryKeyValidator + implements JptValidator { private TypeMapping typeMapping; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityValidator.java new file mode 100644 index 0000000000..67bffd3085 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericEntityValidator.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa1.context; + +import java.util.List; +import org.eclipse.jpt.core.context.Entity; +import org.eclipse.jpt.core.internal.context.EntityTextRangeResolver; +import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; + +public class GenericEntityValidator + extends AbstractEntityValidator +{ + public GenericEntityValidator(Entity entity, JavaResourcePersistentType jrpt, EntityTextRangeResolver textRangeResolver) { + super(entity, jrpt, textRangeResolver); + } + + @Override + protected void validateType(List<IMessage> messages) { + if (this.isFinalType()) { + messages.add(this.buildTypeMessage(JpaValidationMessages.ENTITY_FINAL_CLASS)); + } + if (this.isMemberType()) { + messages.add(this.buildTypeMessage(JpaValidationMessages.ENTITY_MEMBER_CLASS)); + } + if (this.hasNoArgConstructor()) { + if (this.hasPrivateNoArgConstructor()) { + messages.add(this.buildTypeMessage(JpaValidationMessages.ENTITY_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR)); + } + } + else { + messages.add(this.buildTypeMessage(JpaValidationMessages.ENTITY_CLASS_MISSING_NO_ARG_CONSTRUCTOR)); + } + } + + protected IMessage buildTypeMessage(String msgID) { + return DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + msgID, + new String[] {this.entity.getName()}, + this.entity, + this.textRangeResolver.getTypeMappingTextRange() + ); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericPersistentAttributeValidator.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericPersistentAttributeValidator.java new file mode 100644 index 0000000000..2da380507a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/GenericPersistentAttributeValidator.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.core.internal.jpa1.context; + +import java.util.List; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.PersistentAttribute; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.PersistentAttributeTextRangeResolver; +import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; + +public class GenericPersistentAttributeValidator + extends AbstractPersistentAttributeValidator +{ + public GenericPersistentAttributeValidator( + PersistentAttribute persistentAttribute, JavaPersistentAttribute javaPersistentAttribute, PersistentAttributeTextRangeResolver textRangeResolver) + { + super(persistentAttribute, javaPersistentAttribute, textRangeResolver); + } + + @Override + protected void validateAttribute(List<IMessage> messages) { + if (this.persistentAttribute.getMappingKey() == MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY) { + return; + } + + if (this.isFieldAttribute()) { + if (this.isFinalAttribute()) { + messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD)); + } + if (this.isPublicAttribute()) { + messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD)); + } + } + else if (this.isPropertyAttribute()) { + //TODO need to check both the getter and the setter + if (this.isFinalAttribute()) { + messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_GETTER)); + } + } + } + + protected IMessage buildAttributeMessage(String msgID) { + return DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + msgID, + new String[] {this.persistentAttribute.getName()}, + this.persistentAttribute, + this.textRangeResolver.getAttributeTextRange() + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEntity.java index fed7a6e563..20ea4b7c8a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEntity.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaEntity.java @@ -9,8 +9,11 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.jpa1.context.java; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.java.JavaPersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity; +import org.eclipse.jpt.core.internal.jpa1.context.GenericEntityValidator; import org.eclipse.jpt.core.internal.jpa2.context.java.NullJavaCacheable2_0; import org.eclipse.jpt.core.jpa2.JpaFactory2_0; import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; @@ -61,4 +64,11 @@ public class GenericJavaEntity return ((PersistenceUnit2_0) getPersistenceUnit()).calculateDefaultCacheable(); } + + //********** Validation ******************************************** + + @Override + protected JptValidator buildEntityValidator(CompilationUnit astRoot) { + return new GenericEntityValidator(this, this.javaResourcePersistentType, buildTextRangeResolver(astRoot)); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentAttribute.java index 7d052c2afb..a44a3e70ff 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/java/GenericJavaPersistentAttribute.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. + * Copyright (c) 2006, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,9 +9,12 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.jpa1.context.java; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.PersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribute; +import org.eclipse.jpt.core.internal.jpa1.context.GenericPersistentAttributeValidator; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; /** @@ -39,4 +42,11 @@ public class GenericJavaPersistentAttribute throw new UnsupportedOperationException(); } + + // ********** validation ********** + + @Override + protected JptValidator buildAttibuteValidator(CompilationUnit astRoot) { + return new GenericPersistentAttributeValidator(this, this, buildTextRangeResolver(astRoot)); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEntity.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEntity.java index 867a738828..2604582cc9 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEntity.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmEntity.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 Oracle. All rights reserved. + * Copyright (c) 2006, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,7 +10,9 @@ package org.eclipse.jpt.core.internal.jpa1.context.orm; import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEntity; +import org.eclipse.jpt.core.internal.jpa1.context.GenericEntityValidator; import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmCacheable2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmXml2_0ContextNodeFactory; @@ -53,4 +55,12 @@ public class GenericOrmEntity super.update(); getCacheable().update(); } + + + //********** Validation ******************************************** + + @Override + protected JptValidator buildEntityValidator() { + return new GenericEntityValidator(this, getJavaResourcePersistentType(), buildTextRangeResolver()); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentAttribute.java index 076d2c428c..05f6aeda7d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa1/context/orm/GenericOrmPersistentAttribute.java @@ -14,11 +14,14 @@ import java.util.List; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmPersistentAttribute; +import org.eclipse.jpt.core.internal.jpa1.context.GenericPersistentAttributeValidator; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; public class GenericOrmPersistentAttribute extends AbstractOrmPersistentAttribute @@ -42,8 +45,8 @@ public class GenericOrmPersistentAttribute extends AbstractOrmPersistentAttribut } @Override - protected void validateAttribute(List<IMessage> messages) { - super.validateAttribute(messages); + protected void validateAttribute(List<IMessage> messages, IReporter reporter) { + super.validateAttribute(messages, reporter); if (this.javaPersistentAttribute != null) { JavaPersistentType javaPersistentType = getOwningPersistentType().getJavaPersistentType(); if (javaPersistentType != null && javaPersistentType.getAttributeNamed(this.javaPersistentAttribute.getName()) == null) { @@ -59,4 +62,9 @@ public class GenericOrmPersistentAttribute extends AbstractOrmPersistentAttribut } } } + + @Override + protected JptValidator buildAttibuteValidator() { + return new GenericPersistentAttributeValidator(this, getJavaPersistentAttribute(), buildTextRangeResolver()); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java index 9b979f879f..57ca824b24 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/java/GenericJavaPersistentAttribute2_0.java @@ -9,9 +9,12 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.jpa2.context.java; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.PersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribute; +import org.eclipse.jpt.core.internal.jpa1.context.GenericPersistentAttributeValidator; import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; import org.eclipse.jpt.core.jpa2.resource.java.Access2_0Annotation; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; @@ -65,4 +68,12 @@ public class GenericJavaPersistentAttribute2_0 super.update(); this.setSpecifiedAccess_(this.buildSpecifiedAccess()); } + + + // ********** validation ********** + + @Override + protected JptValidator buildAttibuteValidator(CompilationUnit astRoot) { + return new GenericPersistentAttributeValidator(this, this, buildTextRangeResolver(astRoot)); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0.java index c4bfc6940a..baef20f457 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/GenericOrmPersistentAttribute2_0.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. + * Copyright (c) 2009, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -11,7 +11,9 @@ package org.eclipse.jpt.core.internal.jpa2.context.orm; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmPersistentAttribute; +import org.eclipse.jpt.core.internal.jpa1.context.GenericPersistentAttributeValidator; import org.eclipse.jpt.core.resource.orm.XmlAccessHolder; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; @@ -53,5 +55,12 @@ public class GenericOrmPersistentAttribute2_0 protected AccessType getResourceAccess() { return AccessType.fromOrmResourceModel(((XmlAccessHolder) getResourceAttributeMapping()).getAccess()); } - + + + // ********** validation ********** + + @Override + protected JptValidator buildAttibuteValidator() { + return new GenericPersistentAttributeValidator(this, getJavaPersistentAttribute(), buildTextRangeResolver()); + } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java index ddf89016c4..8925e3d86e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentMember.java @@ -12,6 +12,7 @@ package org.eclipse.jpt.core.internal.resource.java.binary; import java.util.Iterator; import java.util.Vector; +import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IAnnotation; import org.eclipse.jdt.core.IMember; import org.eclipse.jdt.core.JavaModelException; @@ -45,6 +46,8 @@ abstract class BinaryPersistentMember boolean persistable; + private boolean final_; // 'final' is a reserved word + // ********** construction/initialization ********** @@ -53,6 +56,7 @@ abstract class BinaryPersistentMember this.adapter = adapter; this.initializeAnnotations(); this.persistable = this.buildPersistable(); + this.final_ = this.buildFinal(); } private void initializeAnnotations() { @@ -75,6 +79,7 @@ abstract class BinaryPersistentMember super.update(); this.updateAnnotations(); this.setPersistable(this.buildPersistable()); + this.setFinal(this.buildFinal()); } // TODO @@ -153,6 +158,27 @@ abstract class BinaryPersistentMember return this.adapter.isPersistable(); } + // ***** final + public boolean isFinal() { + return this.final_; + } + + private void setFinal(boolean final_) { + boolean old = this.final_; + this.final_ = final_; + this.firePropertyChanged(FINAL_PROPERTY, old, final_); + } + + private boolean buildFinal() { + try { + return Flags.isFinal(this.getMember().getFlags()); + } catch (JavaModelException ex) { + JptCorePlugin.log(ex); + return false; + } + } + + public boolean isAnnotated() { return ! this.annotations.isEmpty(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java index 2100f5364c..22ffc19866 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/binary/BinaryPersistentType.java @@ -55,6 +55,14 @@ final class BinaryPersistentType private boolean abstract_; // 'abstract' is a reserved word + private boolean static_; // 'static' is a reserved word + + private boolean memberType; + + private boolean hasPrivateNoArgConstructor; + + private boolean hasNoArgConstructor; + private final Vector<JavaResourcePersistentAttribute> fields; private final Vector<JavaResourcePersistentAttribute> methods; @@ -72,6 +80,10 @@ final class BinaryPersistentType this.superclassQualifiedName = this.buildSuperclassQualifiedName(); this.declaringTypeName = this.buildDeclaringTypeName(); this.abstract_ = this.buildAbstract(); + this.static_ = this.buildStatic(); + this.memberType = this.buildMemberType(); + this.hasNoArgConstructor = this.buildHasNoArgConstructor(); + this.hasPrivateNoArgConstructor = this.buildHasPrivateNoArgConstructor(); this.fields = this.buildFields(); this.methods = this.buildMethods(); // need to wait until everything is built to calculate 'access' @@ -90,6 +102,10 @@ final class BinaryPersistentType this.setSuperclassQualifiedName(this.buildSuperclassQualifiedName()); this.setDeclaringTypeName(this.buildDeclaringTypeName()); this.setAbstract(this.buildAbstract()); + this.setStatic(this.buildStatic()); + this.setMemberType(this.buildMemberType()); + this.setHasNoArgConstructor(this.buildHasNoArgConstructor()); + this.setHasPrivateNoArgConstructor(this.buildHasPrivateNoArgConstructor()); this.updateFields(); this.updateMethods(); // need to wait until everything is updated to calculate 'access' @@ -241,6 +257,97 @@ final class BinaryPersistentType } } + // ***** static + public boolean isStatic() { + return this.static_; + } + + private void setStatic(boolean static_) { + boolean old = this.static_; + this.static_ = static_; + this.firePropertyChanged(STATIC_PROPERTY, old, static_); + } + + private boolean buildStatic() { + try { + return Flags.isStatic(this.getMember().getFlags()); + } catch (JavaModelException ex) { + JptCorePlugin.log(ex); + return false; + } + } + + // ***** member + public boolean isMemberType() { + return this.memberType; + } + + private void setMemberType(boolean memberType) { + boolean old = this.memberType; + this.memberType = memberType; + this.firePropertyChanged(MEMBER_TYPE_PROPERTY, old, memberType); + } + + private boolean buildMemberType() { + try { + return this.getMember().isMember(); + } catch (JavaModelException ex) { + JptCorePlugin.log(ex); + return false; + } + } + + // ***** no-arg constructor + public boolean hasNoArgConstructor() { + return this.hasNoArgConstructor; + } + + private void setHasNoArgConstructor(boolean hasNoArgConstructor) { + boolean old = this.hasNoArgConstructor; + this.hasNoArgConstructor = hasNoArgConstructor; + this.firePropertyChanged(NO_ARG_CONSTRUCTOR_PROPERTY, old, hasNoArgConstructor); + } + + private boolean buildHasNoArgConstructor() { + return this.findNoArgConstructor() != null; + } + + private IMethod findNoArgConstructor() { + try { + for (IMethod method : this.getMember().getMethods()) { + if (method.isConstructor()) { + return method; + } + } + } + catch (JavaModelException ex) { + JptCorePlugin.log(ex); + } + return null; + } + + // ***** private no-arg constructor + public boolean hasPrivateNoArgConstructor() { + return this.hasPrivateNoArgConstructor; + } + + private void setHasPrivateNoArgConstructor(boolean hasPrivateNoArgConstructor) { + boolean old = this.hasPrivateNoArgConstructor; + this.hasPrivateNoArgConstructor = hasPrivateNoArgConstructor; + this.firePropertyChanged(PRIVATE_NO_ARG_CONSTRUCTOR_PROPERTY, old, hasPrivateNoArgConstructor); + } + + private boolean buildHasPrivateNoArgConstructor() { + IMethod method = this.findNoArgConstructor(); + try { + return method != null && Flags.isPrivate(method.getFlags()); + } + catch (JavaModelException ex) { + JptCorePlugin.log(ex); + return false; + } + } + // ***** access public AccessType getAccess() { return this.access; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java index 114613bdfd..8c18ed9a4c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentMember.java @@ -19,7 +19,9 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTVisitor; import org.eclipse.jdt.core.dom.BodyDeclaration; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.IBinding; import org.eclipse.jdt.core.dom.MarkerAnnotation; +import org.eclipse.jdt.core.dom.Modifier; import org.eclipse.jdt.core.dom.NormalAnnotation; import org.eclipse.jdt.core.dom.SingleMemberAnnotation; import org.eclipse.jpt.core.internal.utility.jdt.ASTNodeTextRange; @@ -53,6 +55,8 @@ abstract class SourcePersistentMember<M extends Member> boolean persistable; + boolean final_; // 'final' is a reserved word + // ********** construction/initialization ********** @@ -64,6 +68,8 @@ abstract class SourcePersistentMember<M extends Member> public void initialize(CompilationUnit astRoot) { this.member.getBodyDeclaration(astRoot).accept(this.buildInitialAnnotationVisitor(astRoot)); this.persistable = this.buildPersistable(astRoot); + IBinding binding = this.member.getBinding(astRoot); + this.final_ = this.buildFinal(binding); } private ASTVisitor buildInitialAnnotationVisitor(CompilationUnit astRoot) { @@ -96,6 +102,8 @@ abstract class SourcePersistentMember<M extends Member> public void synchronizeWith(CompilationUnit astRoot) { this.syncAnnotations(astRoot); this.syncPersistable(this.buildPersistable(astRoot)); + IBinding binding = this.member.getBinding(astRoot); + this.syncFinal(this.buildFinal(binding)); } @@ -372,6 +380,21 @@ abstract class SourcePersistentMember<M extends Member> return this.member.isPersistable(astRoot); } + // ***** final + public boolean isFinal() { + return this.final_; + } + + private void syncFinal(boolean astFinal) { + boolean old = this.final_; + this.final_ = astFinal; + this.firePropertyChanged(FINAL_PROPERTY, old, astFinal); + } + + private boolean buildFinal(IBinding binding) { + return (binding == null) ? false : Modifier.isFinal(binding.getModifiers()); + } + // ********** miscellaneous ********** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java index 4020394f05..3dccfd2ff7 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePersistentType.java @@ -22,6 +22,7 @@ import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.IAnnotationBinding; +import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.Modifier; @@ -69,6 +70,14 @@ final class SourcePersistentType private boolean abstract_; // 'abstract' is a reserved word + private boolean static_; // 'static' is a reserved word + + private boolean memberType; + + private boolean hasPrivateNoArgConstructor; + + private boolean hasNoArgConstructor; + private final Vector<JavaResourcePersistentType> types; private final Vector<JavaResourcePersistentAttribute> fields; @@ -140,12 +149,17 @@ final class SourcePersistentType @Override public void initialize(CompilationUnit astRoot) { super.initialize(astRoot); - this.name = this.buildName(astRoot); - this.qualifiedName = this.buildQualifiedName(astRoot); - this.packageName = this.buildPackageName(astRoot); - this.superclassQualifiedName = this.buildSuperclassQualifiedName(astRoot); - this.declaringTypeName = this.buildDeclaringTypeName(astRoot); - this.abstract_ = this.buildAbstract(astRoot); + ITypeBinding binding = this.member.getBinding(astRoot); + this.name = this.buildName(binding); + this.qualifiedName = this.buildQualifiedName(binding); + this.packageName = this.buildPackageName(binding); + this.superclassQualifiedName = this.buildSuperclassQualifiedName(binding); + this.declaringTypeName = this.buildDeclaringTypeName(binding); + this.abstract_ = this.buildAbstract(binding); + this.static_ = this.buildStatic(binding); + this.memberType = this.buildMemberType(binding); + this.hasNoArgConstructor = this.buildHasNoArgConstructor(binding); + this.hasPrivateNoArgConstructor = this.buildHasPrivateNoArgConstructor(binding); this.initializeTypes(astRoot); this.initializeFields(astRoot); this.initializeMethods(astRoot); @@ -181,12 +195,17 @@ final class SourcePersistentType @Override public void synchronizeWith(CompilationUnit astRoot) { super.synchronizeWith(astRoot); - this.syncName(this.buildName(astRoot)); - this.syncQualifiedName(this.buildQualifiedName(astRoot)); - this.syncPackageName(this.buildPackageName(astRoot)); - this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(astRoot)); - this.syncDeclaringTypeName(this.buildDeclaringTypeName(astRoot)); - this.syncAbstract(this.buildAbstract(astRoot)); + ITypeBinding binding = this.member.getBinding(astRoot); + this.syncName(this.buildName(binding)); + this.syncQualifiedName(this.buildQualifiedName(binding)); + this.syncPackageName(this.buildPackageName(binding)); + this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(binding)); + this.syncDeclaringTypeName(this.buildDeclaringTypeName(binding)); + this.syncAbstract(this.buildAbstract(binding)); + this.syncStatic(this.buildStatic(binding)); + this.syncMemberType(this.buildMemberType(binding)); + this.syncHasNoArgConstructor(this.buildHasNoArgConstructor(binding)); + this.syncHasPrivateNoArgConstructor(this.buildHasPrivateNoArgConstructor(binding)); this.syncTypes(astRoot); this.syncFields(astRoot); this.syncMethods(astRoot); @@ -278,7 +297,7 @@ final class SourcePersistentType public void resolveTypes(CompilationUnit astRoot) { super.resolveTypes(astRoot); - this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(astRoot)); + this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(this.member.getBinding(astRoot))); for (JavaResourcePersistentAttribute field : this.getFields()) { field.resolveTypes(astRoot); @@ -317,8 +336,7 @@ final class SourcePersistentType this.firePropertyChanged(NAME_PROPERTY, old, astName); } - private String buildName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); + private String buildName(ITypeBinding binding) { return (binding == null) ? null : binding.getName(); } @@ -333,8 +351,7 @@ final class SourcePersistentType this.firePropertyChanged(QUALIFIED_NAME_PROPERTY, old, astQualifiedName); } - private String buildQualifiedName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); + private String buildQualifiedName(ITypeBinding binding) { return (binding == null) ? null : binding.getQualifiedName(); } @@ -349,8 +366,7 @@ final class SourcePersistentType this.firePropertyChanged(PACKAGE_NAME_PROPERTY, old, astPackageName); } - private String buildPackageName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); + private String buildPackageName(ITypeBinding binding) { return (binding == null) ? null : binding.getPackage().getName(); } @@ -365,8 +381,7 @@ final class SourcePersistentType this.firePropertyChanged(SUPERCLASS_QUALIFIED_NAME_PROPERTY, old, astSuperclassQualifiedName); } - private String buildSuperclassQualifiedName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); + private String buildSuperclassQualifiedName(ITypeBinding binding) { if (binding == null) { return null; } @@ -390,8 +405,7 @@ final class SourcePersistentType this.firePropertyChanged(DECLARING_TYPE_NAME_PROPERTY, old, astDeclaringTypeName); } - private String buildDeclaringTypeName(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); + private String buildDeclaringTypeName(ITypeBinding binding) { if (binding == null) { return null; } @@ -399,7 +413,6 @@ final class SourcePersistentType return (declaringClass == null) ? null : declaringClass.getTypeDeclaration().getQualifiedName(); } - // ***** abstract public boolean isAbstract() { return this.abstract_; @@ -411,11 +424,90 @@ final class SourcePersistentType this.firePropertyChanged(ABSTRACT_PROPERTY, old, astAbstract); } - private boolean buildAbstract(CompilationUnit astRoot) { - ITypeBinding binding = this.member.getBinding(astRoot); + private boolean buildAbstract(ITypeBinding binding) { return (binding == null) ? false : Modifier.isAbstract(binding.getModifiers()); } + // ***** static + public boolean isStatic() { + return this.static_; + } + + private void syncStatic(boolean static_) { + boolean old = this.static_; + this.static_ = static_; + this.firePropertyChanged(STATIC_PROPERTY, old, static_); + } + + private boolean buildStatic(ITypeBinding binding) { + return (binding == null) ? false : Modifier.isStatic(binding.getModifiers()); + } + + // ***** member type + public boolean isMemberType() { + return this.memberType; + } + + private void syncMemberType(boolean memberType) { + boolean old = this.memberType; + this.memberType = memberType; + this.firePropertyChanged(MEMBER_TYPE_PROPERTY, old, memberType); + } + + private boolean buildMemberType(ITypeBinding binding) { + return (binding == null) ? false : binding.isMember(); + } + + // ***** no-arg constructor + public boolean hasNoArgConstructor() { + return this.hasNoArgConstructor; + } + + private void syncHasNoArgConstructor(boolean hasNoArgConstructor) { + boolean old = this.hasNoArgConstructor; + this.hasNoArgConstructor = hasNoArgConstructor; + this.firePropertyChanged(NO_ARG_CONSTRUCTOR_PROPERTY, old, hasNoArgConstructor); + } + + private boolean buildHasNoArgConstructor(ITypeBinding binding) { + return (binding == null) ? false : typeHasNoArgConstructor(binding); + } + + protected static boolean typeHasNoArgConstructor(ITypeBinding binding) { + return findNoArgConstructor(binding) != null; + } + + protected static IMethodBinding findNoArgConstructor(ITypeBinding binding) { + for (IMethodBinding method : binding.getDeclaredMethods()) { + if (method.isConstructor()) { + if (method.getParameterTypes().length == 0) { + return method; + } + } + } + return null; + } + + // ***** private no-arg constructor + public boolean hasPrivateNoArgConstructor() { + return this.hasPrivateNoArgConstructor; + } + + private void syncHasPrivateNoArgConstructor(boolean hasPrivateNoArgConstructor) { + boolean old = this.hasPrivateNoArgConstructor; + this.hasPrivateNoArgConstructor = hasPrivateNoArgConstructor; + this.firePropertyChanged(PRIVATE_NO_ARG_CONSTRUCTOR_PROPERTY, old, hasPrivateNoArgConstructor); + } + + private boolean buildHasPrivateNoArgConstructor(ITypeBinding binding) { + return (binding == null) ? false : typeHasPrivateNoArgConstructor(binding); + } + + protected static boolean typeHasPrivateNoArgConstructor(ITypeBinding binding) { + IMethodBinding method = findNoArgConstructor(binding); + return method != null && Modifier.isPrivate(method.getModifiers()); + } + // ***** access public AccessType getAccess() { return this.access; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java index 73b19d863b..48b6160a31 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JPTTools.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 Oracle. All rights reserved. + * Copyright (c) 2005, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -26,8 +26,6 @@ public class JPTTools { * Return whether the specified type can be "persisted", i.e. marked as * Entity, MappedSuperclass, Embeddable */ - // TODO check for no-arg constructor (or should that just be validation?) - // TODO move other checks to validation (e.g. 'final', 'static')? public static boolean typeIsPersistable(TypeAdapter typeAdapter) { if (typeAdapter.isInterface()) { return false; @@ -50,12 +48,6 @@ public class JPTTools { if (typeAdapter.isArray()) { return false; // should never get here(?) } - int modifiers = typeAdapter.getModifiers(); - if (typeAdapter.isMember()) { - if ( ! Modifier.isStatic(modifiers)) { - return false; - } - } return true; } @@ -172,12 +164,6 @@ public class JPTTools { if (Modifier.isStatic(modifiers)) { return true; } - if (Modifier.isFinal(modifiers)) { - return true; - } - if ( ! (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers))) { - return true; - } return false; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java index a2bf501879..5e4c7d0c0d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java @@ -62,6 +62,10 @@ public interface JpaValidationMessages { public static final String ENTITY_NON_ROOT_ID_CLASS_SPECIFIED = "ENTITY_NON_ROOT_ID_CLASS_SPECIFIED"; public static final String ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED = "ENTITY_NON_ROOT_ID_ATTRIBUTE_SPECIFIED"; public static final String ENTITY_NO_PK = "ENTITY_NO_PK"; + public static final String ENTITY_FINAL_CLASS = "ENTITY_FINAL_CLASS"; + public static final String ENTITY_MEMBER_CLASS = "ENTITY_MEMBER_CLASS"; + public static final String ENTITY_CLASS_MISSING_NO_ARG_CONSTRUCTOR = "ENTITY_CLASS_MISSING_NO_ARG_CONSTRUCTOR"; + public static final String ENTITY_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR = "ENTITY_CLASS_PRIVATE_NO_ARG_CONSTRUCTOR"; public static final String ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE = "ENTITY_SINGLE_TABLE_DESCENDANT_DEFINES_TABLE"; public static final String ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE = "ENTITY_ABSTRACT_TABLE_PER_CLASS_DEFINES_TABLE"; public static final String ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED = "ENTITY_ABSTRACT_DISCRIMINATOR_VALUE_DEFINED"; @@ -72,6 +76,7 @@ public interface JpaValidationMessages { public static final String PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME = "PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME"; public static final String PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED = "PERSISTENT_ATTRIBUTE_INHERITED_ATTRIBUTES_NOT_SUPPORTED"; public static final String PERSISTENT_ATTRIBUTE_FINAL_FIELD = "PERSISTENT_ATTRIBUTE_FINAL_FIELD"; + public static final String PERSISTENT_ATTRIBUTE_FINAL_GETTER = "PERSISTENT_ATTRIBUTE_FINAL_GETTER"; public static final String PERSISTENT_ATTRIBUTE_PUBLIC_FIELD = "PERSISTENT_ATTRIBUTE_PUBLIC_FIELD"; public static final String PERSISTENT_ATTRIBUTE_INVALID_MAPPING = "PERSISTENT_ATTRIBUTE_INVALID_MAPPING"; public static final String MAPPING_UNRESOLVED_MAPPED_BY = "MAPPING_UNRESOLVED_MAPPED_BY"; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java index ca6208055c..83adbce63b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java @@ -127,6 +127,12 @@ public interface JavaResourcePersistentMember */ boolean isPersistable(); String PERSISTABLE_PROPERTY = "persistable"; //$NON-NLS-1$ + + /** + * Return whether the type is final. + */ + boolean isFinal(); + String FINAL_PROPERTY = "final"; //$NON-NLS-1$ /** * Return whether the underlying JDT member is currently annotated with any recognized diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java index fe0ed3fe7f..140da3fd7f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentType.java @@ -65,6 +65,30 @@ public interface JavaResourcePersistentType String ABSTRACT_PROPERTY = "abstract"; //$NON-NLS-1$ /** + * Return whether the type is a member type. + */ + boolean isMemberType(); + String MEMBER_TYPE_PROPERTY = "memberType"; //$NON-NLS-1$ + + /** + * Return whether the type is abstract. + */ + boolean isStatic(); + String STATIC_PROPERTY = "static"; //$NON-NLS-1$ + + /** + * Return whether the type has a no-arg constructor (private, protected, or public) + */ + boolean hasNoArgConstructor(); + String NO_ARG_CONSTRUCTOR_PROPERTY = "noArgConstructor"; //$NON-NLS-1$ + + /** + * Return whether the type has a private no-arg constructor + */ + boolean hasPrivateNoArgConstructor(); + String PRIVATE_NO_ARG_CONSTRUCTOR_PROPERTY = "privateNoArgConstructor"; //$NON-NLS-1$ + + /** * Return the type's access type ("field" or "property"). */ AccessType getAccess(); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/property_files/eclipselink_jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.core/property_files/eclipselink_jpa_validation.properties index ac6549f66e..362cd9a066 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/property_files/eclipselink_jpa_validation.properties +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/property_files/eclipselink_jpa_validation.properties @@ -16,3 +16,4 @@ PERSISTENCE_UNIT_LEGACY_ENTITY_CACHING=\"{0}\" is a legacy entity caching proper PERSISTENCE_UNIT_CACHING_PROPERTY_IGNORED=Property \"{0}\" will be ignored as shared-cache-mode is set to NONE BASIC_COLLECTION_MAPPING_DEPRECATED=The type basic-collection is deprecated BASIC_MAP_MAPPING_DEPRECATED=The type basic-map is deprecated +ENTITY_MEMBER_CLASS_NOT_STATIC=The java class for entity \"{0}\" is a non-static member type diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaValidationMessages.java index e071ee25ae..e3253e7ae7 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaValidationMessages.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaValidationMessages.java @@ -13,13 +13,13 @@ package org.eclipse.jpt.eclipselink.core.internal; public interface EclipseLinkJpaValidationMessages { public static final String BUNDLE_NAME = "eclipselink_jpa_validation"; - + public static final String CACHE_EXPIRY_AND_EXPIRY_TIME_OF_DAY_BOTH_SPECIFIED = "CACHE_EXPIRY_AND_EXPIRY_TIME_OF_DAY_BOTH_SPECIFIED"; public static final String CONVERTER_CLASS_IMPLEMENTS_CONVERTER = "CONVERTER_CLASS_IMPLEMENTS_CONVERTER"; - + public static final String CUSTOMIZER_CLASS_IMPLEMENTS_DESCRIPTOR_CUSTOMIZER = "CUSTOMIZER_CLASS_IMPLEMENTS_DESCRIPTOR_CUSTOMIZER"; - + public static final String MULTIPLE_OBJECT_VALUES_FOR_DATA_VALUE = "MULTIPLE_OBJECT_VALUES_FOR_DATA_VALUE"; public static final String PERSISTENCE_UNIT_LEGACY_ENTITY_CACHING = "PERSISTENCE_UNIT_LEGACY_ENTITY_CACHING"; @@ -29,4 +29,6 @@ public interface EclipseLinkJpaValidationMessages { public static final String BASIC_COLLECTION_MAPPING_DEPRECATED = "BASIC_COLLECTION_MAPPING_DEPRECATED"; public static final String BASIC_MAP_MAPPING_DEPRECATED = "BASIC_MAP_MAPPING_DEPRECATED"; + public static final String ENTITY_MEMBER_CLASS_NOT_STATIC = "ENTITY_MEMBER_CLASS_NOT_STATIC"; + } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java index 9300e417f4..4a6c7863ef 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkEntityImpl.java @@ -12,7 +12,7 @@ package org.eclipse.jpt.eclipselink.core.internal.context.java; import java.util.List; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity; import org.eclipse.jpt.core.jpa2.context.java.JavaCacheable2_0; import org.eclipse.jpt.core.jpa2.context.java.JavaCacheableHolder2_0; @@ -24,6 +24,7 @@ import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkCaching; import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkConverterHolder; import org.eclipse.jpt.eclipselink.core.context.java.JavaEclipseLinkEntity; import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkEntityPrimaryKeyValidator; +import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkEntityValidator; import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink; import org.eclipse.jpt.eclipselink.core.v2_0.resource.java.EclipseLinkClassExtractorAnnotation2_1; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -133,7 +134,12 @@ public class JavaEclipseLinkEntityImpl } @Override - protected PrimaryKeyValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { + protected JptValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { return new EclipseLinkEntityPrimaryKeyValidator(this, buildTextRangeResolver(astRoot)); } + + @Override + protected JptValidator buildEntityValidator(CompilationUnit astRoot) { + return new EclipseLinkEntityValidator(this, this.javaResourcePersistentType, buildTextRangeResolver(astRoot)); + } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkMappedSuperclassImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkMappedSuperclassImpl.java index 618ffadc75..92ee91c0fd 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkMappedSuperclassImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkMappedSuperclassImpl.java @@ -12,7 +12,7 @@ package org.eclipse.jpt.eclipselink.core.internal.context.java; import java.util.List; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaMappedSuperclass; import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; @@ -119,7 +119,7 @@ public class JavaEclipseLinkMappedSuperclassImpl } @Override - protected PrimaryKeyValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { + protected JptValidator buildPrimaryKeyValidator(CompilationUnit astRoot) { return new EclipseLinkMappedSuperclassPrimaryKeyValidator(this, buildTextRangeResolver(astRoot)); } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java index 465f7146d9..16206a7fbe 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/JavaEclipseLinkPersistentAttribute.java @@ -9,11 +9,14 @@ ******************************************************************************/ package org.eclipse.jpt.eclipselink.core.internal.context.java; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.PersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaPersistentAttribute; import org.eclipse.jpt.core.jpa2.context.java.JavaPersistentAttribute2_0; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkPersistentAttributeValidator; /** * EclipseLink Java persistent attribute @@ -67,4 +70,12 @@ public class JavaEclipseLinkPersistentAttribute this.typeIsContainer(interfaceName) || interfaceName.equals("org.eclipse.persistence.indirection.ValueHolderInterface"); //$NON-NLS-1$ } + + + // ********** validation ********** + + @Override + protected JptValidator buildAttibuteValidator(CompilationUnit astRoot) { + return new EclipseLinkPersistentAttributeValidator(this, this, buildTextRangeResolver(astRoot)); + } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java index e11b523afe..cbdb5f3756 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkEntityImpl.java @@ -14,7 +14,7 @@ import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jpt.core.context.orm.EntityMappings; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmEntity; import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; import org.eclipse.jpt.core.jpa2.context.orm.OrmCacheable2_0; @@ -32,6 +32,7 @@ import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkCaching; import org.eclipse.jpt.eclipselink.core.context.orm.OrmEclipseLinkEntity; import org.eclipse.jpt.eclipselink.core.internal.context.java.JavaEclipseLinkCustomizer; import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkEntityPrimaryKeyValidator; +import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkEntityValidator; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCacheHolder; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlChangeTrackingHolder; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlConvertersHolder; @@ -304,7 +305,12 @@ public class OrmEclipseLinkEntityImpl } @Override - protected PrimaryKeyValidator buildPrimaryKeyValidator() { + protected JptValidator buildPrimaryKeyValidator() { return new EclipseLinkEntityPrimaryKeyValidator(this, buildTextRangeResolver()); } + + @Override + protected JptValidator buildEntityValidator() { + return new EclipseLinkEntityValidator(this, getJavaResourcePersistentType(), buildTextRangeResolver()); + } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java index 3bb6018d09..85cbc2f97f 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkMappedSuperclassImpl.java @@ -13,7 +13,7 @@ import java.util.List; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.PrimaryKeyValidator; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmMappedSuperclass; import org.eclipse.jpt.core.jpa2.context.Cacheable2_0; import org.eclipse.jpt.core.jpa2.context.CacheableHolder2_0; @@ -212,7 +212,7 @@ public class OrmEclipseLinkMappedSuperclassImpl } @Override - protected PrimaryKeyValidator buildPrimaryKeyValidator() { + protected JptValidator buildPrimaryKeyValidator() { return new EclipseLinkMappedSuperclassPrimaryKeyValidator(this, buildTextRangeResolver()); } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkPersistentAttribute.java index bf776d3ed2..a055c157d0 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/OrmEclipseLinkPersistentAttribute.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. + * Copyright (c) 2009, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -11,8 +11,10 @@ package org.eclipse.jpt.eclipselink.core.internal.context.orm; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmPersistentAttribute; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkPersistentAttributeValidator; public class OrmEclipseLinkPersistentAttribute extends AbstractOrmPersistentAttribute @@ -35,4 +37,11 @@ public class OrmEclipseLinkPersistentAttribute extends AbstractOrmPersistentAttr throw new UnsupportedOperationException("specifiedAccess is not supported for OrmEclipseLinkPersistentAttribute"); //$NON-NLS-1$ } + + // ********** validation ********** + + @Override + protected JptValidator buildAttibuteValidator() { + return new EclipseLinkPersistentAttributeValidator(this, getJavaPersistentAttribute(), buildTextRangeResolver()); + } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityValidator.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityValidator.java new file mode 100644 index 0000000000..61677584f1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkEntityValidator.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.v1_1.context; + +import java.util.List; +import org.eclipse.jpt.core.context.Entity; +import org.eclipse.jpt.core.internal.context.EntityTextRangeResolver; +import org.eclipse.jpt.core.internal.jpa1.context.AbstractEntityValidator; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.eclipselink.core.internal.DefaultEclipseLinkJpaValidationMessages; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaValidationMessages; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; + +public class EclipseLinkEntityValidator + extends AbstractEntityValidator +{ + public EclipseLinkEntityValidator(Entity entity, JavaResourcePersistentType jrpt, EntityTextRangeResolver textRangeResolver) { + super(entity, jrpt, textRangeResolver); + } + + + @Override + protected void validateType(List<IMessage> messages) { + if (this.isMemberType() && !this.isStaticType()) { + messages.add(this.buildTypeMessage(EclipseLinkJpaValidationMessages.ENTITY_MEMBER_CLASS_NOT_STATIC)); + } + if (!this.hasNoArgConstructor()) { + messages.add(this.buildTypeMessage(JpaValidationMessages.ENTITY_CLASS_MISSING_NO_ARG_CONSTRUCTOR)); + } + } + + protected IMessage buildTypeMessage(String msgID) { + return DefaultEclipseLinkJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + msgID, + new String[] {this.entity.getName()}, + this.entity, + this.textRangeResolver.getTypeMappingTextRange() + ); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkPersistentAttributeValidator.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkPersistentAttributeValidator.java new file mode 100644 index 0000000000..684941b5a4 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/EclipseLinkPersistentAttributeValidator.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.v1_1.context; + +import java.util.List; +import org.eclipse.jpt.core.context.PersistentAttribute; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.PersistentAttributeTextRangeResolver; +import org.eclipse.jpt.core.internal.jpa1.context.AbstractPersistentAttributeValidator; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; + +public class EclipseLinkPersistentAttributeValidator + extends AbstractPersistentAttributeValidator +{ + public EclipseLinkPersistentAttributeValidator( + PersistentAttribute persistentAttribute, JavaPersistentAttribute javaPersistentAttribute, PersistentAttributeTextRangeResolver textRangeResolver) + { + super(persistentAttribute, javaPersistentAttribute, textRangeResolver); + } + + @Override + protected void validateAttribute(List<IMessage> messages) { + return; + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/orm/OrmEclipseLinkPersistentAttribute1_1.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/orm/OrmEclipseLinkPersistentAttribute1_1.java index af446f8a42..00e06a19e0 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/orm/OrmEclipseLinkPersistentAttribute1_1.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v1_1/context/orm/OrmEclipseLinkPersistentAttribute1_1.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. + * Copyright (c) 2008, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -11,7 +11,9 @@ package org.eclipse.jpt.eclipselink.core.internal.v1_1.context.orm; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.orm.AbstractOrmPersistentAttribute; +import org.eclipse.jpt.eclipselink.core.internal.v1_1.context.EclipseLinkPersistentAttributeValidator; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlAttributeMapping; @@ -57,5 +59,12 @@ public class OrmEclipseLinkPersistentAttribute1_1 protected AccessType getResourceAccess() { return AccessType.fromOrmResourceModel(getResourceAttributeMapping().getAccess()); } - + + + // ********** validation ********** + + @Override + protected JptValidator buildAttibuteValidator() { + return new EclipseLinkPersistentAttributeValidator(this, getJavaPersistentAttribute(), buildTextRangeResolver()); + } } diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java index 89dbb7472b..9ce3957c46 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java +++ b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJavaEntity.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. + * Copyright (c) 2008, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,8 +9,11 @@ ******************************************************************************/ package org.eclipse.jpt.core.tests.extension.resource; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.context.java.JavaPersistentType; +import org.eclipse.jpt.core.internal.context.JptValidator; import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity; +import org.eclipse.jpt.core.internal.jpa1.context.GenericEntityValidator; import org.eclipse.jpt.core.jpa2.context.java.JavaCacheable2_0; public class TestJavaEntity extends AbstractJavaEntity @@ -27,5 +30,10 @@ public class TestJavaEntity extends AbstractJavaEntity return false; } - + //********** Validation ******************************************** + + @Override + protected JptValidator buildEntityValidator(CompilationUnit astRoot) { + return new GenericEntityValidator(this, this.javaResourcePersistentType, buildTextRangeResolver(astRoot)); + } } diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java index 9a913bb4b5..d3e1a6e4aa 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. + * Copyright (c) 2007, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -277,18 +277,18 @@ public class JPTToolsTests extends JavaResourceModelTestCase { assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } - //int getFoo() {} - not persistable + //int getFoo() {} - persistable public void testMethodIsPersistablePropertyGetter03() throws Exception { ICompilationUnit cu = createTestTypeGetMethodWithModifier(""); MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); + assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } - //private int getFoo() {} - not persistable + //private int getFoo() {} - persistable public void testMethodIsPersistablePropertyGetter04() throws Exception { ICompilationUnit cu = createTestTypeGetMethodWithModifier("private"); MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); + assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } //public static int getFoo() {} - not persistable @@ -298,11 +298,11 @@ public class JPTToolsTests extends JavaResourceModelTestCase { assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); } - //public final int getFoo() {} - not persistable + //public final int getFoo() {} - persistable public void testMethodIsPersistablePropertyGetter06() throws Exception { ICompilationUnit cu = createTestTypeGetMethodWithModifier("public final"); MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); + assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } //public void setFoo(int foo) {} - persistable @@ -319,18 +319,18 @@ public class JPTToolsTests extends JavaResourceModelTestCase { assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } - //void setFoo(int foo) {} - not persistable + //void setFoo(int foo) {} - persistable public void testMethodIsPersistablePropertyGetter09() throws Exception { ICompilationUnit cu = createTestTypeSetMethodWithModifier(""); MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); + assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } - //private void setFoo(int foo) {} - not persistable + //private void setFoo(int foo) {} - persistable public void testMethodIsPersistablePropertyGetter10() throws Exception { ICompilationUnit cu = createTestTypeSetMethodWithModifier("private"); MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); + assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } //public static void setFoo(int foo) {} - not persistable @@ -340,11 +340,11 @@ public class JPTToolsTests extends JavaResourceModelTestCase { assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); } - //public final void setFoo(int foo) {} - not persistable + //public final void setFoo(int foo) {} - persistable public void testMethodIsPersistablePropertyGetter12() throws Exception { ICompilationUnit cu = createTestTypeSetMethodWithModifier("public final"); MethodAttribute methodAttribute = fooMethod(cu); - assertFalse(methodAttribute.isPersistable(this.buildASTRoot(cu))); + assertTrue(methodAttribute.isPersistable(this.buildASTRoot(cu))); } //public boolean isFoo() {} - persistable @@ -464,13 +464,13 @@ public class JPTToolsTests extends JavaResourceModelTestCase { assertTrue(memberType.isPersistable(astRoot)); } - //non-static member type is not persistable + //non-static member type is persistable, handled with validation public void testTypeIsPersistable7() throws Exception { ICompilationUnit cu = this.createTestTypeWithMemberTypes(); Type testType = this.testType(cu); Type memberType = this.buildType(testType, "FooNotStatic", 1, cu); CompilationUnit astRoot = this.buildASTRoot(cu); - assertFalse(memberType.isPersistable(astRoot)); + assertTrue(memberType.isPersistable(astRoot)); } //TODO still need to test typeIsPersistable() returns false for local and anonymous classes diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java index 0834e71591..a51ff80680 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. + * Copyright (c) 2007, 2010 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -783,7 +783,7 @@ public class JavaResourcePersistentTypeTests extends JavaResourceModelTestCase { ICompilationUnit cu = createTestEntityWithMemberTypes(); JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - assertEquals("only persistable types should be returned by #persistableTypes()", 1, CollectionTools.size(persistentType.persistableTypes())); + assertEquals("only persistable types should be returned by #persistableTypes()", 2, CollectionTools.size(persistentType.persistableTypes())); assertEquals("enums and interfaces should be ignored", 2, CollectionTools.size(persistentType.types())); } |