Author: akazakov
Date: 2010-04-16 10:26:42 -0400 (Fri, 16 Apr 2010)
New Revision: 21535
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2708 Added tests for Observes method validation.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-04-16
14:22:03 UTC (rev 21534)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-04-16
14:26:42 UTC (rev 21535)
@@ -51,4 +51,5 @@
public String PERSISTENCE_UNIT_ANNOTATION_TYPE_NAME =
"javax.persistence.PersistenceUnit";
public String DISPOSES_ANNOTATION_TYPE_NAME =
"javax.enterprise.inject.Disposes";
+ public String OBSERVERS_ANNOTATION_TYPE_NAME =
"javax.enterprise.event.Observes";
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-16
14:22:03 UTC (rev 21534)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-16
14:26:42 UTC (rev 21535)
@@ -47,6 +47,7 @@
import org.jboss.tools.cdi.core.IParameter;
import org.jboss.tools.cdi.core.IProducer;
import org.jboss.tools.cdi.core.IProducerField;
+import org.jboss.tools.cdi.core.IProducerMethod;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
import org.jboss.tools.cdi.core.IScope;
import org.jboss.tools.cdi.core.IScopeDeclaration;
@@ -327,11 +328,11 @@
private static final String[] RESOURCE_ANNOTATIONS =
{CDIConstants.RESOURCE_ANNOTATION_TYPE_NAME,
CDIConstants.WEB_SERVICE_REF_ANNOTATION_TYPE_NAME, CDIConstants.EJB_ANNOTATION_TYPE_NAME,
CDIConstants.PERSISTENCE_CONTEXT_ANNOTATION_TYPE_NAME,
CDIConstants.PERSISTENCE_UNIT_ANNOTATION_TYPE_NAME};
private void validateProducer(IProducer producer) {
- /*
- * 3.5.1. Declaring a resource
- * - producer field declaration specifies an EL name (together with one of @Resource,
@PersistenceContext, @PersistenceUnit, @EJB, @WebServiceRef)
- */
if(producer instanceof IProducerField) {
+ /*
+ * 3.5.1. Declaring a resource
+ * - producer field declaration specifies an EL name (together with one of @Resource,
@PersistenceContext, @PersistenceUnit, @EJB, @WebServiceRef)
+ */
IProducerField producerField = (IProducerField)producer;
if(producerField.getName()!=null) {
IAnnotationDeclaration declaration;
@@ -346,6 +347,37 @@
}
}
}
+ } else {
+ IProducerMethod producerMethod = (IProducerMethod)producer;
+ List<IParameter> params = producerMethod.getParameters();
+ Set<IAnnotationDeclaration> declarations = new
HashSet<IAnnotationDeclaration>();
+ declarations.add(producerMethod.getAnnotation(CDIConstants.PRODUCES_ANNOTATION_TYPE_NAME));
+ for (IParameter param : params) {
+ /*
+ * 3.3.6. Declaring a disposer method
+ * - a disposer method is annotated @Produces.
+ *
+ * 3.3.2. Declaring a producer method
+ * - a has a parameter annotated @Disposes
+ */
+ IAnnotationDeclaration declaration =
param.getAnnotation(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ if(declaration!=null) {
+ declarations.add(declaration);
+ }
+ /*
+ * 3.3.2. Declaring a producer method
+ * - a has a parameter annotated @Observers
+ */
+ declaration = param.getAnnotation(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME);
+ if(declaration!=null) {
+ declarations.add(declaration);
+ }
+ }
+ if(declarations.size()>1) {
+ for (IAnnotationDeclaration declaration : declarations) {
+ addError(CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferences.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, declaration,
producer.getResource());
+ }
+ }
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-04-16
14:22:03 UTC (rev 21534)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-04-16
14:26:42 UTC (rev 21535)
@@ -31,7 +31,7 @@
PRODUCER_ANNOTATED_INJECT=Producer method or field is annotated @Inject
PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED=Producer method has a parameter annotated
@Disposes or @Observes
OBSERVER_ANNOTATED_INJECT=Observer method is annotated @Inject
-OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED=observer method has a parameter annotated
@Disposes
+OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED=Observer method has a parameter annotated
@Disposes
ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN=Non-static method of a session bean class is
annotated @Produces, and the method is not a business method of the session bean
MULTIPLE_DISPOSING_PARAMETERS=Method has more than one parameter annotated @Disposes
DISPOSER_ANNOTATED_INJECT=Disposer method is annotated @Inject
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-04-16
14:22:03 UTC (rev 21534)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-04-16
14:26:42 UTC (rev 21535)
@@ -77,7 +77,7 @@
CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_member,
new String[][]{
// {CDIPreferences.PRODUCER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerAnnotatedInject_label},
-// {CDIPreferences.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerParameterIllegallyAnnotated_label},
+ {CDIPreferences.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerParameterIllegallyAnnotated_label},
// {CDIPreferences.OBSERVER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerAnnotatedInject_label},
// {CDIPreferences.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerParameterIllegallyAnnotated_label},
// {CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalProducerMethodInSessionBean_label},
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-16
14:22:03 UTC (rev 21534)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-16
14:26:42 UTC (rev 21535)
@@ -170,6 +170,39 @@
AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.MULTIPLE_DISPOSING_PARAMETERS, 30, 30);
}
+ /**
+ * 3.3.6. Declaring a disposer method
+ * - a disposer method is annotated @Produces.
+ *
+ * @throws Exception
+ */
+ public void testProducesUnallowed() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/disposal/method/definition/broken/producesUnallowed/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 30, 31);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
+ * - a producer method has a parameter annotated @Disposes
+ *
+ * @throws Exception
+ */
+ public void testProducerMethodWithParameterAnnotatedDisposes() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterAnnotatedDisposes/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 26);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
+ * - a producer method has a parameter annotated @Observers
+ *
+ * @throws Exception
+ */
+ public void testProducerMethodWithParameterAnnotatedObserves() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterAnnotatedObserves/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 26);
+ }
+
public static int getMarkersNumber(IResource resource) {
return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
}