Author: scabanovich
Date: 2010-07-21 05:45:17 -0400 (Wed, 21 Jul 2010)
New Revision: 23625
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-6642
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-21
09:12:07 UTC (rev 23624)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java 2010-07-21
09:45:17 UTC (rev 23625)
@@ -80,7 +80,10 @@
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_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/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-07-21
09:12:07 UTC (rev 23624)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-07-21
09:45:17 UTC (rev 23625)
@@ -1789,8 +1789,95 @@
addError(CDIValidationMessages.STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE,
CDIPreferences.STEREOTYPE_DECLARES_MORE_THAN_ONE_SCOPE, scope, stereotype.getResource());
}
}
+
+ try {
+ validateStereotypeAnnotationTypeAnnotations(stereotype, resource);
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
}
+ private void validateStereotypeAnnotationTypeAnnotations(IStereotype stereotype,
IResource resource) throws JavaModelException {
+ /*
+ * 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);
+ }
+ }
+
+ /*
+ * 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);
+ }
+
+ void validateRetentionAnnotation(ICDIAnnotation type, String message, String preference,
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);
+ } 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(message, preference, retention, resource);
+ }
+ }
+ }
+
+ Set<String> getTargetAnnotationValues(IAnnotationDeclaration target) throws
JavaModelException {
+ Set<String> result = new HashSet<String>();
+ IMemberValuePair[] ps = target.getDeclaration().getMemberValuePairs();
+ for (IMemberValuePair p: ps) {
+ if(!"value".equals(p.getMemberName())) continue;
+ Object o = p.getValue();
+ if(o instanceof Object[]) {
+ Object[] os = (Object[])o;
+ for (Object q: os) {
+ String s = q.toString();
+ int i = s.lastIndexOf('.');
+ if(i >= 0) s = s.substring(i + 1);
+ result.add(s);
+ }
+ } else if(o != null) {
+ String s = o.toString();
+ int i = s.lastIndexOf('.');
+ if(i >= 0) s = s.substring(i + 1);
+ result.add(s);
+ }
+ }
+ return result;
+ }
+
+
/**
* Validates a qualifier.
*
@@ -1830,25 +1917,10 @@
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;
- }
- }
+ Set<String> vs = getTargetAnnotationValues(target);
+ boolean ok = vs.size() == 4;
+ if(ok) 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);
@@ -1858,27 +1930,7 @@
/*
* 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);
- }
- }
+ 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-07-21
09:12:07 UTC (rev 23624)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-07-21
09:45:17 UTC (rev 23625)
@@ -47,6 +47,8 @@
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 MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE;
+ public static String MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_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-07-21
09:12:07 UTC (rev 23624)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-07-21
09:45:17 UTC (rev 23625)
@@ -24,8 +24,10 @@
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)
+MISSING_TARGET_ANNOTATION_IN_QUALIFIER_TYPE=Qualifier annotation type should be annotated
with @Target('{'METHOD, FIELD, PARAMETER, TYPE'}') [JSR-299 �2.3.2]
+MISSING_RETENTION_ANNOTATION_IN_QUALIFIER_TYPE=Qualifier annotation type should be
annotated with @Retention(RUNTIME) [JSR-299 �2.3.2]
+MISSING_TARGET_ANNOTATION_IN_STEREOTYPE_TYPE=Stereotype annotation type should be
annotated with @Target with correct targets [JSR-299 �2.7.1]
+MISSING_RETENTION_ANNOTATION_IN_STEREOTYPE_TYPE=Stereotype annotation type should be
annotated with @Retention(RUNTIME) [JSR-299 �2.7.1]
MULTIPLE_SCOPE_TYPE_ANNOTATIONS=Bean class or producer method or field specifies multiple
scope type annotations
MULTIPLE_SCOPE_TYPE_ANNOTATIONS_IN_BEAN_CLASS=Bean class specifies multiple scope type
annotations