Author: akazakov
Date: 2010-11-26 11:53:55 -0500 (Fri, 26 Nov 2010)
New Revision: 26986
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/DisposerOk.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/LocalInt.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/NotBusinessMethod_Broken.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/TestInt.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/CDIUtil.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java
Log:
https://jira.jboss.org/browse/JBIDE-7733 CDI validator for EJB business method is not
aware of @LocalBean annotation. - Fixed.
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-11-26
15:58:21 UTC (rev 26985)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-11-26
16:53:55 UTC (rev 26986)
@@ -57,6 +57,7 @@
public String STATELESS_ANNOTATION_TYPE_NAME = "javax.ejb.Stateless";
public String SINGLETON_ANNOTATION_TYPE_NAME = "javax.ejb.Singleton";
public String LOCAL_ANNOTATION_TYPE_NAME = "javax.ejb.Local";
+ public String LOCAL_BEAN_ANNOTATION_TYPE_NAME = "javax.ejb.LocalBean";
public String RESOURCE_ANNOTATION_TYPE_NAME = "javax.annotation.Resource";
public String WEB_SERVICE_REF_ANNOTATION_TYPE_NAME =
"javax.xml.ws.WebServiceRef";
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-11-26
15:58:21 UTC (rev 26985)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-11-26
16:53:55 UTC (rev 26986)
@@ -12,6 +12,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -415,12 +416,14 @@
}
/**
- * Returns the @Local interface for the session bean if it is defined.
+ * Returns the set of interfaces annotated @Local for the session bean.
+ * Returns an empty set if there is no such interfaces or if the bean class (or any
supper class) annotated @LocalBean.
*
* @param bean
* @return
*/
- public static IType getLocalInterfaceForBean(ISessionBean bean) {
+ public static Set<IType> getLocalInterfaces(ISessionBean bean) {
+ Set<IType> sourceTypes = new HashSet<IType>();
try {
Set<IParametedType> types = bean.getLegalTypes();
for (IParametedType type : types) {
@@ -428,22 +431,27 @@
if (sourceType == null) {
continue;
}
- if(!sourceType.isInterface()) {
- continue;
+ // Check if the class annotated @LocalBean
+ IAnnotation[] annotations = sourceType.getAnnotations();
+ for (IAnnotation annotation : annotations) {
+ if(CDIConstants.LOCAL_BEAN_ANNOTATION_TYPE_NAME.equals(annotation.getElementName())
|| "LocalBean".equals(annotation.getElementName())) {
+ return Collections.emptySet();
+ }
}
- IAnnotation annotation =
sourceType.getAnnotation(CDIConstants.LOCAL_ANNOTATION_TYPE_NAME);
- if (annotation == null) {
- annotation = sourceType.getAnnotation("Local"); //$NON-NLS-N1
+ if(sourceType.isInterface()) {
+ IAnnotation annotation =
sourceType.getAnnotation(CDIConstants.LOCAL_ANNOTATION_TYPE_NAME);
+ if (annotation == null) {
+ annotation = sourceType.getAnnotation("Local"); //$NON-NLS-N1
+ }
+ if (annotation != null &&
CDIConstants.LOCAL_ANNOTATION_TYPE_NAME.equals(EclipseJavaUtil.resolveType(sourceType,
"Local"))) { //$NON-NLS-N1
+ sourceTypes.add(sourceType);
+ }
}
- if (annotation != null &&
CDIConstants.LOCAL_ANNOTATION_TYPE_NAME.equals(EclipseJavaUtil.resolveType(sourceType,
"Local"))) { //$NON-NLS-N1
- return sourceType;
- }
}
- return null;
} catch (JavaModelException e) {
CDICorePlugin.getDefault().logError(e);
}
- return null;
+ return sourceTypes;
}
/**
@@ -460,21 +468,23 @@
int flags = method.getMethod().getFlags();
if(Flags.isStatic(flags)) {
return method.getMethod();
- } else if (!Flags.isFinal(flags) && Flags.isPublic(flags) &&
!method.getMethod().getElementName().startsWith("ejb")) {
+ } else if (!Flags.isFinal(flags) && Flags.isPublic(flags)) {
if(bean.getAnnotation(CDIConstants.SINGLETON_ANNOTATION_TYPE_NAME)!=null) {
return method.getMethod();
}
- IType sourceType = getLocalInterfaceForBean(bean);
- if(sourceType!=null) {
+ Set<IType> sourceTypes = getLocalInterfaces(bean);
+ if(sourceTypes.isEmpty()) {
+ return method.getMethod();
+ }
+ for (IType sourceType : sourceTypes) {
IMethod[] methods = sourceType.getMethods();
for (IMethod iMethod : methods) {
if (method.getMethod().isSimilar(iMethod)) {
return iMethod;
}
}
- return null;
}
- return method.getMethod();
+ return null;
}
} catch (JavaModelException e) {
CDICorePlugin.getDefault().logError(e);
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/DisposerOk.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/DisposerOk.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/DisposerOk.java 2010-11-26
16:53:55 UTC (rev 26986)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.disposers;
+
+import javax.ejb.LocalBean;
+import javax.ejb.Stateful;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+@Stateful
+@LocalBean
+public class DisposerOk implements LocalInt {
+ @PersistenceContext EntityManager em;
+
+ @Produces
+ public EntityManager retrieveEntityManager() {
+ return em;
+ }
+
+ public void disposeEntityManager(@Disposes EntityManager em) {
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/DisposerOk.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/LocalInt.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/LocalInt.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/LocalInt.java 2010-11-26
16:53:55 UTC (rev 26986)
@@ -0,0 +1,8 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.disposers;
+
+import javax.ejb.Local;
+
+@Local
+public interface LocalInt {
+
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/LocalInt.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/NotBusinessMethod_Broken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/NotBusinessMethod_Broken.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/NotBusinessMethod_Broken.java 2010-11-26
16:53:55 UTC (rev 26986)
@@ -0,0 +1,20 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.disposers;
+
+import javax.ejb.Stateful;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+@Stateful
+public class NotBusinessMethod_Broken implements LocalInt {
+ @PersistenceContext EntityManager em;
+
+ @Produces
+ public EntityManager retrieveEntityManager() {
+ return em;
+ }
+
+ public void disposeEntityManager(@Disposes EntityManager em) {
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/NotBusinessMethod_Broken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/TestInt.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/TestInt.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/TestInt.java 2010-11-26
16:53:55 UTC (rev 26986)
@@ -0,0 +1,5 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.disposers;
+
+public interface TestInt {
+
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/TestInt.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java 2010-11-26
15:58:21 UTC (rev 26985)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java 2010-11-26
16:53:55 UTC (rev 26986)
@@ -533,6 +533,33 @@
/**
* 3.3.2. Declaring a producer method
+ * - non-static method of a session bean class is annotated @Produces, and the method
is not a business method of the session bean
+ * See
https://jira.jboss.org/browse/JBIDE-7733
+ *
+ * @throws Exception
+ */
+ public void testProducerMethodOnLocalBeanMustBeBusinessMethodBroken() throws Exception
{
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/disposers/NotBusinessMethod_Broken.java");
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{"retrieveEntityManager", "NotBusinessMethod_Broken"});
+ assertMarkerIsCreated(file, bindedErrorMessage, 13);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
+ * - non-static method of a session bean class is annotated @Produces, and the method
is not a business method of the session bean
+ * Checking @LocalBean
+ * See
https://jira.jboss.org/browse/JBIDE-7733
+ *
+ * @throws Exception
+ */
+ public void testProducerMethodOnLocalBeanMustBeBusinessMethodOk() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/disposers/DisposerOk.java");
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{"retrieveEntityManager", "DisposerOk"});
+ assertMarkerIsNotCreated(file, bindedErrorMessage, 15);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
* - decorator has a method annotated @Produces
*
* @throws Exception
@@ -649,6 +676,33 @@
/**
* 3.3.6. Declaring a disposer method
+ * - a non-static method of a session bean class has a parameter annotated @Disposes,
and the method is not a business method of the session bean
+ * See
https://jira.jboss.org/browse/JBIDE-7733
+ *
+ * @throws Exception
+ */
+ public void testDisposalMethodOnLocalBeanMustBeBusinessMethodBroken() throws Exception
{
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/disposers/NotBusinessMethod_Broken.java");
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN, new
String[]{"disposeEntityManager", "NotBusinessMethod_Broken"});
+ assertMarkerIsCreated(file, bindedErrorMessage, 18);
+ }
+
+ /**
+ * 3.3.6. Declaring a disposer method
+ * - a non-static method of a session bean class has a parameter annotated @Disposes,
and the method is not a business method of the session bean
+ * Checking @LocalBean
+ * See
https://jira.jboss.org/browse/JBIDE-7733
+ *
+ * @throws Exception
+ */
+ public void testDisposalMethodOnLocalBeanMustBeBusinessMethodOk() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/disposers/DisposerOk.java");
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN, new
String[]{"disposeEntityManager", "DisposerOk"});
+ assertMarkerIsNotCreated(file, bindedErrorMessage, 20);
+ }
+
+ /**
+ * 3.3.6. Declaring a disposer method
* - decorators may not declare disposer methods
*
* @throws Exception