Author: akazakov
Date: 2010-11-23 08:47:38 -0500 (Tue, 23 Nov 2010)
New Revision: 26837
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/WidgetRepositoryProducerOk.java
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/internal/core/validation/CDICoreValidator.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-7710
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-23
12:25:58 UTC (rev 26836)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-11-23
13:47:38 UTC (rev 26837)
@@ -410,54 +410,76 @@
* @param method
* @return
*/
- public static boolean isBusinessMethod(ISessionBean bean, IBeanMethod method) {
+ public static boolean isBusinessOrStaticMethod(ISessionBean bean, IBeanMethod method) {
return getBusinessMethodDeclaration(bean, method)!=null;
}
/**
- * Returns IMethod of @Local interface which is implemented by given business method.
- * Returns null if the method is a non-static method of the session bean class, and the
method is not a business method of the session bean.
- * If the method is a static one then returns this method.
+ * Returns the @Local interface for the session bean if it is defined.
*
* @param bean
+ * @return
+ */
+ public static IType getLocalInterfaceForBean(ISessionBean bean) {
+ try {
+ Set<IParametedType> types = bean.getLegalTypes();
+ for (IParametedType type : types) {
+ IType sourceType = type.getType();
+ if (sourceType == null) {
+ continue;
+ }
+ if(!sourceType.isInterface()) {
+ continue;
+ }
+ 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
+ return sourceType;
+ }
+ }
+ return null;
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ return null;
+ }
+
+ /**
+ * Returns IMethod of @Local interface which is implemented by given business method if
such an interface is defined.
+ * If such an interface is not define then return then check if the method is static or
public, not final and doesn't start with "ejb".
+ * If so then return this method, otherwise return null.
+ *
+ * @param bean
* @param method
* @return
*/
public static IMethod getBusinessMethodDeclaration(ISessionBean bean, IBeanMethod
method) {
try {
- if (!Flags.isStatic(method.getMethod().getFlags())) {
+ 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")) {
if(bean.getAnnotation(CDIConstants.SINGLETON_ANNOTATION_TYPE_NAME)!=null) {
return method.getMethod();
}
- Set<IParametedType> types = bean.getLegalTypes();
- for (IParametedType type : types) {
- IType sourceType = type.getType();
- if (sourceType == null) {
- continue;
- }
- if(!sourceType.isInterface()) {
- continue;
- }
- 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
- IMethod[] methods = sourceType.getMethods();
- for (IMethod iMethod : methods) {
- if (method.getMethod().isSimilar(iMethod)) {
- return iMethod;
- }
+ IType sourceType = getLocalInterfaceForBean(bean);
+ if(sourceType!=null) {
+ IMethod[] methods = sourceType.getMethods();
+ for (IMethod iMethod : methods) {
+ if (method.getMethod().isSimilar(iMethod)) {
+ return iMethod;
}
- break;
}
+ return null;
}
- return null;
+ return method.getMethod();
}
} catch (JavaModelException e) {
CDICorePlugin.getDefault().logError(e);
}
- return method.getMethod();
+ return null;
}
/**
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-11-23
12:25:58 UTC (rev 26836)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-11-23
13:47:38 UTC (rev 26837)
@@ -879,7 +879,7 @@
String bindedErrorMessage = NLS.bind(errorMessage, new
String[]{method.getMethod().getElementName(), bean.getBeanClass().getElementName()});
addError(bindedErrorMessage, preferencesKey, declaration, bean.getResource());
}
- } else {
+ } else if (iMethod != method.getMethod()) {
getValidationContext().addLinkedCoreResource(bean.getSourcePath().toOSString(),
iMethod.getResource().getFullPath(), false);
}
}
@@ -1053,7 +1053,7 @@
String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{producerMethod.getMethod().getElementName(),
producer.getBeanClass().getElementName()});
addError(bindedErrorMessage,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource());
saveAllSuperTypesAsLinkedResources(classBean);
- } else {
+ } else if (method != producerMethod.getMethod()) {
getValidationContext().addLinkedCoreResource(classBean.getSourcePath().toOSString(),
method.getResource().getFullPath(), false);
}
}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/WidgetRepositoryProducerOk.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/WidgetRepositoryProducerOk.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/disposers/WidgetRepositoryProducerOk.java 2010-11-23
13:47:38 UTC (rev 26837)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.jbt.validation.disposers;
+
+import javax.ejb.Stateless;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+@Stateless
+public class WidgetRepositoryProducerOk {
+ // NOTE cannot use producer field because Weld attempts to close EntityManager
+ @PersistenceContext EntityManager em;
+
+ public @Produces 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/WidgetRepositoryProducerOk.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-23
12:25:58 UTC (rev 26836)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DefenitionErrorsValidationTest.java 2010-11-23
13:47:38 UTC (rev 26837)
@@ -520,6 +520,19 @@
/**
* 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-7710
+ *
+ * @throws Exception
+ */
+ public void testProducerMethodOnSessionBeanMustBeBusinessMethodWithoutLocalInterface()
throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/disposers/WidgetRepositoryProducerOk.java");
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{"retrieveEntityManager", "WidgetRepositoryProducerOk"});
+ assertMarkerIsNotCreated(file, bindedErrorMessage, 14);
+ }
+
+ /**
+ * 3.3.2. Declaring a producer method
* - decorator has a method annotated @Produces
*
* @throws Exception
@@ -623,6 +636,19 @@
/**
* 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-7710
+ *
+ * @throws Exception
+ */
+ public void testDisposalMethodNotBusinessOrStaticWithoutLocalInterface() throws
Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/disposers/WidgetRepositoryProducerOk.java");
+ String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN, new
String[]{"disposeEntityManager", "WidgetRepositoryProducerOk"});
+ assertMarkerIsNotCreated(file, bindedErrorMessage, 18);
+ }
+
+ /**
+ * 3.3.6. Declaring a disposer method
* - decorators may not declare disposer methods
*
* @throws Exception