Author: scabanovich
Date: 2010-07-20 09:03:35 -0400 (Tue, 20 Jul 2010)
New Revision: 23590
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/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-6637
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-07-20
12:28:02 UTC (rev 23589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java 2010-07-20
13:03:35 UTC (rev 23590)
@@ -78,6 +78,9 @@
// 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$
+
//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/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-07-20
12:28:02 UTC (rev 23589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-07-20
13:03:35 UTC (rev 23590)
@@ -1796,8 +1796,77 @@
* - array-valued or annotation-valued member of a qualifier type is not annotated
@Nonbinding (Non-Portable behavior)
*/
validateAnnotationMembers(qualifier,
CDIValidationMessages.MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_QUALIFIER_TYPE_MEMBER,
CDIValidationMessages.MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_QUALIFIER_TYPE_MEMBER,
CDIPreferences.MISSING_NONBINDING_IN_QUALIFIER_TYPE_MEMBER);
+
+ /*
+ * Qualifier annotation type should be annotated with @Target({METHOD, FIELD,
PARAMETER, TYPE})
+ */
+ try {
+ validateQualifierAnnotationTypeAnnotations(qualifier, resource);
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
}
+ private void validateQualifierAnnotationTypeAnnotations(IQualifier qualifier, IResource
resource) throws JavaModelException {
+ /*
+ * Qualifier annotation type should be annotated with @Target({METHOD, FIELD,
PARAMETER, TYPE})
+ * Qualifier annotation type should be annotated with @Retention(RUNTIME)
+ */
+ IAnnotationDeclaration target =
qualifier.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);
+ } else {
+ IMemberValuePair[] ps = target.getDeclaration().getMemberValuePairs();
+ boolean ok = false;
+ for (IMemberValuePair p: ps) {
+ if(!"value".equals(p.getMemberName())) continue;
+ Object o = p.getValue();
+ if(o instanceof Object[]) {
+ ok = true;
+ Object[] os = (Object[])o;
+ Set<String> vs = new HashSet<String>();
+ for (Object q: os) {
+ String s = q.toString();
+ int i = s.lastIndexOf('.');
+ if(i >= 0) s = s.substring(i + 1);
+ vs.add(s);
+ }
+ for (String s: new String[]{"TYPE", "METHOD", "FIELD",
"PARAMETER"}) {
+ if(!vs.contains(s)) ok = false;
+ }
+ }
+ }
+ if(!ok) {
+ addError(CDIValidationMessages.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE,
CDIPreferences.MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE, target, resource);
+ }
+ }
+
+ /*
+ * Qualifier annotation type should be annotated with @Retention(RUNTIME)
+ */
+ IAnnotationDeclaration retention =
qualifier.getAnnotationDeclaration(CDIConstants.RETENTION_ANNOTATION_TYPE_NAME);
+ if(retention == null) {
+ addError(CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE,
CDIPreferences.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE,
CDIUtil.convertToSourceReference(qualifier.getSourceType().getNameRange()), resource);
+ } else {
+ IMemberValuePair[] ps = retention.getDeclaration().getMemberValuePairs();
+ boolean ok = false;
+ for (IMemberValuePair p: ps) {
+ if(!"value".equals(p.getMemberName())) continue;
+ Object o = p.getValue();
+ if(o != null) {
+ ok = true;
+ String s = o.toString();
+ int i = s.lastIndexOf('.');
+ if(i >= 0) s = s.substring(i + 1);
+ if(!"RUNTIME".equals(s)) ok = false;
+ }
+ }
+ if(!ok) {
+ addError(CDIValidationMessages.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE,
CDIPreferences.MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE, retention, resource);
+ }
+ }
+ }
+
private void validateInterceptorBinding(IInterceptorBinding binding) {
if(binding==null) {
return;
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-07-20
12:28:02 UTC (rev 23589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-07-20
13:03:35 UTC (rev 23590)
@@ -42,6 +42,8 @@
public static String MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_QUALIFIER_TYPE_MEMBER;
public static String
MISSING_NONBINDING_FOR_ANNOTATION_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER;
public static String
MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_INTERCEPTOR_BINDING_TYPE_MEMBER;
+ public static String MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE;
+ public static String MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE;
public static String MULTIPLE_SCOPE_TYPE_ANNOTATIONS;
public static String MISSING_SCOPE_WHEN_THERE_IS_NO_DEFAULT_SCOPE;
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-07-20
12:28:02 UTC (rev 23589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-07-20
13:03:35 UTC (rev 23590)
@@ -21,6 +21,8 @@
MISSING_NONBINDING_FOR_ARRAY_VALUE_IN_QUALIFIER_TYPE_MEMBER=Array-valued member of a
qualifier type should 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 should 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 should be annotated @Nonbinding [JSR-299 �9.5.2]
+MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE=Qualifier annotation type should be annotated
with @Target('{'METHOD, FIELD, PARAMETER, TYPE'}')
+MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE=Qualifier annotation type should be
annotated with @Retention(RUNTIME)
MULTIPLE_SCOPE_TYPE_ANNOTATIONS=Bean class or producer method or field specifies multiple
scope type annotations
MISSING_SCOPE_WHEN_THERE_IS_NO_DEFAULT_SCOPE=Bean does not explicitly declare a scope
when there is no default scope