Author: akazakov
Date: 2010-09-01 14:23:17 -0400 (Wed, 01 Sep 2010)
New Revision: 24620
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/observers/
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/observers/ClassFragmentLogger.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.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/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java
Log:
https://jira.jboss.org/browse/JBIDE-6955 Erroroneous error about CDI observer method on
session bean
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-09-01
18:21:45 UTC (rev 24619)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-09-01
18:23:17 UTC (rev 24620)
@@ -425,6 +425,9 @@
public static IMethod getBusinessMethodDeclaration(ISessionBean bean, IBeanMethod
method) {
try {
if (!Flags.isStatic(method.getMethod().getFlags())) {
+ if(bean.getAnnotation(CDIConstants.SINGLETON_ANNOTATION_TYPE_NAME)!=null) {
+ return method.getMethod();
+ }
Set<IParametedType> types = bean.getLegalTypes();
for (IParametedType type : types) {
IType sourceType = type.getType();
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-09-01
18:21:45 UTC (rev 24619)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-09-01
18:23:17 UTC (rev 24620)
@@ -42,6 +42,7 @@
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
@@ -872,13 +873,14 @@
* @param annotatedParams
* @param errorKey
*/
- private void validateSessionBeanMethod(IClassBean bean, IBeanMethod method,
Set<ITextSourceReference> annotatedParams, String errorMessageKey, String
preferencesKey) {
+ private void validateSessionBeanMethod(IClassBean bean, IBeanMethod method,
Set<ITextSourceReference> annotatedParams, String errorMessage, String
preferencesKey) {
if (bean instanceof ISessionBean && annotatedParams != null) {
IMethod iMethod = CDIUtil.getBusinessMethodDeclaration((SessionBean)bean, method);
if(iMethod==null) {
saveAllSuperTypesAsLinkedResources(bean);
for (ITextSourceReference declaration : annotatedParams) {
- addError(errorMessageKey, preferencesKey, declaration, bean.getResource());
+ String bindedErrorMessage = NLS.bind(errorMessage, new
String[]{method.getMethod().getElementName(), bean.getBeanClass().getElementName()});
+ addError(bindedErrorMessage, preferencesKey, declaration, bean.getResource());
}
} else {
getValidationContext().addLinkedCoreResource(bean.getSourcePath().toOSString(),
iMethod.getResource().getFullPath(), false);
@@ -1066,7 +1068,8 @@
if(classBean instanceof ISessionBean) {
IMethod method = CDIUtil.getBusinessMethodDeclaration((SessionBean)classBean,
producerMethod);
if(method==null) {
- addError(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource());
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{producerMethod.getMethod().getElementName(),
producer.getBeanClass().getElementName()});
+ addError(bindedErrorMessage,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource());
saveAllSuperTypesAsLinkedResources(classBean);
} else {
getValidationContext().addLinkedCoreResource(classBean.getSourcePath().toOSString(),
method.getResource().getFullPath(), false);
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-09-01
18:21:45 UTC (rev 24619)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-09-01
18:23:17 UTC (rev 24620)
@@ -52,10 +52,10 @@
PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED_OBSERVES=Producer method has a parameter annotated
@Observes [JSR-299 �3.3.2]
OBSERVER_ANNOTATED_INJECT=Observer method cannot be annotated @Inject [JSR-299 �10.4.2]
OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED=Observer method has a parameter annotated
@Disposes [JSR-299 �10.4.2]
-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 [JSR-299
�3.3.2]
+ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN=Non-static method {0}() of a session bean class
{1} is annotated @Produces, and the method is not a business method of the session bean
[JSR-299 �3.3.2]
MULTIPLE_DISPOSING_PARAMETERS=Method has more than one parameter annotated @Disposes
[JSR-299 �3.3.6]
DISPOSER_ANNOTATED_INJECT=Disposer method cannot be annotated @Inject [JSR-299 �3.3.6]
-ILLEGAL_DISPOSER_IN_SESSION_BEAN=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
[JSR-299 �3.3.6]
+ILLEGAL_DISPOSER_IN_SESSION_BEAN=Non-static method {0}() of a session bean class {1} has
a parameter annotated @Disposes, and the method is not a business method of the session
bean [JSR-299 �3.3.6]
NO_PRODUCER_MATCHING_DISPOSER=There is no producer method declared by the (same) bean
class that is assignable to the disposed parameter of a disposer method [JSR-299 �3.3.7]
MULTIPLE_DISPOSERS_FOR_PRODUCER=There are multiple disposer methods for a single producer
method [JSR-299 �3.3.7]
ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN=Non-static field of a session bean class is
annotated @Produces [JSR-299 �3.4.2]
@@ -65,7 +65,7 @@
GENERIC_METHOD_ANNOTATED_INJECT=Generic method of a bean cannot be annotated @Inject
[JSR-299 �3.9.1]
STATIC_METHOD_ANNOTATED_INJECT=Static method of a bean cannot be annotated @Inject
[JSR-299 �3.9.1]
MULTIPLE_OBSERVING_PARAMETERS=Method has more than one parameter annotated @Observes
[JSR-299 �10.4.2]
-ILLEGAL_OBSERVER_IN_SESSION_BEAN=Non-static method of a session bean class has a
parameter annotated @Observes, and the method is not a business method of the EJB [JSR-299
�10.4.2]
+ILLEGAL_OBSERVER_IN_SESSION_BEAN=Non-static method {0}() of a session bean class {1} has
a parameter annotated @Observes, and the method is not a business method of the EJB
[JSR-299 �10.4.2]
ILLEGAL_CONDITIONAL_OBSERVER=Beans with scope @Dependent may not have conditional
observer methods [JSR-299 �10.4.3]
BOTH_INTERCEPTOR_AND_DECORATOR=The bean class of a managed bean cannot be annotated with
both the @Interceptor and @Decorator stereotypes [JSR-299 �3.1]
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/observers/ClassFragmentLogger.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/observers/ClassFragmentLogger.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/observers/ClassFragmentLogger.java 2010-09-01
18:23:17 UTC (rev 24620)
@@ -0,0 +1,24 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.observers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.enterprise.event.Observes;
+
+@Singleton
+public class ClassFragmentLogger {
+
+ private final List<Object> log;
+
+ public ClassFragmentLogger() {
+ this.log = new ArrayList<Object>();
+ }
+
+ @Lock(LockType.WRITE)
+ public void addEntry(@Observes Object codeFragment) {
+ this.log.add(codeFragment);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/observers/ClassFragmentLogger.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java 2010-09-01
18:21:45 UTC (rev 24619)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java 2010-09-01
18:23:17 UTC (rev 24620)
@@ -14,6 +14,7 @@
import java.text.MessageFormat;
import org.eclipse.core.resources.IFile;
+import org.eclipse.osgi.util.NLS;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationMessages;
/**
@@ -502,7 +503,8 @@
*/
public void testProducerMethodOnSessionBeanMustBeBusinessMethod() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/enterprise/nonbusiness/FooProducer.java");
- assertMarkerIsCreated(file,
CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, 25);
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{"createFoo", "FooProducer"});
+ assertMarkerIsCreated(file, bindedErrorMessage, 25);
}
/**
@@ -601,9 +603,11 @@
*/
public void testDisposalMethodNotBusinessOrStatic() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/disposal/method/definition/broken/methodOnSessionBean/AppleTree.java");
- assertMarkerIsCreated(file, CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN,
31);
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN, new
String[]{"recycle", "AppleTree"});
+ assertMarkerIsCreated(file, bindedErrorMessage, 31);
file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/Fox.java");
- assertMarkerIsNotCreated(file, CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN,
73);
+ bindedErrorMessage = NLS.bind(CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN,
new String[]{"disposeLitter", "Fox"});
+ assertMarkerIsNotCreated(file, bindedErrorMessage, 73);
}
/**
@@ -1332,11 +1336,25 @@
*/
public void testObserverMethodOnEnterpriseBeanNotBusinessMethodOrStaticFails() throws
Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/event/broken/observer/notBusinessMethod/TibetanTerrier_Broken.java");
- assertMarkerIsCreated(file, CDIValidationMessages.ILLEGAL_OBSERVER_IN_SESSION_BEAN,
25);
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_OBSERVER_IN_SESSION_BEAN, new
String[]{"observeSomeEvent", "TibetanTerrier_Broken"});
+ assertMarkerIsCreated(file, bindedErrorMessage, 25);
}
/**
* 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
+ * See
https://jira.jboss.org/browse/JBIDE-6955
+ *
+ * @throws Exception
+ */
+ public void testObserverMethodOnSingletonBeanIsBusinessMethodOk() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/observers/ClassFragmentLogger.java");
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_OBSERVER_IN_SESSION_BEAN, new
String[]{"addEntry", "ClassFragmentLogger"});
+ assertMarkerIsNotCreated(file, bindedErrorMessage, 21);
+ }
+
+ /**
+ * 10.4.2. Declaring an observer method
* - interceptor has a method with a parameter annotated @Observes
*
* @throws Exception