From e6e9f03cdba80509d9b8057b5e900065212d7b87 Mon Sep 17 00:00:00 2001 From: pfullbright Date: Mon, 19 Sep 2011 20:25:00 +0000 Subject: added method signature validation to XmlElementDecl --- .../property_files/jaxb_validation.properties | 2 ++ .../java/GenericJavaElementFactoryMethod.java | 20 ++++++++++++++++++++ .../internal/validation/JaxbValidationMessages.java | 2 ++ 3 files changed, 24 insertions(+) (limited to 'jaxb/plugins/org.eclipse.jpt.jaxb.core') diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties b/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties index 36f375b2d5..827b3134dd 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/property_files/jaxb_validation.properties @@ -28,6 +28,8 @@ XML_ELEMENT_WRAPPER_DEFINED_ON_NON_ARRAY_NON_COLLECTION = An XML element wrapper XML_ELEMENT__UNSPECIFIED_TYPE = Unspecified XML element type. XML_ELEMENT__ILLEGAL_TYPE = XML element type must be a sub-type of ''{0}''. +XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_RETURN_TYPE = An element factory method must have a return type of ''javax.xml.bind.JAXBElement''. +XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_PARAM = An element factory method must have a single parameter assignable to ''java.lang.Object''. XML_ELEMENT_DECL__SUBST_HEAD_NAME_EQUALS_NAME = XML element decl substitution head must not match its XML element. XML_ELEMENT_DECL__SUBST_HEAD_NO_MATCHING_ELEMENT_DECL = XML element decl substitution head must match another XML element decl. diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaElementFactoryMethod.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaElementFactoryMethod.java index e4e5922baf..a45a23a10e 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaElementFactoryMethod.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaElementFactoryMethod.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.jaxb.core.internal.context.java; import java.util.List; import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.common.core.internal.utility.JDTTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.Filter; @@ -207,6 +208,25 @@ public class GenericJavaElementFactoryMethod super.validate(messages, reporter, astRoot); this.qName.validate(messages, reporter, astRoot); this.substitutionHeadQName.validate(messages, reporter, astRoot); + + JavaResourceMethod resourceMethod = getResourceMethod(); + if (! JAXB.JAXB_ELEMENT.equals(resourceMethod.getTypeName())) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_RETURN_TYPE, + this, + getValidationTextRange(astRoot))); + } + if (resourceMethod.getParametersSize() != 1 || + ! JDTTools.typeIsSubType(getJaxbProject().getJavaProject(), resourceMethod.getParameterTypeName(0), Object.class.getName())) { + messages.add( + DefaultValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JaxbValidationMessages.XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_PARAM, + this, + getValidationTextRange(astRoot))); + } } diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java index 41844b2fb9..1ec2e5b10a 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/validation/JaxbValidationMessages.java @@ -47,6 +47,8 @@ public interface JaxbValidationMessages { String XML_ELEMENT__UNSPECIFIED_TYPE = "XML_ELEMENT__UNSPECIFIED_TYPE"; String XML_ELEMENT__ILLEGAL_TYPE = "XML_ELEMENT__ILLEGAL_TYPE"; + String XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_RETURN_TYPE = "XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_RETURN_TYPE"; + String XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_PARAM = "XML_ELEMENT_DECL__INVALID_METHOD_SIGNATURE_PARAM"; String XML_ELEMENT_DECL__SUBST_HEAD_NAME_EQUALS_NAME = "XML_ELEMENT_DECL__SUBST_HEAD_NAME_EQUALS_NAME"; String XML_ELEMENT_DECL__SUBST_HEAD_NO_MATCHING_ELEMENT_DECL = "XML_ELEMENT_DECL__SUBST_HEAD_NO_MATCHING_ELEMENT_DECL"; -- cgit v1.2.3