Author: akazakov
Date: 2010-04-16 14:45:21 -0400 (Fri, 16 Apr 2010)
New Revision: 21545
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
18:22:54 UTC (rev 21544)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-16
18:45:21 UTC (rev 21545)
@@ -305,41 +305,38 @@
private void validateDisposers(IClassBean bean) {
Set<IBeanMethod> disposers = bean.getDisposers();
- for (IBeanMethod dssposer : disposers) {
- List<IParameter> params = dssposer.getParameters();
+ for (IBeanMethod disposer : disposers) {
+ List<IParameter> params = disposer.getParameters();
/*
* 3.3.6. Declaring a disposer method
* - method has more than one parameter annotated @Disposes
*/
- Set<IAnnotationDeclaration> declarations = new
HashSet<IAnnotationDeclaration>();
+ Set<IAnnotationDeclaration> disposerDeclarations = new
HashSet<IAnnotationDeclaration>();
for (IParameter param : params) {
IAnnotationDeclaration declaration =
param.getAnnotation(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
if(declaration!=null) {
- declarations.add(declaration);
+ disposerDeclarations.add(declaration);
}
}
- if(declarations.size()>1) {
- for (IAnnotationDeclaration declaration : declarations) {
+ if(disposerDeclarations.size()>1) {
+ for (IAnnotationDeclaration declaration : disposerDeclarations) {
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.
+ * - a disposer method has a parameter annotated @Observes.
*
* 10.4.2. Declaring an observer method
- * - a observer method is annotated @Disposes.
+ * - a observer method has a parameter annotated @Disposes.
*/
- declarations = new HashSet<IAnnotationDeclaration>();
+ Set<IAnnotationDeclaration> declarations = new
HashSet<IAnnotationDeclaration>();
boolean observesExists = false;
+ declarations.addAll(disposerDeclarations);
for (IParameter param : params) {
- IAnnotationDeclaration declaration =
param.getAnnotation(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ IAnnotationDeclaration declaration =
param.getAnnotation(CDIConstants.OBSERVERS_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;
}
}
@@ -348,6 +345,20 @@
addError(CDIValidationMessages.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferences.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED, declaration, bean.getResource());
}
}
+ /*
+ * 3.3.6. Declaring a disposer method
+ * - a disposer method is annotated @Inject.
+ *
+ * 3.9.1. Declaring an initializer method
+ * - an initializer method has a parameter annotated @Disposes
+ */
+ IAnnotationDeclaration injectDeclaration =
disposer.getAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ if(injectDeclaration!=null) {
+ addError(CDIValidationMessages.DISPOSER_ANNOTATED_INJECT,
CDIPreferences.DISPOSER_ANNOTATED_INJECT, injectDeclaration, bean.getResource());
+ for (IAnnotationDeclaration declaration : disposerDeclarations) {
+ addError(CDIValidationMessages.DISPOSER_ANNOTATED_INJECT,
CDIPreferences.DISPOSER_ANNOTATED_INJECT, declaration, bean.getResource());
+ }
+ }
}
}
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
18:22:54 UTC (rev 21544)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-04-16
18:45:21 UTC (rev 21545)
@@ -82,7 +82,7 @@
{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},
+ {CDIPreferences.DISPOSER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_disposerAnnotatedInject_label},
// {CDIPreferences.ILLEGAL_DISPOSER_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalDisposerInSessionBean_label},
// {CDIPreferences.NO_PRODUCER_MATCHING_DISPOSER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_noProducerMatchingDisposer_label},
// {CDIPreferences.MULTIPLE_DISPOSERS_FOR_PRODUCER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleDisposersForProducer_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
18:22:54 UTC (rev 21544)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-16
18:45:21 UTC (rev 21545)
@@ -193,6 +193,28 @@
}
/**
+ * 3.3.6. Declaring a disposer method
+ * - a disposer method is annotated @Inject.
+ *
+ * @throws Exception
+ */
+ public void testInitializerUnallowed() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/disposal/method/definition/broken/initializerUnallowed/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.DISPOSER_ANNOTATED_INJECT,
32, 33);
+ }
+
+ /**
+ * 3.9.1. Declaring an initializer method
+ * - an initializer method has a parameter annotated @Disposes
+ *
+ * @throws Exception
+ */
+ public void testInitializerMethodHasParameterAnnotatedDisposes() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/initializer/broken/parameterAnnotatedDisposes/Capercaillie_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.DISPOSER_ANNOTATED_INJECT,
25, 26);
+ }
+
+ /**
* 3.3.2. Declaring a producer method
* - a producer method has a parameter annotated @Disposes
*