Author: akazakov
Date: 2010-05-11 11:24:42 -0400 (Tue, 11 May 2010)
New Revision: 22013
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/DecoratorWithWrongScopeBroken.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/InterceptorWithWrongScopeBroken.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ScopedStereotype.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.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/errorList.txt
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 CDI validation rule: Interceptor
or decorator has any scope other than @Dependent
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java 2010-05-11
14:37:20 UTC (rev 22012)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java 2010-05-11
15:24:42 UTC (rev 22013)
@@ -33,5 +33,7 @@
}
defaultPreferences.put(CDIPreferences.INTERCEPTOR_HAS_NAME, CDIPreferences.WARNING);
defaultPreferences.put(CDIPreferences.DECORATOR_HAS_NAME, CDIPreferences.WARNING);
+ defaultPreferences.put(CDIPreferences.ILLEGAL_SCOPE_FOR_INTERCEPTOR,
CDIPreferences.WARNING);
+ defaultPreferences.put(CDIPreferences.ILLEGAL_SCOPE_FOR_DECORATOR,
CDIPreferences.WARNING);
}
}
\ No newline at end of file
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-11
14:37:20 UTC (rev 22012)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-11
15:24:42 UTC (rev 22013)
@@ -827,6 +827,38 @@
}
}
}
+
+ /*
+ * 2.4.1. Built-in scope types
+ * - interceptor or decorator has any scope other than @Dependent (Non-Portable
behavior)
+ */
+ boolean interceptor = bean instanceof IInterceptor;
+ boolean decorator = bean instanceof IDecorator;
+ if(interceptor || decorator) {
+ IScope scope = bean.getScope();
+ if(!CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(scope.getSourceType().getFullyQualifiedName()))
{
+ String key;
+ String message;
+ ITextSourceReference declaration = null;
+ if(!scopes.isEmpty()) {
+ declaration = scopes.iterator().next();
+ }
+ if(interceptor) {
+ key = CDIPreferences.ILLEGAL_SCOPE_FOR_INTERCEPTOR;
+ message = CDIValidationMessages.ILLEGAL_SCOPE_FOR_INTERCEPTOR;
+ if(declaration==null) {
+ declaration = ((IInterceptor)bean).getInterceptorAnnotation();
+ }
+ } else {
+ key = CDIPreferences.ILLEGAL_SCOPE_FOR_DECORATOR;
+ message = CDIValidationMessages.ILLEGAL_SCOPE_FOR_DECORATOR;
+ if(declaration==null) {
+ declaration = ((IDecorator)bean).getDecoratorAnnotation();
+ }
+ }
+ addError(message, key, declaration, bean.getResource());
+ }
+ }
}
/**
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-05-11
14:37:20 UTC (rev 22012)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-11
15:24:42 UTC (rev 22013)
@@ -7,6 +7,10 @@
2.4.1. Built-in scope types
- interceptor or decorator has any scope other than @Dependent (Non-Portable behavior)
+
+
+
+
2.4.3. Declaring the bean scope
- bean class or producer method or field specifies multiple scope type annotations
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-11
14:37:20 UTC (rev 22012)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-05-11
15:24:42 UTC (rev 22013)
@@ -67,8 +67,8 @@
{CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForProducerMethod_label},
{CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForProducerField_label},
// {CDIPreferences.ILLEGAL_SCOPE_WHEN_TYPE_INJECTIONPOINT_IS_INJECTED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeWhenTypeInjectionPointIsInjected_label},
-// {CDIPreferences.ILLEGAL_SCOPE_FOR_INTERCEPTOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForInterceptor_label},
-// {CDIPreferences.ILLEGAL_SCOPE_FOR_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForDecorator_label},
+ {CDIPreferences.ILLEGAL_SCOPE_FOR_INTERCEPTOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForInterceptor_label},
+ {CDIPreferences.ILLEGAL_SCOPE_FOR_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForDecorator_label},
},
CDICorePlugin.PLUGIN_ID
);
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/DecoratorWithWrongScopeBroken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/DecoratorWithWrongScopeBroken.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/DecoratorWithWrongScopeBroken.java 2010-05-11
15:24:42 UTC (rev 22013)
@@ -0,0 +1,10 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.decorators;
+
+import javax.decorator.Decorator;
+import javax.enterprise.context.ApplicationScoped;
+
+@Decorator
+@ApplicationScoped
+public class DecoratorWithWrongScopeBroken {
+
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/DecoratorWithWrongScopeBroken.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-05-11
14:37:20 UTC (rev 22012)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/decorators/beans.xml 2010-05-11
15:24:42 UTC (rev 22013)
@@ -1,5 +1,6 @@
<beans>
<decorators>
<class>org.jboss.jsr299.tck.tests.jdt.validation.decorators.NamedDecoratorBroken</class>
+
<class>org.jboss.jsr299.tck.tests.jdt.validation.decorators.DecoratorWithWrongScopeBroken</class>
</decorators>
</beans>
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/InterceptorWithWrongScopeBroken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/InterceptorWithWrongScopeBroken.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/InterceptorWithWrongScopeBroken.java 2010-05-11
15:24:42 UTC (rev 22013)
@@ -0,0 +1,15 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.interceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+@Interceptor
+@ScopedStereotype
+public class InterceptorWithWrongScopeBroken {
+
+ @AroundInvoke
+ public Object alwaysReturnThis(InvocationContext ctx) throws Exception {
+ return ctx.proceed();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/InterceptorWithWrongScopeBroken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ScopedStereotype.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ScopedStereotype.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ScopedStereotype.java 2010-05-11
15:24:42 UTC (rev 22013)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.jbt.validation.interceptors;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Stereotype;
+
+@Stereotype
+@Target( { TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+@RequestScoped
+@Inherited
+@interface ScopedStereotype {
+
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/ScopedStereotype.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-05-11
14:37:20 UTC (rev 22012)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/interceptors/beans.xml 2010-05-11
15:24:42 UTC (rev 22013)
@@ -2,5 +2,6 @@
<interceptors>
<class>org.jboss.jsr299.tck.tests.jdt.validation.interceptors.NamedInterceptorBroken</class>
<class>org.jboss.jsr299.tck.tests.jdt.validation.interceptors.FordInterceptor</class>
+
<class>org.jboss.jsr299.tck.tests.jdt.validation.interceptors.InterceptorWithWrongScopeBroken</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-05-11
14:37:20 UTC (rev 22012)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-11
15:24:42 UTC (rev 22013)
@@ -21,6 +21,56 @@
public class ValidationTest extends TCKTest {
/**
+ * 2.2.2. Restricting the bean types of a bean
+ * - bean class or producer method or field specifies a @Typed annotation,
+ * and the value member specifies a class which does not correspond to a type
+ * in the unrestricted set of bean types of a bean
+ *
+ * @throws Exception
+ */
+ public void testLegalTypesInTyped() throws Exception {
+ IFile petShopFile =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/PetShop.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(petShopFile,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_TYPE_IN_TYPED_DECLARATION, 25);
+ int markerNumbers = getMarkersNumber(petShopFile);
+ assertEquals("PetShop.java should has the only error marker.", markerNumbers,
1);
+ }
+
+ /**
+ * 2.4.1. Built-in scope types
+ * - interceptor has any scope other than @Dependent (Non-Portable behavior)
+ *
+ * @throws Exception
+ */
+ public void testInterceptorWithWrongScope() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/InterceptorWithWrongScopeBroken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_INTERCEPTOR, 7);
+ }
+
+ /**
+ * 2.4.1. Built-in scope types
+ * - decorator has any scope other than @Dependent (Non-Portable behavior)
+ *
+ * @throws Exception
+ */
+ public void testDecoratorWithWrongScope() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/decorators/DecoratorWithWrongScopeBroken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.ILLEGAL_SCOPE_FOR_DECORATOR,
7);
+ }
+
+ /**
+ * 2.5.3. Beans with no EL name
+ * - interceptor or decorator has a name (Non-Portable behavior)
+ *
+ * @throws Exception
+ */
+ public void testNamedInterceptor() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/NamedInterceptorBroken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.INTERCEPTOR_HAS_NAME, 9);
+ file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/NamedStereotypedInterceptorBroken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.INTERCEPTOR_HAS_NAME, 7);
+ }
+
+ /**
* 2.7.1.3. Stereotype declares a non-empty @Named annotation (Non-Portable behavior)
*
* @throws Exception
@@ -60,19 +110,6 @@
*
* @throws Exception
*/
- public void testNamedInterceptor() throws Exception {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/NamedInterceptorBroken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.INTERCEPTOR_HAS_NAME, 9);
- file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/interceptors/NamedStereotypedInterceptorBroken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.INTERCEPTOR_HAS_NAME, 7);
- }
-
- /**
- * 2.5.3. Beans with no EL name
- * - interceptor or decorator has a name (Non-Portable behavior)
- *
- * @throws Exception
- */
public void testNamedDecorator() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/decorators/NamedDecoratorBroken.java");
AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.DECORATOR_HAS_NAME, 10);
@@ -81,21 +118,6 @@
}
/**
- * 2.2.2. Restricting the bean types of a bean
- * - bean class or producer method or field specifies a @Typed annotation,
- * and the value member specifies a class which does not correspond to a type
- * in the unrestricted set of bean types of a bean
- *
- * @throws Exception
- */
- public void testLegalTypesInTyped() throws Exception {
- IFile petShopFile =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/PetShop.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(petShopFile,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_TYPE_IN_TYPED_DECLARATION, 25);
- int markerNumbers = getMarkersNumber(petShopFile);
- assertEquals("PetShop.java should has the only error marker.", markerNumbers,
1);
- }
-
- /**
* 2.7.1.3. Stereotype declares any other qualifier annotation
*
* @throws Exception
@@ -303,7 +325,7 @@
}
/**
- * 3.4. Producer methods
+ * 3.4. Producer fields.
* - producer field type is a type variable
*
* @throws Exception