Author: akazakov
Date: 2010-04-13 12:33:43 -0400 (Tue, 13 Apr 2010)
New Revision: 21452
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotated.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanMember.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.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.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/CDIPreferencesMessages.properties
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: Producer field
declaration of resource specifies EL name.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-04-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -44,4 +44,9 @@
public String STATEFUL_ANNOTATION_TYPE_NAME = "javax.ejb.Stateful";
public String STATELESS_ANNOTATION_TYPE_NAME = "javax.ejb.Stateless";
-}
+ public String RESOURCE_ANNOTATION_TYPE_NAME = "javax.annotation.Resource";
+ public String WEB_SERVICE_REF_ANNOTATION_TYPE_NAME =
"javax.xml.ws.WebServiceRef";
+ public String EJB_ANNOTATION_TYPE_NAME = "javax.ejb.EJB";
+ public String PERSISTENCE_CONTEXT_ANNOTATION_TYPE_NAME =
"javax.persistence.PersistenceContext";
+ public String PERSISTENCE_UNIT_ANNOTATION_TYPE_NAME =
"javax.persistence.PersistenceUnit";
+}
\ No newline at end of file
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotated.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotated.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotated.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.core;
+
+import java.util.List;
+
+import org.jboss.tools.cdi.internal.core.impl.AnnotationDeclaration;
+
+/**
+ * Represents a CDI element that can be annotated.
+ *
+ * @author Alexey Kazakov
+ */
+public interface IAnnotated {
+
+ /**
+ * Get all annotations of the element.
+ *
+ * @return all annotations of the element, or an empty list if no
+ * annotations are present
+ */
+ List<AnnotationDeclaration> getAnnotations();
+
+ /**
+ * Get element annotation of a certain annotation type.
+ *
+ * @param annotationTypeName
+ * the name of the annotation type
+ * @return the element annotation of the given annotation type, or a null
+ * value
+ */
+ IAnnotationDeclaration getAnnotation(String annotationTypeName);
+
+ /**
+ * Determine if the element has an annotation of a certain annotation type.
+ *
+ * @param annotationTypeName
+ * the annotation type to check for
+ * @return true if the element has an annotation of the given annotation
+ * type, or false otherwise
+ */
+ boolean isAnnotationPresent(String annotationTypeName);
+}
\ No newline at end of file
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IAnnotated.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java 2010-04-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -21,7 +21,7 @@
*
* @author Alexey Kazakov
*/
-public interface IBean extends IScoped, ICDIElement, IVariable {
+public interface IBean extends IScoped, ICDIElement, IVariable, IAnnotated {
/**
* Returns the corresponding IType of the managed bean or session bean or of
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanMember.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanMember.java 2010-04-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanMember.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -17,7 +17,7 @@
*
* @author Alexey Kazakov
*/
-public interface IBeanMember extends IJavaSourceReference {
+public interface IBeanMember extends IJavaSourceReference, IAnnotated {
/**
* Returns the class bean that declares this method.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-04-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -25,6 +25,7 @@
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IAnnotated;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IInjectionPoint;
@@ -43,7 +44,7 @@
* @author Viacheslav Kabanovich
*
*/
-public class AbstractBeanElement extends CDIElement {
+public class AbstractBeanElement extends CDIElement implements IAnnotated {
protected AbstractMemberDefinition definition;
public AbstractBeanElement() {}
@@ -56,6 +57,24 @@
return definition;
}
+ public List<AnnotationDeclaration> getAnnotations() {
+ if(definition!=null) {
+ return definition.getAnnotations();
+ }
+ return Collections.emptyList();
+ }
+
+ public IAnnotationDeclaration getAnnotation(String annotationTypeName) {
+ if(definition!=null) {
+ return definition.getAnnotation(annotationTypeName);
+ }
+ return null;
+ }
+
+ public boolean isAnnotationPresent(String annotationTypeName) {
+ return definition!=null && definition.isAnnotationPresent(annotationTypeName);
+ }
+
protected AnnotationDeclaration findNamedAnnotation() {
AnnotationDeclaration named = getDefinition().getNamedAnnotation();
if(named != null) return named;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java 2010-04-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/AbstractMemberDefinition.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -22,6 +22,7 @@
import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IAnnotated;
import org.jboss.tools.cdi.internal.core.impl.AnnotationDeclaration;
import org.jboss.tools.cdi.internal.core.impl.InterceptorBindingDeclaration;
import org.jboss.tools.cdi.internal.core.impl.QualifierDeclaration;
@@ -33,7 +34,7 @@
* @author Viacheslav Kabanovich
*
*/
-public abstract class AbstractMemberDefinition {
+public abstract class AbstractMemberDefinition implements IAnnotated {
protected List<AnnotationDeclaration> annotations = new
ArrayList<AnnotationDeclaration>();
protected IAnnotatable member;
protected Map<String, AnnotationDeclaration> annotationsByType = new
HashMap<String, AnnotationDeclaration>();
@@ -82,14 +83,30 @@
}
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IAnnotated#getAnnotations()
+ */
public List<AnnotationDeclaration> getAnnotations() {
return annotations;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IAnnotated#getAnnotation(java.lang.String)
+ */
public AnnotationDeclaration getAnnotation(String typeName) {
return annotationsByType.get(typeName);
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IAnnotated#isAnnotationPresent(java.lang.String)
+ */
+ public boolean isAnnotationPresent(String annotationTypeName) {
+ return getAnnotation(annotationTypeName)!=null;
+ }
+
public AnnotationDeclaration getNamedAnnotation() {
return annotationsByType.get(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
}
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-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -38,6 +38,8 @@
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IParametedType;
+import org.jboss.tools.cdi.core.IProducer;
+import org.jboss.tools.cdi.core.IProducerField;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
import org.jboss.tools.cdi.core.IScope;
import org.jboss.tools.cdi.core.IScopeDeclaration;
@@ -264,9 +266,34 @@
validateTyped(bean);
validateBeanScope(bean);
+ if(bean instanceof IProducer) {
+ validateProducer((IProducer)bean);
+ }
+
// TODO
}
+ private static final String[] RESOURCE_ANNOTATIONS =
{CDIConstants.RESOURCE_ANNOTATION_TYPE_NAME,
CDIConstants.WEB_SERVICE_REF_ANNOTATION_TYPE_NAME, CDIConstants.EJB_ANNOTATION_TYPE_NAME,
CDIConstants.PERSISTENCE_CONTEXT_ANNOTATION_TYPE_NAME,
CDIConstants.PERSISTENCE_UNIT_ANNOTATION_TYPE_NAME};
+
+ private void validateProducer(IProducer producer) {
+ if(producer instanceof IProducerField) {
+ IProducerField producerField = (IProducerField)producer;
+ if(producerField.getName()!=null) {
+ IAnnotationDeclaration declaration;
+ for (String annotationType : RESOURCE_ANNOTATIONS) {
+ declaration = producerField.getAnnotation(annotationType);
+ if(declaration!=null) {
+ IAnnotationDeclaration nameDeclaration =
producerField.getAnnotation(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ if(nameDeclaration!=null) {
+ declaration = nameDeclaration;
+ }
+ addError(CDIValidationMessages.RESOURCE_PRODUCER_FIELD_SETS_EL_NAME,
CDIPreferences.RESOURCE_PRODUCER_FIELD_SETS_EL_NAME, declaration,
producer.getResource());
+ }
+ }
+ }
+ }
+ }
+
/*
* 2.2.2. Restricting the bean types of a bean
* - bean class or producer method or field specifies a @Typed annotation,
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-04-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -31,7 +31,7 @@
CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_name,
new String[][]{
{CDIPreferences.STEREOTYPE_DECLARES_NON_EMPTY_NAME,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_stereotypeDeclaresNonEmptyName_label},
-// {CDIPreferences.RESOURCE_PRODUCER_FIELD_SETS_EL_NAME,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_resourceProducerFieldSetsElName_label},
+ {CDIPreferences.RESOURCE_PRODUCER_FIELD_SETS_EL_NAME,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_resourceProducerFieldSetsElName_label},
// {CDIPreferences.PARAM_INJECTION_DECLARES_EMPTY_NAME,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_paramInjectionDeclaresEmptyName_label},
// {CDIPreferences.INTERCEPTOR_HAS_NAME,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_interceptorHasName_label},
},
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.properties 2010-04-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.properties 2010-04-13
16:33:43 UTC (rev 21452)
@@ -24,7 +24,7 @@
##Section Name
CDIValidatorConfigurationBlock_section_name=Name
CDIValidatorConfigurationBlock_pb_stereotypeDeclaresNonEmptyName_label=Stereotype has
non-empty name:
-CDIValidatorConfigurationBlock_pb_resourceProducerFieldSetsElName_label=Producer field
sets EL name:
+CDIValidatorConfigurationBlock_pb_resourceProducerFieldSetsElName_label=Producer field
declaration of resource specifies EL name:
CDIValidatorConfigurationBlock_pb_paramInjectionDeclaresEmptyName_label=Empty name at
parameter injection:
CDIValidatorConfigurationBlock_pb_interceptorHasName_label=Interceptor declares name:
CDIValidatorConfigurationBlock_pb_decoratorHasName_label=Decorator declares name:
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-13
15:39:57 UTC (rev 21451)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-13
16:33:43 UTC (rev 21452)
@@ -37,11 +37,7 @@
*/
public void testResourceWithELName() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/resources/ProducerFieldsBroken.java");
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Producer field declaration of Java EE
resource specifies an EL name", 15);
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Producer field declaration of Java EE
resource specifies an EL name", 19);
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Producer field declaration of Java EE
resource specifies an EL name", 23);
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Producer field declaration of Java EE
resource specifies an EL name", 27);
- AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Producer field declaration of Java EE
resource specifies an EL name", 31);
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE, "Producer field declaration of Java EE
resource specifies an EL name", 15, 19, 23, 27, 31);
}
public void testLegalTypesInTyped() throws Exception {