Author: akazakov
Date: 2010-04-16 16:00:59 -0400 (Fri, 16 Apr 2010)
New Revision: 21546
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/ISessionBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/SessionBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.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 disposer 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
18:45:21 UTC (rev 21545)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2010-04-16
20:00:59 UTC (rev 21546)
@@ -43,6 +43,7 @@
public String STATEFUL_ANNOTATION_TYPE_NAME = "javax.ejb.Stateful";
public String STATELESS_ANNOTATION_TYPE_NAME = "javax.ejb.Stateless";
+ public String LOCAL_ANNOTATION_TYPE_NAME = "javax.ejb.Local";
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/ISessionBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ISessionBean.java 2010-04-16
18:45:21 UTC (rev 21545)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/ISessionBean.java 2010-04-16
20:00:59 UTC (rev 21546)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.cdi.core;
-import org.eclipse.jdt.core.IAnnotation;
/**
* Represents a session bean.
@@ -31,5 +30,12 @@
*
* @return @Statefull annotaion declaration.
*/
- IAnnotation getStatefulDeclaration();
+ IAnnotationDeclaration getStatefulDeclaration();
+
+ /**
+ * Returns @Stateless annotaion declaration.
+ *
+ * @return @Stateless annotaion declaration.
+ */
+ IAnnotationDeclaration getStatelessDeclaration();
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/SessionBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/SessionBean.java 2010-04-16
18:45:21 UTC (rev 21545)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/SessionBean.java 2010-04-16
20:00:59 UTC (rev 21546)
@@ -1,17 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.internal.core.impl;
-import org.eclipse.jdt.core.IAnnotation;
+import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.ISessionBean;
public class SessionBean extends ClassBean implements ISessionBean {
- public IAnnotation getStatefulDeclaration() {
- AnnotationDeclaration stateful = getDefinition().getStatefulAnnotation();
- return stateful != null ? stateful.getDeclaration() : null;
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.ISessionBean#getStatefulDeclaration()
+ */
+ public IAnnotationDeclaration getStatefulDeclaration() {
+ return getDefinition().getStatefulAnnotation();
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.ISessionBean#getStatelessDeclaration()
+ */
+ public IAnnotationDeclaration getStatelessDeclaration() {
+ return getDefinition().getStatelessAnnotation();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.ISessionBean#isStateful()
+ */
public boolean isStateful() {
return getDefinition().getStatefulAnnotation() != null;
}
-
-}
+}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.java 2010-04-16
18:45:21 UTC (rev 21545)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/TypeDefinition.java 2010-04-16
20:00:59 UTC (rev 21546)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * Copyright (c) 2009 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,
@@ -94,5 +94,4 @@
public AnnotationDeclaration getStatelessAnnotation() {
return annotationsByType.get(CDIConstants.STATELESS_ANNOTATION_TYPE_NAME);
}
-
-}
+}
\ 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
18:45:21 UTC (rev 21545)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-04-16
20:00:59 UTC (rev 21546)
@@ -26,7 +26,10 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.wst.validation.internal.core.ValidationException;
@@ -51,11 +54,13 @@
import org.jboss.tools.cdi.core.IQualifierDeclaration;
import org.jboss.tools.cdi.core.IScope;
import org.jboss.tools.cdi.core.IScopeDeclaration;
+import org.jboss.tools.cdi.core.ISessionBean;
import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.core.IStereotypeDeclaration;
import org.jboss.tools.cdi.core.IStereotyped;
import org.jboss.tools.cdi.core.ITypeDeclaration;
import org.jboss.tools.cdi.core.preferences.CDIPreferences;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.text.ITextSourceReference;
import org.jboss.tools.jst.web.kb.IKbProject;
import org.jboss.tools.jst.web.kb.KbProjectFactory;
@@ -359,9 +364,61 @@
addError(CDIValidationMessages.DISPOSER_ANNOTATED_INJECT,
CDIPreferences.DISPOSER_ANNOTATED_INJECT, declaration, bean.getResource());
}
}
+
+ /*
+ * 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
+ */
+ validateSessionBeanMethod(bean, disposer, disposerDeclarations,
CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN,
CDIPreferences.ILLEGAL_DISPOSER_IN_SESSION_BEAN);
}
}
+ /**
+ * 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.
+ *
+ * @param bean
+ * @param method
+ * @param annotatedParams
+ * @param errorKey
+ */
+ private void validateSessionBeanMethod(IClassBean bean, IBeanMethod method,
Set<IAnnotationDeclaration> annotatedParams, String errorMessageKey, String
preferencesKey) {
+ if(bean instanceof ISessionBean) {
+ if(annotatedParams!=null) {
+ try {
+ if(!Flags.isStatic(method.getMethod().getFlags())) {
+ ISessionBean sessionBean = (ISessionBean)bean;
+ Set<IParametedType> types = sessionBean.getLegalTypes();
+ boolean businessMethod = false;
+ for (IParametedType type : types) {
+ IType sourceType = type.getType();
+ 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)) {
+ businessMethod = true;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+ if(!businessMethod) {
+ for (IAnnotationDeclaration declaration : annotatedParams) {
+ addError(errorMessageKey, preferencesKey, declaration, bean.getResource());
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
+ }
+ }
+
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
18:45:21 UTC (rev 21545)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-04-16
20:00:59 UTC (rev 21546)
@@ -83,7 +83,7 @@
// {CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalProducerMethodInSessionBean_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.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.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalProducerFieldInSessionBean_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-04-16
18:45:21 UTC (rev 21545)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-04-16
20:00:59 UTC (rev 21546)
@@ -204,6 +204,17 @@
}
/**
+ * 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
+ *
+ * @throws Exception
+ */
+ public void testDisposalMethodNotBusinessOrStatic() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/implementation/disposal/method/definition/broken/methodOnSessionBean/AppleTree.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_DISPOSER_IN_SESSION_BEAN, 31);
+ }
+
+ /**
* 3.9.1. Declaring an initializer method
* - an initializer method has a parameter annotated @Disposes
*