Author: akazakov
Date: 2010-04-14 11:47:36 -0400 (Wed, 14 Apr 2010)
New Revision: 21475
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/NamedInjectionBroken.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/Order.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.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 validation rule: Injection point
other than injected field declares a @Named annotation that does not specify the value
member
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-04-14
14:40:01 UTC (rev 21474)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-14
15:47:36 UTC (rev 21475)
@@ -37,6 +37,8 @@
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IInjectionPointField;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IProducer;
import org.jboss.tools.cdi.core.IProducerField;
@@ -270,6 +272,11 @@
validateProducer((IProducer)bean);
}
+ Set<IInjectionPoint> points = bean.getInjectionPoints();
+ for (IInjectionPoint point : points) {
+ validateInjectionPoint(point);
+ }
+
// TODO
}
@@ -294,6 +301,29 @@
}
}
+ private void validateInjectionPoint(IInjectionPoint injection) {
+ if(!(injection instanceof IInjectionPointField)) {
+ IAnnotationDeclaration named =
injection.getAnnotation(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ if(named!=null) {
+ try {
+ IMemberValuePair[] values = named.getDeclaration().getMemberValuePairs();
+ boolean valueExists = false;
+ for (IMemberValuePair pair : values) {
+ if("value".equals(pair.getMemberName())) {
+ valueExists = true;
+ break;
+ }
+ }
+ if(!valueExists) {
+ addError(CDIValidationMessages.PARAM_INJECTION_DECLARES_EMPTY_NAME,
CDIPreferences.PARAM_INJECTION_DECLARES_EMPTY_NAME, named, injection.getResource());
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
+ }
+ }
+
/*
* 2.2.2. Restricting the bean types of a bean
* - bean class or producer method or field specifies a @Typed annotation,
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/NamedInjectionBroken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/NamedInjectionBroken.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/NamedInjectionBroken.java 2010-04-14
15:47:36 UTC (rev 21475)
@@ -0,0 +1,24 @@
+package org.jboss.jsr299.tck.tests.jbt.inject;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+public class NamedInjectionBroken {
+
+ @Named @Inject Order order;
+
+ @Named
+ @Inject
+ NamedInjectionBroken(Order order) {
+ // DO nothing
+ }
+
+ @Named @Inject public void init(Order order) {
+ // DO nothing
+ }
+
+ @Named("injectTestFooName") @Inject
+ public void foo(Order order) {
+ // DO nothing
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/NamedInjectionBroken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/Order.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/Order.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/Order.java 2010-04-14
15:47:36 UTC (rev 21475)
@@ -0,0 +1,5 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.inject;
+
+public class Order {
+
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/inject/Order.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/ValidationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-14
14:40:01 UTC (rev 21474)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-14
15:47:36 UTC (rev 21475)
@@ -40,6 +40,17 @@
AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Producer field declaration of Java EE
resource specifies an EL name", 15, 19, 24, 27, 31);
}
+ /**
+ * 3.11. The qualifier @Named at injection points
+ * - injection point other than injected field declares a @Named annotation that does
not specify the value member
+ *
+ * @throws Exception
+ */
+ public void testNamedInjectPoint() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/inject/NamedInjectionBroken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Injection point other than injected field
declares a @Named annotation that does not specify the value member", 10, 16);
+ }
+
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, "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", 25);