[jbosstools-commits] JBoss Tools SVN: r23910 - in trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi: core/preferences and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Aug 4 06:31:31 EDT 2010


Author: scabanovich
Date: 2010-08-04 06:31:29 -0400 (Wed, 04 Aug 2010)
New Revision: 23910

Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.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/CDIValidationMessages.java
   trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
Log:
https://jira.jboss.org/browse/JBIDE-6639

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java	2010-08-04 08:19:49 UTC (rev 23909)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java	2010-08-04 10:31:29 UTC (rev 23910)
@@ -251,6 +251,13 @@
 	IScope getScope(String qualifiedName);
 
 	/**
+	 * Returns the scope by resource path.
+	 * 
+	 * @param resource path
+	 * @return the scope by resource path
+	 */
+	IScope getScope(IPath path);
+	/**
 	 * Returns the set of observers for an event which is injected by given
 	 * injection point.
 	 * 

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java	2010-08-04 08:19:49 UTC (rev 23909)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java	2010-08-04 10:31:29 UTC (rev 23910)
@@ -74,12 +74,8 @@
 //	  is not annotated @Nonbinding (9.5.2 non-portable)
 	public static final String MISSING_NONBINDING_IN_INTERCEPTOR_BINDING_TYPE_MEMBER = INSTANCE.createSeverityOption("missingNonbindingInInterceptorBindingTypeMember"); //$NON-NLS-1$
 
-	public static final String MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE = INSTANCE.createSeverityOption("missingTargetAnnotationInQualifierType"); //$NON-NLS-1$
-	public static final String MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE = INSTANCE.createSeverityOption("missingRetentionAnnotationInQualifierType"); //$NON-NLS-1$
+	public static final String MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE = INSTANCE.createSeverityOption("missingOrIncorrectTargetOrRetentionInAnnotationType"); //$NON-NLS-1$
 
-	public static final String MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE = INSTANCE.createSeverityOption("missingTargetAnnotationInStereotypeType"); //$NON-NLS-1$
-	public static final String MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE = INSTANCE.createSeverityOption("missingRetentionAnnotationInStereotypeType"); //$NON-NLS-1$
-
 	//Scope group
 
 //	- bean class or producer method or field specifies multiple scope type annotations (2.4.3)

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2010-08-04 08:19:49 UTC (rev 23909)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java	2010-08-04 10:31:29 UTC (rev 23910)
@@ -51,6 +51,7 @@
 import org.jboss.tools.cdi.core.IProducerMethod;
 import org.jboss.tools.cdi.core.IQualifier;
 import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.cdi.core.IScope;
 import org.jboss.tools.cdi.core.IStereotype;
 import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
 import org.jboss.tools.cdi.internal.core.impl.definition.BeansXMLDefinition;
@@ -74,6 +75,7 @@
 	private Map<String, QualifierElement> qualifiers = new HashMap<String, QualifierElement>();
 	private Map<IPath, QualifierElement> qualifiersByPath = new HashMap<IPath, QualifierElement>();
 	private Map<String, ScopeElement> scopes = new HashMap<String, ScopeElement>();
+	private Map<IPath, ScopeElement> scopesByPath = new HashMap<IPath, ScopeElement>();
 
 	private Set<IBean> allBeans = new HashSet<IBean>();
 	private Map<IPath, Set<IBean>> beansByPath = new HashMap<IPath, Set<IBean>>();
@@ -914,6 +916,10 @@
 		return scopes.get(qualifiedName);
 	}
 
+	public IScope getScope(IPath path) {
+		return scopesByPath.get(path);
+	}
+
 	public void update() {
 		rebuildXML();
 		rebuildAnnotationTypes();
@@ -928,6 +934,7 @@
 		qualifiersByPath.clear();
 		interceptorBindingsByPath.clear();
 		scopes.clear();
+		scopesByPath.clear();
 		List<AnnotationDefinition> ds = n.getDefinitions().getAllAnnotations();
 		for (AnnotationDefinition d: ds) {
 			if(d.getKind() == AnnotationDefinition.STEREOTYPE) {
@@ -948,7 +955,6 @@
 				QualifierElement s = new QualifierElement();
 				initAnnotationElement(s, d);
 				qualifiers.put(d.getQualifiedName(), s);
-				System.out.println(d.getQualifiedName());
 				if(d.getResource() != null && d.getResource().getFullPath() != null) {
 					qualifiersByPath.put(d.getResource().getFullPath(), s);
 				}
@@ -956,6 +962,9 @@
 				ScopeElement s = new ScopeElement();
 				initAnnotationElement(s, d);
 				scopes.put(d.getQualifiedName(), s);
+				if(d.getResource() != null && d.getResource().getFullPath() != null) {
+					scopesByPath.put(d.getResource().getFullPath(), s);
+				}
 			}
 		}
 	}

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-08-04 08:19:49 UTC (rev 23909)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java	2010-08-04 10:31:29 UTC (rev 23910)
@@ -279,6 +279,11 @@
 		for (IInterceptorBinding binding : bindings) {
 			validateInterceptorBinding(binding);
 		}
+		
+		Set<String> scopes = cdiProject.getScopeNames();
+		for (String scope: scopes) {
+			validateScopeType(cdiProject.getScope(scope));
+		}
 		return OK_STATUS;
 	}
 
@@ -301,6 +306,9 @@
 
 		IQualifier qualifier = cdiProject.getQualifier(file.getFullPath());
 		validateQualifier(qualifier);
+		
+		IScope scope = cdiProject.getScope(file.getFullPath());
+		validateScopeType(scope);
 
 		IInterceptorBinding binding = cdiProject.getInterceptorBinding(file.getFullPath());
 		validateInterceptorBinding(binding);
@@ -1809,37 +1817,58 @@
 		 * Stereotype annotation type should be annotated with @Target with correct targets [JSR-299 §2.7.1]
 		 * Stereotype annotation type should be annotated with @Retention(RUNTIME)
 		 */
-		IAnnotationDeclaration target = stereotype.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
-		if(target == null) {
-			addError(CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, CDIPreferences.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, CDIUtil.convertToSourceReference(stereotype.getSourceType().getNameRange()), resource);
-		} else {
-			boolean ok = false;
-			Set<String> vs = getTargetAnnotationValues(target);
-			boolean hasType = vs.contains("TYPE");
-			boolean hasMethod = vs.contains("METHOD");
-			boolean hasField = vs.contains("FIELD");
-			if(vs.size() == 3) {
-				ok = hasType && hasMethod && hasField;
-			} else if(vs.size() == 2) {
-				ok = hasMethod && hasField;
-			} else if(vs.size() == 1) {
-				ok = hasType || hasMethod || hasField;
-			}
-			if(!ok) {
-				addError(CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, CDIPreferences.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, target, resource);
-			}
-		}
+		String[][] variants = {{TARGET_METHOD, TARGET_FIELD, TARGET_TYPE}, 
+					           {TARGET_METHOD, TARGET_FIELD},
+					           {TARGET_TYPE}, {TARGET_METHOD}, {TARGET_FIELD}};
+		validateTargetAnnotation(stereotype, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
 		
 		/*
 		 * Stereotype annotation type should be annotated with @Retention(RUNTIME)
 		 */
-		validateRetentionAnnotation(stereotype, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE, CDIPreferences.MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
+		validateRetentionAnnotation(stereotype, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE, resource);
 	}
 
-	void validateRetentionAnnotation(ICDIAnnotation type, String message, String preference, IResource resource) throws JavaModelException {
+	/**
+	 * Validates a qualifier.
+	 * 
+	 * @param qualifier
+	 */
+	private void validateScopeType(IScope scope) {
+		if(scope == null) {
+			return;
+		}
+		IResource resource = scope.getResource();
+		if (resource == null || !resource.getName().toLowerCase().endsWith(".java")) {
+			// validate sources only
+			return;
+		}
+
+		try {
+			validateScopeAnnotationTypeAnnotations(scope, resource);
+		} catch (JavaModelException e) {
+			CDICorePlugin.getDefault().logError(e);
+		}
+	}
+	
+	private void validateScopeAnnotationTypeAnnotations(IScope scope, IResource resource) throws JavaModelException {
+		/*
+		 * Scope annotation type should be annotated with @Target({TYPE, METHOD, FIELD})
+		 */
+		String[][] variants = {{TARGET_TYPE, TARGET_METHOD, TARGET_FIELD}};
+		validateTargetAnnotation(scope, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE, resource);
+		
+		/*
+		 * Scope annotation type should be annotated with @Retention(RUNTIME)
+		 */
+		validateRetentionAnnotation(scope, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_SCOPE_TYPE, resource);
+	}
+
+
+
+	void validateRetentionAnnotation(ICDIAnnotation type, String message, IResource resource) throws JavaModelException {
 		IAnnotationDeclaration retention = type.getAnnotationDeclaration(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME);
 		if(retention == null) {
-			addError(message, preference, CDIUtil.convertToSourceReference(type.getSourceType().getNameRange()), resource);
+			addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, CDIUtil.convertToSourceReference(type.getSourceType().getNameRange()), resource);
 		} else {
 			IMemberValuePair[] ps = retention.getDeclaration().getMemberValuePairs();
 			boolean ok = false;
@@ -1855,7 +1884,7 @@
 				}
 			}
 			if(!ok) {
-				addError(message, preference, retention, resource);
+				addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, retention, resource);
 			}
 		}
 	}
@@ -1914,35 +1943,55 @@
 			CDICorePlugin.getDefault().logError(e);
 		}
 	}
+	
+	static String TARGET_METHOD = "METHOD";
+	static String TARGET_FIELD = "FIELD";
+	static String TARGET_PARAMETER = "PARAMETER";
+	static String TARGET_TYPE = "TYPE";
 
 	private void validateQualifierAnnotationTypeAnnotations(IQualifier qualifier, IResource resource) throws JavaModelException {
 		/*
 		 * Qualifier annotation type should be annotated with @Target({METHOD, FIELD, PARAMETER, TYPE}) or  @Target({"FIELD", "PARAMETER"})
 		 * Qualifier annotation type should be annotated with @Retention(RUNTIME)
 		 */
-		IAnnotationDeclaration target = qualifier.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
+		String[][] variants = {{TARGET_METHOD, TARGET_FIELD, TARGET_PARAMETER, TARGET_TYPE}, 
+				               {TARGET_FIELD, TARGET_PARAMETER}};
+		validateTargetAnnotation(qualifier, variants, CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, resource);
+		
+		/*
+		 * Qualifier annotation type should be annotated with @Retention(RUNTIME)
+		 */
+		validateRetentionAnnotation(qualifier, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE, resource);
+	}
+
+	private void validateTargetAnnotation(ICDIAnnotation annotationType, String[][] variants, String message, IResource resource) throws JavaModelException {
+		IAnnotationDeclaration target = annotationType.getAnnotationDeclaration(CDIConstants.TARGET_ANNOTATION_TYPE_NAME);
 		if(target == null) {
-			addError(CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, CDIPreferences.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, CDIUtil.convertToSourceReference(qualifier.getSourceType().getNameRange()), resource);
+			addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, CDIUtil.convertToSourceReference(annotationType.getSourceType().getNameRange()), resource);
 		} else {
 			Set<String> vs = getTargetAnnotationValues(target);
-			boolean ok = vs.size() == 4 || vs.size() == 2;
-			if(ok) {
-				String[] values = (vs.size() == 4) 
-					? new String[]{"TYPE", "METHOD", "FIELD", "PARAMETER"} 
-					: new String[]{"FIELD", "PARAMETER"};
-				for (String s: values) {
-					if(!vs.contains(s)) ok = false;
+			boolean ok = false;
+			for (int i = 0; i < variants.length; i++) {
+				if(vs.size() == variants[i].length) {
+					boolean ok2 = true;
+					String[] values = variants[i];
+					for (String s: values) {
+						if(!vs.contains(s)) {
+							ok2 = false;
+							break;
+						}
+					}
+					if(ok2) {
+						ok = true;
+						break;
+					}
 				}
 			}
 			if(!ok) {
-				addError(CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, CDIPreferences.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, target, resource);
+				addError(message, CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE, target, resource);
 			}
 		}
 		
-		/*
-		 * Qualifier annotation type should be annotated with @Retention(RUNTIME)
-		 */
-		validateRetentionAnnotation(qualifier, CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE, CDIPreferences.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE, resource);
 	}
 
 	private void validateInterceptorBinding(IInterceptorBinding binding) {

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java	2010-08-04 08:19:49 UTC (rev 23909)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java	2010-08-04 10:31:29 UTC (rev 23910)
@@ -47,6 +47,8 @@
 	public static String MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE;
 	public static String MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE;
 	public static String MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE;
+	public static String MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE;
+	public static String MISSING_RETENTION_ANNOTATION_IN_SCOPE_TYPE;
 
 	public static String MULTIPLE_SCOPE_TYPE_ANNOTATIONS;
 	public static String MULTIPLE_SCOPE_TYPE_ANNOTATIONS_IN_BEAN_CLASS;

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties	2010-08-04 08:19:49 UTC (rev 23909)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties	2010-08-04 10:31:29 UTC (rev 23910)
@@ -23,10 +23,12 @@
 MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_QUALIFIER_TYPE_MEMBER=Array-valued member of a qualifier type must be annotated @Nonbinding [JSR-299 §5.2.5]
 MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER=Annotation-valued member of an interceptor binding type must be annotated @Nonbinding [JSR-299 §9.5.2]
 MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER=Array-valued member of an interceptor binding type must be annotated @Nonbinding [JSR-299 §9.5.2]
-MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE=Qualifier annotation type must be annotated with @Target('{'METHOD, FIELD, PARAMETER, TYPE'}') [JSR-299 §2.3.2]
+MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE=Qualifier annotation type must be annotated with correct targets [JSR-299 §2.3.2, §10.1]
 MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE=Qualifier annotation type must be annotated with @Retention(RUNTIME) [JSR-299 §2.3.2]
 MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE=Stereotype annotation type must be annotated with @Target with correct targets [JSR-299 §2.7.1]
 MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE=Stereotype annotation type must be annotated with @Retention(RUNTIME) [JSR-299 §2.7.1]
+MISSING_TARGET_ANNOTATION_IN_SCOPE_TYPE=Scope annotation type must be annotated with @Target with correct targets [JSR-299 §2.4.2]
+MISSING_RETENTION_ANNOTATION_IN_SCOPE_TYPE=Scope annotation type must be annotated with @Retention(RUNTIME) [JSR-299 §2.4.2]
 
 MULTIPLE_SCOPE_TYPE_ANNOTATIONS=Bean class or producer method or field specifies multiple scope type annotations [JSR-299 §2.4.3]
 MULTIPLE_SCOPE_TYPE_ANNOTATIONS_IN_BEAN_CLASS=Bean class specifies multiple scope type annotations [JSR-299 §2.4.3]



More information about the jbosstools-commits mailing list