Author: akazakov
Date: 2010-05-24 09:46:57 -0400 (Mon, 24 May 2010)
New Revision: 22281
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.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/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: bean class
has more than one constructor annotated @Inject
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java 2010-05-24
13:37:42 UTC (rev 22280)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IClassBean.java 2010-05-24
13:46:57 UTC (rev 22281)
@@ -34,9 +34,9 @@
Set<IBeanMethod> getDisposers();
/**
- * Returns a set of bean constructor of the bean.
+ * Returns a set of bean constructors of the bean.
*
- * @return a set of bean constructor of the bean.
+ * @return a set of bean constructors of the bean.
*/
Set<IBeanMethod> getBeanConstructor();
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2010-05-24
13:37:42 UTC (rev 22280)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2010-05-24
13:46:57 UTC (rev 22281)
@@ -47,7 +47,7 @@
}
public boolean isConstructor() {
- return isConstructor();
+ return isConstructor;
}
protected void init(IType contextType, DefinitionContext context) throws CoreException
{
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
13:37:42 UTC (rev 22280)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-24
13:46:57 UTC (rev 22281)
@@ -343,8 +343,31 @@
validateSessionBean((ISessionBean) bean);
}
validateMixedClassBean(bean);
+ validateConstructors(bean);
}
+ private void validateConstructors(IClassBean bean) {
+ Set<IBeanMethod> constructors = bean.getBeanConstructor();
+ if(constructors.size()>1) {
+ Set<IAnnotationDeclaration> injects = new
HashSet<IAnnotationDeclaration>();
+ for (IBeanMethod constructor : constructors) {
+ IAnnotationDeclaration inject =
constructor.getAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ if(inject!=null) {
+ injects.add(inject);
+ }
+ }
+ /*
+ * 3.7.1. Declaring a bean constructor
+ * - bean class has more than one constructor annotated @Inject
+ */
+ if(injects.size()>1) {
+ for (IAnnotationDeclaration inject : injects) {
+ addError(CDIValidationMessages.MULTIPLE_INJECTION_CONSTRUCTORS,
CDIPreferences.MULTIPLE_INJECTION_CONSTRUCTORS, inject, bean.getResource());
+ }
+ }
+ }
+ }
+
private void validateDisposers(IClassBean bean) {
Set<IBeanMethod> disposers = bean.getDisposers();
if (disposers.isEmpty()) {
@@ -367,8 +390,7 @@
Set<ITextSourceReference> disposerDeclarations =
CDIUtil.getAnnotationPossitions(disposerMethod,
CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
for (ITextSourceReference declaration : disposerDeclarations) {
- addError(CDIValidationMessages.MULTIPLE_DISPOSERS_FOR_PRODUCER,
CDIPreferences.MULTIPLE_DISPOSERS_FOR_PRODUCER, declaration, bean
- .getResource());
+ addError(CDIValidationMessages.MULTIPLE_DISPOSERS_FOR_PRODUCER,
CDIPreferences.MULTIPLE_DISPOSERS_FOR_PRODUCER, 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-24
13:37:42 UTC (rev 22280)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-24
13:46:57 UTC (rev 22281)
@@ -97,14 +97,14 @@
- matching object in the Java EE component environment is not of the same type
as the producer field declaration
-
-
-
3.6. Additional built-in beans
- Java EE component class has an injection point of type UserTransaction
and qualifier @Default, and may not validly make use of the JTA UserTransaction
according to the Java EE platform specification
+
+
+
3.7.1. Declaring a bean constructor
- bean class has more than one constructor annotated @Inject
- bean constructor has a parameter annotated @Disposes, or @Observes
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
13:37:42 UTC (rev 22280)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-24
13:46:57 UTC (rev 22281)
@@ -746,10 +746,28 @@
* 3.5.1. Declaring a resource
* - matching object in the Java EE component environment is not of the same type as
the producer field declaration
*
- * Cannot implement this validation rule.
+ * TODO needs some investigation.
*/
+ /*
+ * 3.6. Additional built-in beans
+ * - Java EE component class has an injection point of type UserTransaction and
qualifier @Default, and may not validly make use of the JTA UserTransaction according to
the Java EE platform specification
+ *
+ * TODO needs some investigation.
+ */
+
/**
+ * 3.7.1. Declaring a bean constructor
+ * - bean class has more than one constructor annotated @Inject
+ *
+ * @throws Exception
+ */
+ public void testTooManyInitializerAnnotatedConstructor() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/simple/definition/tooManyInitializerAnnotatedConstructors/Goose_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.MULTIPLE_INJECTION_CONSTRUCTORS, 24, 29);
+ }
+
+ /**
* 3.9.1. Declaring an initializer method
* - an initializer method has a parameter annotated @Disposes
*