Author: akazakov
Date: 2010-05-04 10:47:34 -0400 (Tue, 04 May 2010)
New Revision: 21889
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/IProducer.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/impl/ProducerField.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.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 new CDI validation rules:
1. There is no producer method declared by the (same) bean class that is assignable to the
disposed parameter of a disposer method.
2. There are multiple disposer methods for a single producer method
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-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -232,6 +232,16 @@
Set<IBean> resolve(Set<IBean> beans);
/**
+ * Return the disposer methods which are bound to the producer method.
+ *
+ * @param producer
+ * a producer method
+ *
+ * @return bound disposer methods
+ */
+ Set<IBeanMethod> resolveDisposers(IProducerMethod producer);
+
+ /**
* Tests the given annotation type to determine if it is a scope type.
*
* @param annotationType
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IProducer.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IProducer.java 2010-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IProducer.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -17,4 +17,11 @@
*/
public interface IProducer extends IBean, IBeanMember {
+ /**
+ * Returns the @Produces annotation of this producer.
+ *
+ * @return the @Produces annotation of this producer
+ */
+ IAnnotationDeclaration getProducesAnnotation();
+
}
\ No newline at end of file
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-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -35,12 +35,14 @@
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IBeanMember;
+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.IInjectionPoint;
import org.jboss.tools.cdi.core.IObserverMethod;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IProducer;
+import org.jboss.tools.cdi.core.IProducerMethod;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
@@ -558,6 +560,11 @@
return new HashSet<IObserverMethod>();
}
+ public Set<IBeanMethod> resolveDisposers(IProducerMethod producer) {
+ // TODO
+ return new HashSet<IBeanMethod>();
+ }
+
public CDIProject getCDIProject() {
return this;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerField.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -171,4 +171,8 @@
}
return getCDIProject().getScope(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
}
+
+ public IAnnotationDeclaration getProducesAnnotation() {
+ return getDefinition().getProducesAnnotation();
+ }
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/ProducerMethod.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -211,4 +211,7 @@
return getCDIProject().getScope(CDIConstants.DEPENDENT_ANNOTATION_TYPE_NAME);
}
-}
+ public IAnnotationDeclaration getProducesAnnotation() {
+ return produces;
+ }
+}
\ 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-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -310,6 +310,32 @@
private void validateDisposers(IClassBean bean) {
Set<IBeanMethod> disposers = bean.getDisposers();
+ if(disposers.isEmpty()) {
+ return;
+ }
+
+ Set<IBeanMethod> boundDisposers = new HashSet<IBeanMethod>();
+ Set<IProducer> producers = bean.getProducers();
+ for (IProducer producer : producers) {
+ if(producer instanceof IProducerMethod) {
+ IProducerMethod producerMethod = (IProducerMethod)producer;
+ Set<IBeanMethod> disposerMethods =
producer.getCDIProject().resolveDisposers(producerMethod);
+ boundDisposers.addAll(disposerMethods);
+ if(disposerMethods.size()>1) {
+ /*
+ * 3.3.7. Disposer method resolution
+ * - there are multiple disposer methods for a single producer method
+ */
+ for (IBeanMethod disposerMethod : disposerMethods) {
+ Set<ITextSourceReference> disposerDeclarations =
getAnnotationPossitions(disposerMethod, CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ for (ITextSourceReference declaration : disposerDeclarations) {
+ addError(CDIValidationMessages.MULTIPLE_DISPOSERS_FOR_PRODUCER,
CDIPreferences.MULTIPLE_DISPOSERS_FOR_PRODUCER, declaration, bean.getResource());
+ }
+ }
+ }
+ }
+ }
+
for (IBeanMethod disposer : disposers) {
List<IParameter> params = disposer.getParameters();
@@ -399,9 +425,34 @@
addError(CDIValidationMessages.DISPOSER_IN_INTERCEPTOR,
CDIPreferences.DISPOSER_IN_INTERCEPTOR_OR_DECORATOR, declaration, bean.getResource());
}
}
+
+ /*
+ * 3.3.7. Disposer method resolution
+ * - there is no producer method declared by the (same) bean class that is assignable
to the disposed parameter of a disposer method
+ */
+ for (IBeanMethod disposerMethod : disposers) {
+ if(!boundDisposers.contains(disposerMethod)) {
+ for (ITextSourceReference declaration : disposerDeclarations) {
+ // TODO uncomment it when
https://jira.jboss.org/jira/browse/JBIDE-6252 is resolved
+// addError(CDIValidationMessages.NO_PRODUCER_MATCHING_DISPOSER,
CDIPreferences.NO_PRODUCER_MATCHING_DISPOSER, declaration, bean.getResource());
+ }
+ }
+ }
}
}
+ private Set<ITextSourceReference> getAnnotationPossitions(IBeanMethod method,
String annotationTypeName) {
+ List<IParameter> params = method.getParameters();
+ Set<ITextSourceReference> declarations = new
HashSet<ITextSourceReference>();
+ for (IParameter param : params) {
+ ITextSourceReference declaration = param.getAnnotationPosition(annotationTypeName);
+ if(declaration!=null) {
+ declarations.add(declaration);
+ }
+ }
+ return declarations;
+ }
+
/**
* If the method is not a static method and is not a business method of the session bean
and is observer or disposer then mark it as incorrect.
*
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-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -84,8 +84,8 @@
{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},
-// {CDIPreferences.MULTIPLE_DISPOSERS_FOR_PRODUCER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleDisposersForProducer_label},
+ {CDIPreferences.NO_PRODUCER_MATCHING_DISPOSER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_noProducerMatchingDisposer_label},
+ {CDIPreferences.MULTIPLE_DISPOSERS_FOR_PRODUCER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleDisposersForProducer_label},
// {CDIPreferences.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalProducerFieldInSessionBean_label},
// {CDIPreferences.MULTIPLE_INJECTION_CONSTRUCTORS,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_multipleInjectionConstructors_label},
// {CDIPreferences.CONSTRUCTOR_PARAMETER_ILLEGALLY_ANNOTATED,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_constructorParameterIllegallyAnnotated_label},
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-05-04
14:12:34 UTC (rev 21888)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-04
14:47:34 UTC (rev 21889)
@@ -240,15 +240,27 @@
/**
* 3.3.7. Disposer method resolution
- * TODO
+ * - there is no producer method declared by the (same) bean class that is assignable
to the disposed parameter of a disposer method
*
* @throws Exception
*/
public void testUnresolvedDisposalMethod() throws Exception {
- //TODO
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/disposal/method/definition/broken/unresolvedMethod/SpiderProducer_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.NO_PRODUCER_MATCHING_DISPOSER, 35);
}
-
+
/**
+ * 3.3.7. Disposer method resolution
+ * - there are multiple disposer methods for a single producer method
+ *
+ * @throws Exception
+ */
+ public void testMultipleDisposersForProducer() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/disposers/TimestampLogger_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.MULTIPLE_DISPOSERS_FOR_PRODUCER, 13, 16);
+ }
+
+ /**
* 3.9.1. Declaring an initializer method
* - an initializer method has a parameter annotated @Disposes
*