diff options
author | pfullbright | 2007-05-14 20:30:58 +0000 |
---|---|---|
committer | pfullbright | 2007-05-14 20:30:58 +0000 |
commit | 18d1f88a4e6ad79b8cd02e5cab50c51038feeb62 (patch) | |
tree | 890f59543c1660284793c54a7cc5b0372afe2f69 /jpa | |
parent | 7825d87b06de7d464771e5e6fedf6b80b987c027 (diff) | |
download | webtools.dali-18d1f88a4e6ad79b8cd02e5cab50c51038feeb62.tar.gz webtools.dali-18d1f88a4e6ad79b8cd02e5cab50c51038feeb62.tar.xz webtools.dali-18d1f88a4e6ad79b8cd02e5cab50c51038feeb62.zip |
143298 - support for public and final fields
Diffstat (limited to 'jpa')
5 files changed, 90 insertions, 7 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 1837212afe..ae6ef1b93d 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 @@ -32,6 +32,8 @@ ENTITY_NO_ID=Entity \"{0}\" has no Id or EmbeddedId PERSISTENT_ATTRIBUTE_UNSPECIFIED_NAME=Unspecified name PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME=Attribute \"{0}\" in class \"{1}\" cannot be resolved 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_PUBLIC_FIELD=The java field for attribute \"{0}\" is public MAPPING_UNRESOLVED_MAPPED_BY=Cannot resolve attribute named \"{0}\" MAPPING_INVALID_MAPPED_BY=Attribute named \"{0}\" has invalid mapping for this relationship MAPPING_MAPPED_BY_WITH_JOIN_TABLE=Cannot specify join table if this attribute is mapped by another attribute diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/AttributeAnnotationTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/AttributeAnnotationTools.java index 4dbfbbb1c4..31fa4cec12 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/AttributeAnnotationTools.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jdtutility/AttributeAnnotationTools.java @@ -49,21 +49,19 @@ public class AttributeAnnotationTools { throw new RuntimeException(ex); } } - + + /** + * According to the spec, "All non-transient instance variables that are not + * annotated with the Transient annotation are persistent." + */ private static boolean fieldIsPersistable_(IField field) throws JavaModelException { int flags = field.getFlags(); if (Flags.isStatic(flags)) { return false; } - if (Flags.isPublic(flags)) { - return false; - } if (Flags.isTransient(flags)) { return false; } - if (Flags.isFinal(flags)) { - return false; - } return true; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaAttributeContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaAttributeContext.java index 1d6e348db4..c3bfbeb146 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaAttributeContext.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/JavaAttributeContext.java @@ -9,11 +9,14 @@ package org.eclipse.jpt.core.internal.platform; import java.util.List; +import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; import org.eclipse.jpt.core.internal.IPersistentType; import org.eclipse.jpt.core.internal.ITypeMapping; import org.eclipse.jpt.core.internal.content.java.IJavaAttributeMapping; +import org.eclipse.jpt.core.internal.content.java.JavaPersistentAttribute; import org.eclipse.jpt.core.internal.validation.IJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -86,9 +89,47 @@ public abstract class JavaAttributeContext extends BaseContext public void addToMessages(List<IMessage> messages) { super.addToMessages(messages); + addModifierMessages(messages); + addInvalidMappingMessage(messages); } + protected void addModifierMessages(List<IMessage> messages) { + JavaPersistentAttribute attribute = + (JavaPersistentAttribute) attributeMapping.getPersistentAttribute(); + if (attribute.getAttribute().isField()) { + int flags; + + try { + flags = attribute.getAttribute().getJdtMember().getFlags(); + } catch (JavaModelException jme) { + /* no error to log, in that case */ + return; + } + + if (Flags.isFinal(flags)) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, + new String[] {attribute.getName()}, + attribute, attribute.validationTextRange()) + ); + } + + if (Flags.isPublic(flags)) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, + new String[] {attribute.getName()}, + attribute, attribute.validationTextRange()) + ); + + } + } + } + protected void addInvalidMappingMessage(List<IMessage> messages) { IAttributeMapping attributeMapping = getMapping(); ITypeMapping typeMapping = attributeMapping.typeMapping(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlAttributeContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlAttributeContext.java index 1f8a5112dd..afb708ca0a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlAttributeContext.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/XmlAttributeContext.java @@ -9,6 +9,8 @@ package org.eclipse.jpt.core.internal.platform; import java.util.List; +import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jpt.core.internal.IAttributeMapping; import org.eclipse.jpt.core.internal.IMappingKeys; import org.eclipse.jpt.core.internal.IPersistentType; @@ -96,6 +98,7 @@ public abstract class XmlAttributeContext extends BaseContext protected void addAttributeMessages(List<IMessage> messages) { addUnspecifiedAttributeMessage(messages); addUnresolvedAttributeMessage(messages); + addModifierMessages(messages); } protected void addUnspecifiedAttributeMessage(List<IMessage> messages) { @@ -125,6 +128,41 @@ public abstract class XmlAttributeContext extends BaseContext } } + protected void addModifierMessages(List<IMessage> messages) { + XmlPersistentAttribute attribute = xmlAttributeMapping.getPersistentAttribute(); + + if (attribute.getAttribute() != null && attribute.getAttribute().isField()) { + int flags; + try { + flags = attribute.getAttribute().getJdtMember().getFlags(); + } catch (JavaModelException jme) { + /* no error to log, in that case */ + return; + } + + if (Flags.isFinal(flags)) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD, + new String[] {attribute.getName()}, + attribute, attribute.validationTextRange()) + ); + } + + if (Flags.isPublic(flags)) { + messages.add( + JpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + IJpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD, + new String[] {attribute.getName()}, + attribute, attribute.validationTextRange()) + ); + + } + } + } + protected void addInvalidMappingMessage(List<IMessage> messages) { IAttributeMapping attributeMapping = attributeMapping(); ITypeMapping typeMapping = attributeMapping.typeMapping(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java index f223d6e84a..b6fa20698c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/IJpaValidationMessages.java @@ -58,6 +58,10 @@ public interface IJpaValidationMessages public static final String PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME = "PERSISTENT_ATTRIBUTE_UNRESOLVED_NAME"; + public static final String PERSISTENT_ATTRIBUTE_FINAL_FIELD = "PERSISTENT_ATTRIBUTE_FINAL_FIELD"; + + 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"; |