Author: akazakov
Date: 2010-05-12 13:02:40 -0400 (Wed, 12 May 2010)
New Revision: 22043
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/errorList.txt
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 rule: Managed bean
class annotated @Specializes does not directly extend the bean class of another managed
bean
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-12
16:38:12 UTC (rev 22042)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-05-12
17:02:40 UTC (rev 22043)
@@ -745,6 +745,43 @@
CDICorePlugin.getDefault().logError(e);
}
}
+ /*
+ * 3.1.4. Specializing a managed bean
+ * - managed bean class annotated @Specializes does not directly extend the bean class
of another managed bean
+ */
+ IAnnotationDeclaration specializesDeclaration =
bean.getSpecializesAnnotationDeclaration();
+ if(specializesDeclaration!=null) {
+ try {
+ IBean sBean = bean.getSpecializedBean();
+ if(sBean!=null) {
+ if(sBean instanceof ISessionBean ||
sBean.getAnnotation(CDIConstants.STATELESS_ANNOTATION_TYPE_NAME)!=null) {
+ // The specializing bean directly extends an enterprise bean class
+ addError(CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN,
CDIPreferences.ILLEGAL_SPECIALIZING_MANAGED_BEAN, specializesDeclaration,
bean.getResource());
+ } else {
+ // Validate the specializing bean extends a non simple bean
+ boolean hasDefaultConstructor = true;
+ IMethod[] methods = sBean.getBeanClass().getMethods();
+ for (IMethod method : methods) {
+ if(method.isConstructor()) {
+ if(Flags.isPublic(method.getFlags()) &&
method.getParameterNames().length==0) {
+ hasDefaultConstructor = true;
+ break;
+ }
+ hasDefaultConstructor = false;
+ }
+ }
+ if(!hasDefaultConstructor) {
+ addError(CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN,
CDIPreferences.ILLEGAL_SPECIALIZING_MANAGED_BEAN, specializesDeclaration,
bean.getResource());
+ }
+ }
+ } else {
+ // The specializing bean extends nothing
+ addError(CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN,
CDIPreferences.ILLEGAL_SPECIALIZING_MANAGED_BEAN, specializesDeclaration,
bean.getResource());
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
}
private void validateInterceptor(IInterceptor interceptor) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-12
16:38:12 UTC (rev 22042)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-12
17:02:40 UTC (rev 22043)
@@ -35,14 +35,14 @@
- managed bean with a public field declares any scope other than @Dependent
- managed bean with a parameterized bean class declares any scope other than @Dependent
+3.1.4. Specializing a managed bean
+- managed bean class annotated @Specializes does not directly extend
+ the bean class of another managed bean
-3.1.4. Specializing a managed bean
-- managed bean class annotated @Specializes does not directly extend
- the bean class of another managed bean
3.2. Session beans
- session bean specifies an illegal scope (a stateless session bean must belong
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-12
16:38:12 UTC (rev 22042)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-05-12
17:02:40 UTC (rev 22043)
@@ -119,20 +119,20 @@
CDICorePlugin.PLUGIN_ID
);
-// private static SectionDescription SECTION_SPECIALIZATION = new SectionDescription(
-// CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_specializing,
-// new String[][]{
-// {CDIPreferences.ILLEGAL_SPECIALIZING_MANAGED_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalSpecializingManagedBean_label},
+ private static SectionDescription SECTION_SPECIALIZATION = new SectionDescription(
+ CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_specializing,
+ new String[][]{
+ {CDIPreferences.ILLEGAL_SPECIALIZING_MANAGED_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalSpecializingManagedBean_label},
// {CDIPreferences.ILLEGAL_SPECIALIZING_SESSION_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalSpecializingSessionBean_label},
// {CDIPreferences.ILLEGAL_SPECIALIZING_PRODUCER,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_illegalSpecializingProducer_label},
// {CDIPreferences.MISSING_TYPE_IN_SPECIALIZING_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_missingTypeInSpecializingBean_label},
// {CDIPreferences.CONFLICTING_NAME_IN_SPECIALIZING_BEAN,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_conflictingNameInSpecializingBean_label},
// {CDIPreferences.INTERCEPTOR_ANNOTATED_SPECIALIZES,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_interceptorAnnotatedSpecializes_label},
// {CDIPreferences.DECORATOR_ANNOTATED_SPECIALIZES,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_decoratorAnnotatedSpecializes_label},
-// },
-// CDICorePlugin.PLUGIN_ID
-// );
-//
+ },
+ CDICorePlugin.PLUGIN_ID
+ );
+
private static SectionDescription SECTION_MISCELLANEOUS = new SectionDescription(
CDIPreferencesMessages.CDIValidatorConfigurationBlock_section_miscellaneous,
new String[][]{
@@ -149,7 +149,7 @@
SECTION_SCOPE,
SECTION_MEMBER,
SECTION_INTERCEPTOR,
-// SECTION_SPECIALIZATION,
+ 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-05-12
16:38:12 UTC (rev 22042)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ValidationTest.java 2010-05-12
17:02:40 UTC (rev 22043)
@@ -218,6 +218,54 @@
}
/**
+ * 3.1.4. Specializing a managed bean
+ * - managed bean class annotated @Specializes does not directly extend the bean class
of another managed bean
+ * (Test a specializing bean extending a non simple bean)
+ *
+ * @throws Exception
+ */
+ public void testSpecializingClassExtendsNonSimpleBean() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/inheritance/specialization/simple/broken/noextend3/Cow_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN, 21);
+ }
+
+ /**
+ * 3.1.4. Specializing a managed bean
+ * - managed bean class annotated @Specializes does not directly extend the bean class
of another managed bean
+ * (Test a specializing bean extending nothing)
+ *
+ * @throws Exception
+ */
+ public void testSpecializingClassDirectlyExtendsNothing() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/inheritance/specialization/simple/broken/noextend2/Cow_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN, 21);
+ }
+
+ /**
+ * 3.1.4. Specializing a managed bean
+ * - managed bean class annotated @Specializes does not directly extend the bean class
of another managed bean
+ * (Test a specializing bean directly extending an enterprise bean class)
+ *
+ * @throws Exception
+ */
+ public void testSpecializingClassDirectlyExtendsEnterpriseBean() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/inheritance/specialization/simple/broken/extendejb/Tractor_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN, 21);
+ }
+
+ /**
+ * 3.1.4. Specializing a managed bean
+ * - managed bean class annotated @Specializes does not directly extend the bean class
of another managed bean
+ * (Test a specializing bean implementing an interface and extending nothing)
+ *
+ * @throws Exception
+ */
+ public void testSpecializingClassImplementsInterfaceAndExtendsNothing() throws Exception
{
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/inheritance/specialization/simple/broken/noextend1/Donkey_Broken.java");
+ AbstractResourceMarkerTest.assertMarkerIsCreated(file,
AbstractResourceMarkerTest.MARKER_TYPE,
CDIValidationMessages.ILLEGAL_SPECIALIZING_MANAGED_BEAN, 21);
+ }
+
+ /**
* 3.5.1. Declaring a resource
* - producer field declaration specifies an EL name (together with one of @Resource,
@PersistenceContext, @PersistenceUnit, @EJB, @WebServiceRef)
*