Author: akazakov
Date: 2010-04-16 09:18:48 -0400 (Fri, 16 Apr 2010)
New Revision: 21531
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/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
Log:
https://jira.jboss.org/jira/browse/JBIDE-2708 Added tests for disposing method
validation.
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-16
13:05:56 UTC (rev 21530)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-04-16
13:18:48 UTC (rev 21531)
@@ -49,4 +49,6 @@
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";
+
+ public String DISPOSES_ANNOTATION_TYPE_NAME =
"javax.enterprise.inject.Disposes";
}
\ No newline at end of file
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-16
13:05:56 UTC (rev 21530)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-16
13:18:48 UTC (rev 21531)
@@ -36,12 +36,15 @@
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.IBeanMethod;
import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IDecorator;
import org.jboss.tools.cdi.core.IInjectionPoint;
import org.jboss.tools.cdi.core.IInjectionPointField;
import org.jboss.tools.cdi.core.IInterceptor;
import org.jboss.tools.cdi.core.IParametedType;
+import org.jboss.tools.cdi.core.IParameter;
import org.jboss.tools.cdi.core.IProducer;
import org.jboss.tools.cdi.core.IProducerField;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
@@ -288,9 +291,39 @@
validateDecorator((IDecorator)bean);
}
+ if(bean instanceof IClassBean) {
+ validateClassBean((IClassBean)bean);
+ }
+
// TODO
}
+ private void validateClassBean(IClassBean bean) {
+ Set<IBeanMethod> disposers = bean.getDisposers();
+ /*
+ * 3.3.6. Declaring a disposer method
+ * - method has more than one parameter annotated @Disposes
+ */
+ for (IBeanMethod dssposer : disposers) {
+ List<IParameter> params = dssposer.getParameters();
+ if(params.size()<2) {
+ continue;
+ }
+ Set<IAnnotationDeclaration> declarations = new
HashSet<IAnnotationDeclaration>();
+ for (IParameter param : params) {
+ IAnnotationDeclaration declaration =
param.getAnnotation(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ if(declaration!=null) {
+ declarations.add(declaration);
+ }
+ }
+ if(declarations.size()>1) {
+ for (IAnnotationDeclaration declaration : declarations) {
+ addError(CDIValidationMessages.MULTIPLE_DISPOSING_PARAMETERS,
CDIPreferences.MULTIPLE_DISPOSING_PARAMETERS, declaration, bean.getResource());
+ }
+ }
+ }
+ }
+
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) {
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-16
13:05:56 UTC (rev 21530)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-04-16
13:18:48 UTC (rev 21531)
@@ -73,15 +73,15 @@
CDICorePlugin.PLUGIN_ID
);
-// private static SectionDescription SECTION_MEMBER = new SectionDescription(
-// CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_member,
-// new String[][]{
+ private static SectionDescription SECTION_MEMBER = new SectionDescription(
+ CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_member,
+ new String[][]{
// {CDIPreferences.PRODUCER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerAnnotatedInject_label},
// {CDIPreferences.PRODUCER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_producerParameterIllegallyAnnotated_label},
// {CDIPreferences.OBSERVER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerAnnotatedInject_label},
// {CDIPreferences.OBSERVER_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_observerParameterIllegallyAnnotated_label},
// {CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalProducerMethodInSessionBean_label},
-// {CDIPreferences.MULTIPLE_DISPOSING_PARAMETERS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleDisposingParameters_label},
+ {CDIPreferences.MULTIPLE_DISPOSING_PARAMETERS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleDisposingParameters_label},
// {CDIPreferences.DISPOSER_ANNOTATED_INJECT,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_disposerAnnotatedInject_label},
// {CDIPreferences.ILLEGAL_DISPOSER_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalDisposerInSessionBean_label},
// {CDIPreferences.NO_PRODUCER_MATCHING_DISPOSER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_noProducerMatchingDisposer_label},
@@ -93,9 +93,9 @@
// {CDIPreferences.MULTIPLE_OBSERVING_PARAMETERS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleObservingParameters_label},
// {CDIPreferences.ILLEGAL_OBSERVER_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalObserverInSessionBean_label},
// {CDIPreferences.ILLEGAL_CONDITIONAL_OBSERVER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalConditionalObserver_label},
-// },
-// CDICorePlugin.PLUGIN_ID
-// );
+ },
+ CDICorePlugin.PLUGIN_ID
+ );
// private static SectionDescription SECTION_INTERCEPTOR = new SectionDescription(
// CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_interceptor_and_decorator,
@@ -147,7 +147,7 @@
SECTION_NAME,
SECTION_TYPE,
SECTION_SCOPE,
-// SECTION_MEMBER,
+ SECTION_MEMBER,
// SECTION_INTERCEPTOR,
// SECTION_SPECIALIZATION,
SECTION_MISCELLANEOUS
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-16
13:05:56 UTC (rev 21530)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-16
13:18:48 UTC (rev 21531)
@@ -22,6 +22,8 @@
/**
* 2.7.1.3. Stereotype declares a non-empty @Named annotation (Non-Portable behavior)
+ *
+ * @throws Exception
*/
public void testNonEmptyNamedForStereotype() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/stereotype/broken/nonEmptyNamed/StereotypeWithNonEmptyNamed_Broken.java");
@@ -83,6 +85,8 @@
* - bean class or producer method or field specifies a @Typed annotation,
* and the value member specifies a class which does not correspond to a type
* in the unrestricted set of bean types of a bean
+ *
+ * @throws Exception
*/
public void testLegalTypesInTyped() throws Exception {
IFile petShopFile =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/lookup/typesafe/resolution/PetShop.java");
@@ -93,6 +97,8 @@
/**
* 2.7.1.3. Stereotype declares any other qualifier annotation
+ *
+ * @throws Exception
*/
public void testAnnotatedStereotype() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/stereotype/broken/withBindingType/StereotypeWithBindingTypes_Broken.java");
@@ -103,6 +109,8 @@
/**
* 2.7.1.3. Stereotype is annotated @Typed
+ *
+ * @throws Exception
*/
public void testTypedStereotype() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/stereotype/broken/withBindingType/StereotypeWithTyped_Broken.java");
@@ -114,6 +122,8 @@
/**
* 2.7.1.1. Declaring the default scope for a stereotype
* - stereotype declares more than one scope
+ *
+ * @throws Exception
*/
public void testStereotypeScope() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/stereotype/broken/tooManyScopes/StereotypeWithTooManyScopeTypes_Broken.java");
@@ -125,6 +135,8 @@
/**
* 2.4.3. Declaring the bean scope
* - bean class or producer method or field specifies multiple scope type
annotations
+ *
+ * @throws Exception
*/
public void testMultipleBeanScope() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/scope/broken/tooManyScopes/BeanWithTooManyScopeTypes_Broken.java");
@@ -137,6 +149,8 @@
* 2.4.4. Default scope
* - bean does not explicitly declare a scope when there is no default scope
* (there are two different stereotypes declared by the bean that declare
different default scopes)
+ *
+ * @throws Exception
*/
public void testBeanWithMultipleScopedStereotypes() throws Exception {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/stereotype/broken/scopeConflict/Scallop_Broken.java");
@@ -145,6 +159,17 @@
assertEquals("Scallop_Broken.java should has two error markers.",
markerNumbers, 2);
}
+ /**
+ * 3.3.6. Declaring a disposer method
+ * - method has more than one parameter annotated @Disposes
+ *
+ * @throws Exception
+ */
+ public void testMultipleDisposeParameters() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/disposal/method/definition/broken/multiParams/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.MULTIPLE_DISPOSING_PARAMETERS, 30, 30);
+ }
+
public static int getMarkersNumber(IResource resource) {
return AbstractResourceMarkerTest.getMarkersNumberByGroupName(resource, null);
}