Author: akazakov
Date: 2010-05-24 13:18:22 -0400 (Mon, 24 May 2010)
New Revision: 22293
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 new CDI validation rule: Non-static
method of a session bean class has a parameter annotated @Observes, and the method is not
a business method of the EJB
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-05-24
17:06:45 UTC (rev 22292)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-24
17:18:22 UTC (rev 22293)
@@ -413,6 +413,8 @@
} catch (JavaModelException e) {
CDICorePlugin.getDefault().logError(e);
}
+
+ validateSessionBeanMethod(bean, observer, declarations,
CDIValidationMessages.ILLEGAL_OBSERVER_IN_SESSION_BEAN, CDIPreferences.ILLEGAL_OBSERVER_IN_SESSION_BEAN);
}
}
@@ -431,8 +433,8 @@
boundDisposers.addAll(disposerMethods);
if (disposerMethods.size() > 1) {
/*
- * 3.3.7. Disposer method resolution - there are multiple
- * disposer methods for a single producer method
+ * 3.3.7. Disposer method resolution
+ * - there are multiple disposer methods for a single producer method
*/
for (IBeanMethod disposerMethod : disposerMethods) {
Set<ITextSourceReference> disposerDeclarations =
CDIUtil.getAnnotationPossitions(disposerMethod,
CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
@@ -448,8 +450,8 @@
List<IParameter> params = disposer.getParameters();
/*
- * 3.3.6. Declaring a disposer method - method has more than one
- * parameter annotated @Disposes
+ * 3.3.6. Declaring a disposer method
+ * - method has more than one parameter annotated @Disposes
*/
Set<ITextSourceReference> disposerDeclarations = new
HashSet<ITextSourceReference>();
for (IParameter param : params) {
@@ -465,11 +467,11 @@
}
/*
- * 3.3.6. Declaring a disposer method - a disposer method has a
- * parameter annotated @Observes.
+ * 3.3.6. Declaring a disposer method
+ * - a disposer method has a parameter annotated @Observes.
*
- * 10.4.2. Declaring an observer method - a observer method has a
- * parameter annotated @Disposes.
+ * 10.4.2. Declaring an observer method
+ * - a observer method has a parameter annotated @Disposes.
*/
Set<ITextSourceReference> declarations = new
HashSet<ITextSourceReference>();
boolean observesExists = false;
@@ -488,11 +490,11 @@
}
/*
- * 3.3.6. Declaring a disposer method - a disposer method is
- * annotated @Inject.
+ * 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
+ * 3.9.1. Declaring an initializer method
+ * - an initializer method has a parameter annotated @Disposes
*
* 3.7.1. Declaring a bean constructor
* - bean constructor has a parameter annotated @Disposes
@@ -512,16 +514,15 @@
}
/*
- * 3.3.6. Declaring a disposer method - a non-static method of a
- * session bean class has a parameter annotated @Disposes, and the
- * method is not a business method of the session bean
+ * 3.3.6. Declaring a disposer method
+ * - a non-static method of a session bean class has a parameter annotated @Disposes,
and the method is not a business method of the session bean
*/
validateSessionBeanMethod(bean, disposer, disposerDeclarations,
CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN,
CDIPreferences.ILLEGAL_DISPOSER_IN_SESSION_BEAN);
/*
- * 3.3.6. Declaring a disposer method - decorators may not declare
- * disposer methods
+ * 3.3.6. Declaring a disposer method
+ * - decorators may not declare disposer methods
*/
if (bean instanceof IDecorator) {
IDecorator decorator = (IDecorator) bean;
@@ -534,8 +535,8 @@
}
/*
- * 3.3.6. Declaring a disposer method - interceptors may not declare
- * disposer methods
+ * 3.3.6. Declaring a disposer method
+ * - interceptors may not declare disposer methods
*/
if (bean instanceof IInterceptor) {
IInterceptor interceptor = (IInterceptor) bean;
@@ -549,9 +550,8 @@
}
/*
- * 3.3.7. Disposer method resolution - there is no producer method
- * declared by the (same) bean class that is assignable to the
- * disposed parameter of a disposer method
+ * 3.3.7. Disposer method resolution
+ * - there is no producer method declared by the (same) bean class that is assignable
to the disposed parameter of a disposer method
*/
if (!boundDisposers.contains(disposer)) {
for (ITextSourceReference declaration : disposerDeclarations) {
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-05-24
17:06:45 UTC (rev 22292)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-05-24
17:18:22 UTC (rev 22293)
@@ -91,7 +91,7 @@
{CDIPreferences.CONSTRUCTOR_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_constructorParameterIllegallyAnnotated_label},
// {CDIPreferences.GENERIC_METHOD_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_genericMethodAnnotatedInject_label},
{CDIPreferences.MULTIPLE_OBSERVING_PARAMETERS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleObservingParameters_label},
-// {CDIPreferences.ILLEGAL_OBSERVER_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalObserverInSessionBean_label},
+ {CDIPreferences.ILLEGAL_OBSERVER_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalObserverInSessionBean_label},
// {CDIPreferences.ILLEGAL_CONDITIONAL_OBSERVER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalConditionalObserver_label},
},
CDICorePlugin.PLUGIN_ID
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-05-24
17:06:45 UTC (rev 22292)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-24
17:18:22 UTC (rev 22293)
@@ -856,6 +856,17 @@
AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED, 28, 28);
}
+ /**
+ * 10.4.2. Declaring an observer method
+ * - non-static method of a session bean class has a parameter annotated @Observes, and
the method is not a business method of the EJB
+ *
+ * @throws Exception
+ */
+ public void testObserverMethodOnEnterpriseBeanNotBusinessMethodOrStaticFails() throws
Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/event/broken/observer/notBusinessMethod/TibetanTerrier_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_OBSERVER_IN_SESSION_BEAN, 25);
+ }
+
public static int getMarkersNumber(IResource resource) {
return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
}