Author: akazakov
Date: 2010-06-30 13:26:24 -0400 (Wed, 30 Jun 2010)
New Revision: 23130
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/ObserverMethodInDecoratorBroken.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ObserverMethodInInterceptorBroken.java
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/CDIValidationMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt
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/resources/tck/tests/jbt/validation/decorators/beans.xml
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/beans.xml
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 validation rule: interceptor or
decorator has a method with a parameter annotated @Observes
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-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-06-30
17:26:24 UTC (rev 23130)
@@ -499,6 +499,19 @@
} catch (JavaModelException e) {
CDICorePlugin.getDefault().logError(e);
}
+ /*
+ * 10.4.2. Declaring an observer method
+ * - interceptor or decorator has a method with a parameter annotated @Observes
+ */
+ if(bean instanceof IDecorator) {
+ for (ITextSourceReference declaration : declarations) {
+ addError(CDIValidationMessages.OBSERVER_IN_DECORATOR,
CDIPreferences.OBSERVER_IN_INTERCEPTOR_OR_DECORATOR, declaration, bean.getResource());
+ }
+ } else if(bean instanceof IInterceptor) {
+ for (ITextSourceReference declaration : declarations) {
+ addError(CDIValidationMessages.OBSERVER_IN_INTERCEPTOR,
CDIPreferences.OBSERVER_IN_INTERCEPTOR_OR_DECORATOR, declaration, bean.getResource());
+ }
+ }
validateSessionBeanMethod(bean, observer, declarations,
CDIValidationMessages.ILLEGAL_OBSERVER_IN_SESSION_BEAN, CDIPreferences.ILLEGAL_OBSERVER_IN_SESSION_BEAN);
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-06-30
17:26:24 UTC (rev 23130)
@@ -93,7 +93,8 @@
public static String ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING;
public static String ILLEGAL_INTERCEPTOR_BINDING_METHOD;
public static String CONFLICTING_INTERCEPTOR_BINDINGS;
- public static String OBSERVER_IN_INTERCEPTOR_OR_DECORATOR;
+ public static String OBSERVER_IN_INTERCEPTOR;
+ public static String OBSERVER_IN_DECORATOR;
public static String INTERCEPTOR_IS_ALTERNATIVE;
public static String DECORATOR_IS_ALTERNATIVE;
public static String MISSING_INTERCEPTOR_BINDING;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-06-30
17:26:24 UTC (rev 23130)
@@ -158,16 +158,15 @@
- delegate type does not implement or extend a decorated type of the decorator,
or specifies different type parameters
-
-
-
-
-
9.2. Declaring the interceptor bindings of an interceptor
- interceptor for lifecycle callbacks declares an interceptor binding type
that is defined @Target({TYPE, METHOD})
- interceptor declared using @Interceptor does not declare any interceptor binding
(Non-Portable behavior)
+
+
+
+
9.3. Binding an interceptor to a bean
- managed bean has a class level interceptor binding and is declared final
or has a non-static, non-private, final method
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-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-06-30
17:26:24 UTC (rev 23130)
@@ -72,7 +72,8 @@
ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING=Interceptor for lifecycle callbacks may
only declare interceptor binding types that are defined as @Target(TYPE) [JSR-299 �9.2]
ILLEGAL_INTERCEPTOR_BINDING_METHOD=Non-static, non-private, final method of a managed
bean has a interceptor binding (either method level, or declaring class level)
CONFLICTING_INTERCEPTOR_BINDINGS=The set of interceptor bindings of a bean or
interceptor, including bindings inherited from stereotypes and other interceptor bindings,
has two instances of a certain interceptor binding type and the instances have different
values of some annotation member
-OBSERVER_IN_INTERCEPTOR_OR_DECORATOR=Interceptor or decorator has a method with a
parameter annotated @Observes
+OBSERVER_IN_DECORATOR=Interceptor cannot have a method with a parameter annotated
@Observes [JSR-299 �10.4.2]
+OBSERVER_IN_INTERCEPTOR=Decorator cannot have a method with a parameter annotated
@Observes [JSR-299 �10.4.2]
INTERCEPTOR_IS_ALTERNATIVE=Interceptor is an alternative
DECORATOR_IS_ALTERNATIVE=Decorator is an alternative
MISSING_INTERCEPTOR_BINDING=Interceptor declared using @Interceptor should specify at
least one interceptor binding [JSR-299 �9.2]
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-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-06-30
17:26:24 UTC (rev 23130)
@@ -115,7 +115,7 @@
{CDIPreferences.ILLEGAL_LIFECYCLE_CALLBACK_INTERCEPTOR_BINDING,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalLifecycleCallbackInterceptorBinding_label},
// {CDIPreferences.ILLEGAL_INTERCEPTOR_BINDING_METHOD,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalInterceptorBindingMethod_label},
// {CDIPreferences.CONFLICTING_INTERCEPTOR_BINDINGS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_conflictingInterceptorBindings_label},
-// {CDIPreferences.OBSERVER_IN_INTERCEPTOR_OR_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerInInterceptorOrDecorator_label},
+ {CDIPreferences.OBSERVER_IN_INTERCEPTOR_OR_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerInInterceptorOrDecorator_label},
{CDIPreferences.INTERCEPTOR_OR_DECORATOR_IS_ALTERNATIVE,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_interceptorOrDecoratorIsAlternative_label},
{CDIPreferences.MISSING_INTERCEPTOR_BINDING,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_missingInterceptorBinding_label},
{CDIPreferences.INJECTED_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_injectedDecorator_label},
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/ObserverMethodInDecoratorBroken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/ObserverMethodInDecoratorBroken.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/ObserverMethodInDecoratorBroken.java 2010-06-30
17:26:24 UTC (rev 23130)
@@ -0,0 +1,16 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.decorators;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+
+@Decorator
+public class ObserverMethodInDecoratorBroken {
+
+ @Inject @Delegate @Any Object logger;
+
+ public void observeSomeEvent(@Observes String someEvent) {
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/ObserverMethodInDecoratorBroken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/beans.xml
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/beans.xml 2010-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/beans.xml 2010-06-30
17:26:24 UTC (rev 23130)
@@ -3,5 +3,6 @@
<class>org.jboss.jsr299.tck.tests.jdt.validation.decorators.NamedDecoratorBroken</class>
<class>org.jboss.jsr299.tck.tests.jdt.validation.decorators.DecoratorWithWrongScopeBroken</class>
<class>org.jboss.jsr299.tck.tests.jdt.validation.decorators.AlternativeDecoratorBroken</class>
+
<class>org.jboss.jsr299.tck.tests.jdt.validation.decorators.ObserverMethodInDecoratorBroken</class>
</decorators>
</beans>
\ No newline at end of file
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ObserverMethodInInterceptorBroken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ObserverMethodInInterceptorBroken.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ObserverMethodInInterceptorBroken.java 2010-06-30
17:26:24 UTC (rev 23130)
@@ -0,0 +1,12 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.interceptors;
+
+import javax.enterprise.event.Observes;
+import javax.interceptor.Interceptor;
+
+@Interceptor
+@CatInterceptorBinding
+public class ObserverMethodInInterceptorBroken {
+
+ public void observeSomeEvent(@Observes String someEvent) {
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ObserverMethodInInterceptorBroken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/beans.xml
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/beans.xml 2010-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/beans.xml 2010-06-30
17:26:24 UTC (rev 23130)
@@ -9,5 +9,6 @@
<class>org.jboss.jsr299.tck.tests.jdt.validation.interceptors.InterceptorWithLifeCycleMethodOk</class>
<class>org.jboss.jsr299.tck.tests.jdt.validation.interceptors.InterceptorWithPostConstructorBroken</class>
<class>org.jboss.jsr299.tck.tests.jdt.validation.interceptors.InterceptorWithPreDestroyBroken</class>
+
<class>org.jboss.jsr299.tck.tests.jdt.validation.interceptors.ObserverMethodInInterceptorBroken</class>
</interceptors>
</beans>
\ No newline at end of file
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-06-30
17:08:12 UTC (rev 23129)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-06-30
17:26:24 UTC (rev 23130)
@@ -1261,6 +1261,28 @@
assertMarkerIsCreated(file, CDIValidationMessages.ILLEGAL_OBSERVER_IN_SESSION_BEAN,
25);
}
+ /**
+ * 10.4.2. Declaring an observer method
+ * - interceptor has a method with a parameter annotated @Observes
+ *
+ * @throws Exception
+ */
+ public void testObserverMethodInInterceptor() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/ObserverMethodInInterceptorBroken.java");
+ assertMarkerIsCreated(file, CDIValidationMessages.OBSERVER_IN_INTERCEPTOR, 10);
+ }
+
+ /**
+ * 10.4.2. Declaring an observer method
+ * - decorator has a method with a parameter annotated @Observes
+ *
+ * @throws Exception
+ */
+ public void testObserverMethodInDecorator() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/decorators/ObserverMethodInDecoratorBroken.java");
+ assertMarkerIsCreated(file, CDIValidationMessages.OBSERVER_IN_DECORATOR, 14);
+ }
+
public static int getMarkersNumber(IResource resource) {
return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
}