Author: akazakov
Date: 2010-04-16 11:06:06 -0400 (Fri, 16 Apr 2010)
New Revision: 21537
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.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 disposer method validation.
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:27:17 UTC (rev 21536)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-16
15:06:06 UTC (rev 21537)
@@ -300,16 +300,17 @@
}
private void validateClassBean(IClassBean bean) {
+ validateDisposers(bean);
+ }
+
+ private void validateDisposers(IClassBean bean) {
Set<IBeanMethod> disposers = bean.getDisposers();
- /*
- * 3.3.6. Declaring a disposer method
- * - method has more than one parameter annotated @Disposes
- */
for (IBeanMethod dssposer : disposers) {
List<IParameter> params = dssposer.getParameters();
- if(params.size()<2) {
- continue;
- }
+ /*
+ * 3.3.6. Declaring a disposer method
+ * - method has more than one parameter annotated @Disposes
+ */
Set<IAnnotationDeclaration> declarations = new
HashSet<IAnnotationDeclaration>();
for (IParameter param : params) {
IAnnotationDeclaration declaration =
param.getAnnotation(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
@@ -322,6 +323,31 @@
addError(CDIValidationMessages.MULTIPLE_DISPOSING_PARAMETERS,
CDIPreferences.MULTIPLE_DISPOSING_PARAMETERS, declaration, bean.getResource());
}
}
+ /*
+ * 3.3.6. Declaring a disposer method
+ * - a disposer method is annotated @Observes.
+ *
+ * 10.4.2. Declaring an observer method
+ * - a observer method is annotated @Disposes.
+ */
+ declarations = new HashSet<IAnnotationDeclaration>();
+ boolean observesExists = false;
+ for (IParameter param : params) {
+ IAnnotationDeclaration declaration =
param.getAnnotation(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ if(declaration!=null) {
+ declarations.add(declaration);
+ }
+ declaration = param.getAnnotation(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME);
+ if(declaration!=null) {
+ declarations.add(declaration);
+ observesExists = true;
+ }
+ }
+ if(observesExists) {
+ for (IAnnotationDeclaration declaration : declarations) {
+ addError(CDIValidationMessages.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferences.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED, declaration, bean.getResource());
+ }
+ }
}
}
@@ -367,6 +393,9 @@
/*
* 3.3.2. Declaring a producer method
* - a has a parameter annotated @Observers
+ *
+ * 10.4.2. Declaring an observer method
+ * - an observer method is annotated @Produces
*/
declaration = param.getAnnotation(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME);
if(declaration!=null) {
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:27:17 UTC (rev 21536)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-04-16
15:06:06 UTC (rev 21537)
@@ -79,7 +79,7 @@
// {CDIPreferences.PRODUCER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerAnnotatedInject_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.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerParameterIllegallyAnnotated_label},
// {CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalProducerMethodInSessionBean_label},
{CDIPreferences.MULTIPLE_DISPOSING_PARAMETERS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleDisposingParameters_label},
// {CDIPreferences.DISPOSER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_disposerAnnotatedInject_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:27:17 UTC (rev 21536)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-16
15:06:06 UTC (rev 21537)
@@ -182,6 +182,17 @@
}
/**
+ * 3.3.6. Declaring a disposer method
+ * - a disposer method is annotated @Observes.
+ *
+ * @throws Exception
+ */
+ public void testObserverParameterUnallowed() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/disposal/method/definition/broken/observesUnallowed/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED, 32, 32);
+ }
+
+ /**
* 3.3.2. Declaring a producer method
* - a producer method has a parameter annotated @Disposes
*
@@ -203,6 +214,28 @@
AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 26);
}
+ /**
+ * 10.4.2. Declaring an observer method
+ * - an observer method is annotated @Produces
+ *
+ * @throws Exception
+ */
+ public void testObserverMethodAnnotatedProducesFails() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/event/broken/observer/isProducer/BorderTerrier_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 25);
+ }
+
+ /**
+ * 10.4.2. Declaring an observer method
+ * - a observer method is annotated @Disposes.
+ *
+ * @throws Exception
+ */
+ public void testObserverMethodWithDisposesParamFails() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/event/broken/observer/isDisposer/FoxTerrier_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED, 32, 32);
+ }
+
public static int getMarkersNumber(IResource resource) {
return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
}