[jbosstools-commits] JBoss Tools SVN: r21961 - in trunk: cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences and 3 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri May 7 12:35:25 EDT 2010


Author: akazakov
Date: 2010-05-07 12:35:24 -0400 (Fri, 07 May 2010)
New Revision: 21961

Added:
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/AnotherScope.java
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/FishStereotype.java
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.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.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
   trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2708 Added new CDI validation rule: Producer field with a parameterized type with a type variable declares any scope other than @Dependent


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-07 16:26:53 UTC (rev 21960)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java	2010-05-07 16:35:24 UTC (rev 21961)
@@ -544,6 +544,32 @@
 						}
 					}
 				}
+
+				/**
+				 * 3.3. Producer methods
+				 *  - producer method with a parameterized return type with a type variable declares any scope other than @Dependent
+				 *  
+				 * 3.4. Producer fields
+				 *  - producer field with a parameterized type with a type variable declares any scope other than @Dependent
+				 */
+				if(paramTypes.length>0) {
+					IScope scope = producer.getScope();
+					if(!CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME.equals(scope.getSourceType().getFullyQualifiedName())) {
+						ITextSourceReference declaration = typeDeclaration;
+						Set<IScopeDeclaration> decls = producer.getScopeDeclarations();
+						for (IScopeDeclaration decl : decls) {
+							if(decl.getParentMember().getResource().equals(producer.getResource())) {
+								declaration = decl;
+								break;
+							}
+						}
+						boolean field = producer instanceof IProducerField;
+						addError(
+								field?CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD:CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD,
+								field?CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD:CDIPreferences.ILLEGAL_SCOPE_FOR_PRODUCER_METHOD,
+								declaration, producer.getResource());
+					}
+				}
 			}
 
 			String[] typeVariables = producer.getBeanClass().getTypeParameterSignatures();

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-07 16:26:53 UTC (rev 21960)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java	2010-05-07 16:35:24 UTC (rev 21961)
@@ -64,8 +64,8 @@
 			{CDIPreferences.STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE, CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_stereotypeDeclaresMoreThanOneScope_label},
 //			{CDIPreferences.ILLEGAL_SCOPE_FOR_MANAGED_BEAN, CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForManagedBean_label},
 //			{CDIPreferences.ILLEGAL_SCOPE_FOR_SESSION_BEAN, CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalScopeForSessionBean_label},
-//			{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_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},

Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/AnotherScope.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/AnotherScope.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/AnotherScope.java	2010-05-07 16:35:24 UTC (rev 21961)
@@ -0,0 +1,20 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.producers;
+
+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.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.NormalScope;
+
+ at Target( { TYPE, METHOD, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at NormalScope
+ at interface AnotherScope {
+
+}
\ No newline at end of file


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/AnotherScope.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/FishStereotype.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/FishStereotype.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/FishStereotype.java	2010-05-07 16:35:24 UTC (rev 21961)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.producers;
+
+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.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Stereotype;
+import javax.inject.Named;
+
+ at Stereotype
+ at Target( { TYPE, METHOD, FIELD })
+ at Retention(RUNTIME)
+ at ApplicationScoped
+ at Named
+ at interface FishStereotype {
+
+}
\ No newline at end of file


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/FishStereotype.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.java	2010-05-07 16:35:24 UTC (rev 21961)
@@ -0,0 +1,44 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.producers;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+public class ParameterizedTypeWithWrongScope_Broken {
+
+	@Produces public FunnelWeaver<String> getAnotherFunnelWeaver;
+
+	@AnotherScope
+	@Produces public FunnelWeaver<String> getAnotherFunnelWeaver2;
+
+	@Dependent @Produces public FunnelWeaver<String> getAnotherFunnelWeaver3;
+
+	@AnotherScope @Produces public String getAnotherFunnelWeaver4;
+
+	@FishStereotype
+	@Produces public FunnelWeaver<String> getAnotherFunnelWeaver5;
+
+	@Produces public FunnelWeaver<String> create(InjectionPoint point) {
+		return null;
+	}
+
+	@AnotherScope
+	@Produces
+	public FunnelWeaver<String> create2(InjectionPoint point) {
+		return null;
+	}
+
+	@Dependent @Produces public FunnelWeaver<String> create3(InjectionPoint point) {
+		return null;
+	}
+
+	@AnotherScope @Produces public String create4(InjectionPoint point) {
+		return null;
+	}
+
+	@FishStereotype
+	@Produces
+	public FunnelWeaver<String> create5(InjectionPoint point) {
+		return null;
+	}
+}
\ No newline at end of file


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/producers/ParameterizedTypeWithWrongScope_Broken.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-05-07 16:26:53 UTC (rev 21960)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java	2010-05-07 16:35:24 UTC (rev 21961)
@@ -308,23 +308,38 @@
 	 *  
 	 * @throws Exception
 	 */
-	public void testVariableType() throws Exception {
+	public void testTypeVariable() throws Exception {
 		IFile file = tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/SpiderProducerVariableType_Broken.java");
 		AbstractResourceMarkerTest.assertMarkerIsCreated(file, AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.PRODUCER_FIELD_TYPE_IS_VARIABLE, 10);
 	}
 
 	/**
+	 * 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, 41);
+		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, 32);
+	}
+
+	/**
 	 * 3.4. Producer fields
 	 *  - producer field with a parameterized type with a type variable declares any scope other than @Dependent
-	 *  // TODO
 	 *  
 	 * @throws Exception
 	 */
-//	public void testParameterizedReturnTypeWithTypeVariable() throws Exception {
-//		IFile file = tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/producers/SpiderProducerVariableType_Broken.java");
-//		AbstractResourceMarkerTest.assertMarkerIsCreatedForGivenPosition(file, AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 23, 1008, 1033);
-//		AbstractResourceMarkerTest.assertMarkerIsCreatedForGivenPosition(file, AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 24, 10011, 1036);
-//	}
+	public void testParameterizedTypeWithWrongScope() 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_FIELD, 11, 19);
+		AbstractResourceMarkerTest.assertMarkerIsNotCreated(file, AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 9);
+		AbstractResourceMarkerTest.assertMarkerIsNotCreated(file, AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 14);
+		AbstractResourceMarkerTest.assertMarkerIsNotCreated(file, AbstractResourceMarkerTest.MARKER_TYPE, CDIValidationMessages.ILLEGAL_SCOPE_FOR_PRODUCER_FIELD, 16);
+	}
 
 	/**
 	 * 3.9.1. Declaring an initializer method

Modified: trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java
===================================================================
--- trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java	2010-05-07 16:26:53 UTC (rev 21960)
+++ trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java	2010-05-07 16:35:24 UTC (rev 21961)
@@ -149,9 +149,9 @@
 	}
 
 	public static void assertMarkerIsNotCreated(IResource resource, String type, String pattern, int expectedLine) throws CoreException {
-		int line = findMarkerLine(resource, type, pattern);
+		List<Integer> lines = findMarkerLines(resource, type, pattern);
 
-		assertFalse("Marker  matches the '" + pattern + "' pattern was found", line != -1); //$NON-NLS-1$ //$NON-NLS-2$
+		assertFalse("Marker  matches the '" + pattern + "' pattern was found", lines.contains(expectedLine)); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	public static void assertMarkerIsCreated(IResource resource, String type, String pattern) throws CoreException {



More information about the jbosstools-commits mailing list