Author: akazakov
Date: 2010-05-19 12:15:55 -0400 (Wed, 19 May 2010)
New Revision: 22202
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/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/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2708 Added new CDI validation rule: If a producer
method is annotated @Inject, the container automatically detects the problem and treats it
as a definition error.
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-19
14:56:48 UTC (rev 22201)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-19
16:15:55 UTC (rev 22202)
@@ -551,6 +551,15 @@
}
}
+ /*
+ * 3.3.2. Declaring a producer method
+ * - producer method is annotated @Inject
+ */
+ IAnnotationDeclaration inject =
producer.getAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ if(inject!=null) {
+ addError(CDIValidationMessages.PRODUCER_ANNOTATED_INJECT,
CDIPreferences.PRODUCER_ANNOTATED_INJECT, inject, producer.getResource());
+ }
+
String[] typeVariables = producer.getBeanClass().getTypeParameterSignatures();
if (producer instanceof IProducerField) {
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-19
14:56:48 UTC (rev 22201)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-19
16:15:55 UTC (rev 22202)
@@ -51,17 +51,15 @@
- session bean class annotated @Specializes does not directly extend
the bean class of another session bean
-
-
-
-
-
3.3. Producer methods
- producer method return type contains a wildcard type parameter
- producer method with a parameterized return type with a type variable declares
any scope other than @Dependent
- producer method return type is a type variable
+
+
+
3.3.2. Declaring a producer method
- producer method is annotated @Inject
- producer method has a parameter annotated @Disposes
@@ -70,6 +68,9 @@
is not a business method of the session bean
- interceptor or decorator has a method annotated @Produces
+
+
+
3.3.3. Specializing a producer method
- method annotated @Specializes is static or does not directly override another producer
method
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-19
14:56:48 UTC (rev 22201)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-05-19
16:15:55 UTC (rev 22202)
@@ -76,7 +76,7 @@
private static SectionDescription SECTION_MEMBER = new SectionDescription(
CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_member,
new String[][]{
-// {CDIPreferences.PRODUCER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerAnnotatedInject_label},
+ {CDIPreferences.PRODUCER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerAnnotatedInject_label},
{CDIPreferences.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerParameterIllegallyAnnotated_label},
// {CDIPreferences.OBSERVER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerAnnotatedInject_label},
{CDIPreferences.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerParameterIllegallyAnnotated_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-05-19
14:56:48 UTC (rev 22201)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-19
16:15:55 UTC (rev 22202)
@@ -415,8 +415,85 @@
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/inheritance/specialization/enterprise/broken/directlyExtendsNothing/Cow_Broken.java");
AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SPECIALIZING_SESSION_BEAN, 22);
}
-
+
/**
+ * 3.3. Producer methods
+ * - producer method return type contains a wildcard type parameter
+ *
+ * 2.2.1 - Legal bean types
+ * - a parameterized type that contains a wildcard type parameter is not a legal bean
type.
+ *
+ * @throws Exception
+ */
+ public void testParameterizedReturnTypeWithWildcard() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterizedTypeWithWildcard/SpiderProducer.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD, 24);
+ }
+
+ /**
+ * 3.3. Producer methods
+ * - producer method return type is a type variable
+ *
+ * 2.2.1 - Legal bean types
+ * - a type variable is not a legal bean type
+ *
+ * @throws Exception
+ */
+ public void testParameterizedType() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterizedTypeWithTypeParameter2/TProducer.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_IS_VARIABLE, 25);
+ file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/SpiderProducerVariableType_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_IS_VARIABLE, 13);
+ }
+
+ /**
+ * 3.3. Producer methods
+ * - producer method with a parameterized return type with a type variable declares any
scope other than @Dependent
+ *
+ * @throws Exception
+ */
+ public void testParameterizedReturnTypeWithWrongScope() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 25, 39);
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 21);
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 35);
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 31);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
+ * - producer method is annotated @Inject
+ *
+ * @throws Exception
+ */
+ public void testInitializerMethodAnnotatedProduces() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/initializer/broken/methodAnnotatedProduces/Pheasant_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.PRODUCER_ANNOTATED_INJECT,
25);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
+ * - a producer method has a parameter annotated @Disposes
+ *
+ * @throws Exception
+ */
+ public void testProducerMethodWithParameterAnnotatedDisposes() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterAnnotatedDisposes/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 26);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
+ * - a producer method has a parameter annotated @Observers
+ *
+ * @throws Exception
+ */
+ public void testProducerMethodWithParameterAnnotatedObserves() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterAnnotatedObserves/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 26);
+ }
+
+ /**
* 3.5.1. Declaring a resource
* - producer field declaration specifies an EL name (together with one of @Resource,
@PersistenceContext, @PersistenceUnit, @EJB, @WebServiceRef)
*
@@ -541,20 +618,6 @@
}
/**
- * 3.3. Producer methods
- * - producer method return type contains a wildcard type parameter
- *
- * 2.2.1 - Legal bean types
- * - a parameterized type that contains a wildcard type parameter is not a legal bean
type.
- *
- * @throws Exception
- */
- public void testParameterizedReturnTypeWithWildcard() throws Exception {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterizedTypeWithWildcard/SpiderProducer.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_HAS_WILDCARD, 24);
- }
-
- /**
* 3.4. Producer fields
* - producer field type contains a wildcard type parameter
*
@@ -567,22 +630,6 @@
}
/**
- * 3.3. Producer methods
- * - producer method return type is a type variable
- *
- * 2.2.1 - Legal bean types
- * - a type variable is not a legal bean type
- *
- * @throws Exception
- */
- public void testParameterizedType() throws Exception {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterizedTypeWithTypeParameter2/TProducer.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_IS_VARIABLE, 25);
- file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/SpiderProducerVariableType_Broken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_METHOD_RETURN_TYPE_IS_VARIABLE, 13);
- }
-
- /**
* 3.4. Producer fields.
* - producer field type is a type variable
*
@@ -594,20 +641,6 @@
}
/**
- * 3.3. Producer methods
- * - producer method with a parameterized return type with a type variable declares any
scope other than @Dependent
- *
- * @throws Exception
- */
- public void testParameterizedReturnTypeWithWrongScope() throws Exception {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 25, 39);
- AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 21);
- AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 35);
- AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD, 31);
- }
-
- /**
* 3.4. Producer fields
* - producer field with a parameterized type with a type variable declares any scope
other than @Dependent
*
@@ -634,28 +667,6 @@
}
/**
- * 3.3.2. Declaring a producer method
- * - a producer method has a parameter annotated @Disposes
- *
- * @throws Exception
- */
- public void testProducerMethodWithParameterAnnotatedDisposes() throws Exception {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterAnnotatedDisposes/SpiderProducer_Broken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 26);
- }
-
- /**
- * 3.3.2. Declaring a producer method
- * - a producer method has a parameter annotated @Observers
- *
- * @throws Exception
- */
- public void testProducerMethodWithParameterAnnotatedObserves() throws Exception {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/producer/method/broken/parameterAnnotatedObserves/SpiderProducer_Broken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED, 25, 26);
- }
-
- /**
* 10.4.2. Declaring an observer method
* - an observer method is annotated @Produces
*