Author: akazakov
Date: 2010-12-01 08:28:17 -0500 (Wed, 01 Dec 2010)
New Revision: 27048
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.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.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.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.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
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/CDIPreferencesMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.properties
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DeploymentProblemsValidationTests.java
Log:
https://jira.jboss.org/browse/JBIDE-6575 Added 8.3. Decorator resolution validation
rules.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java 2010-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferenceInitializer.java 2010-12-01
13:28:17 UTC (rev 27048)
@@ -49,6 +49,7 @@
defaultPreferences.put(CDIPreferences.MISSING_NONBINDING_IN_INTERCEPTOR_BINDING_TYPE_MEMBER,
CDIPreferences.WARNING);
defaultPreferences.put(CDIPreferences.ILLEGAL_CONDITIONAL_OBSERVER,
CDIPreferences.WARNING);
defaultPreferences.put(CDIPreferences.MISSING_OR_INCORRECT_TARGET_OR_RETENTION_IN_ANNOTATION_TYPE,
CDIPreferences.WARNING);
+ defaultPreferences.put(CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN,
CDIPreferences.WARNING);
defaultPreferences.putInt(SeverityPreferences.MAX_NUMBER_OF_MARKERS_PREFERENCE_NAME,
SeverityPreferences.DEFAULT_MAX_NUMBER_OF_MARKERS_PER_FILE);
}
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java 2010-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/preferences/CDIPreferences.java 2010-12-01
13:28:17 UTC (rev 27048)
@@ -195,6 +195,11 @@
public static final String INJECTED_DECORATOR =
INSTANCE.createSeverityOption("injectedDecorator"); //$NON-NLS-1$
// - an interceptor can not be injected
public static final String INJECTED_INTERCEPTOR =
INSTANCE.createSeverityOption("injectedInterceptor"); //$NON-NLS-1$
+// 8.3. Decorator resolution
+// - If a decorator matches a managed bean, and the managed bean class is declared final,
the container automatically detects
+// the problem and treats it as a deployment problem.
+// - If a decorator matches a managed bean with a non-static, non-private, final method,
and the decorator also implements that method, the container automatically detects the
problem and treats it as a deployment problem.
+ public static final String DECORATOR_RESOLVES_TO_FINAL_BEAN =
INSTANCE.createSeverityOption("decoratorResolvesToFinalBean"); //$NON-NLS-1$
//Specialization
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-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-01
13:28:17 UTC (rev 27048)
@@ -1215,6 +1215,7 @@
addError(CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS,
CDIPreferences.AMBIGUOUS_INJECTION_POINTS, reference, injection.getResource());
} else if(beans.size()==1) {
IBean bean = beans.iterator().next();
+ getValidationContext().addLinkedCoreResource(injection.getSourcePath().toOSString(),
bean.getResource().getFullPath(), false);
/*
* 5.2.4. Primitive types and null values
* - injection point of primitive type resolves to a bean that may have null values,
such as a producer method with a non-primitive return type or a producer field with a
non-primitive type
@@ -1273,6 +1274,47 @@
}
}
}
+ if(injection.getClassBean() instanceof IDecorator && injection.isDelegate()
&& bean instanceof IClassBean) {
+ try {
+ IType beanClass = bean.getBeanClass();
+ if(Flags.isFinal(beanClass.getFlags())) {
+ // 8.3. Decorator resolution
+ // - If a decorator matches a managed bean, and the managed bean class is declared
final, the container automatically detects
+ // the problem and treats it as a deployment problem.
+ addError(MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_CLASS,
bean.getSimpleJavaName()), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN, reference,
injection.getResource());
+ } else {
+ // 8.3. Decorator resolution
+ // - If a decorator matches a managed bean with a non-static, non-private, final
method, and the decorator also implements that method,
+ // the container automatically detects the problem and treats it as a
deployment problem.
+ IType decoratorClass = injection.getClassBean().getBeanClass();
+ IMethod[] methods = decoratorClass.getMethods();
+ boolean reported = false;
+ if(methods!=null) {
+ for (IMethod method : methods) {
+ if(!Flags.isPrivate(method.getFlags()) &&
!Flags.isStatic(method.getFlags())) {
+ IMethod[] beanMethods = beanClass.findMethods(method);
+ if(beanMethods!=null) {
+ for (IMethod beanMethod : beanMethods) {
+ int flags = beanMethod.getFlags();
+ if(!Flags.isPrivate(flags) && !Flags.isStatic(flags) &&
Flags.isFinal(flags)) {
+ String methodName = Signature.toString(beanMethod.getSignature(),
beanMethod.getElementName(), beanMethod.getParameterNames(), false, false);
+ addError(MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_METHOD,
bean.getSimpleJavaName(), methodName), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN,
reference, injection.getResource());
+ reported = true;
+ break;
+ }
+ }
+ if(reported) {
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
}
/*
* 5.5.7. Injection point metadata
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2010-12-01
13:28:17 UTC (rev 27048)
@@ -32,6 +32,8 @@
public static String UNPROXYABLE_BEAN_TYPE_WITH_NPC;
public static String UNPROXYABLE_BEAN_FINAL_TYPE;
public static String UNPROXYABLE_BEAN_TYPE_WITH_FM;
+ public static String DECORATOR_RESOLVES_TO_FINAL_CLASS;
+ public static String DECORATOR_RESOLVES_TO_FINAL_METHOD;
public static String ILLEGAL_TYPE_IN_TYPED_DECLARATION;
public static String ILLEGAL_TYPE_IN_TYPED_DECLARATION_IN_BEAN_CLASS;
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-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-12-01
13:28:17 UTC (rev 27048)
@@ -190,11 +190,19 @@
treats it as a deployment problem.
5.2.4. Primitive types and null values
-- if an injection point of primitive type resolves to a bean that may have null values,
such as a producer method
+- If an injection point of primitive type resolves to a bean that may have null values,
such as a producer method
with a non-primitive return type or a producer field with a non-primitive type, the
container automatically detects the problem
and treats it as a deployment problem.
+5.4.1. Unproxyable bean types
+- If an injection point whose declared type cannot be proxied by the container resolves
to a bean with a normal scope,
+ the container automatically detects the problem and treats it as a deployment problem:
+a) Classes which don't have a non-private constructor with no parameters cannot be
proxied by the container.
+b) Classes which are declared final or have final methods cannot be proxied by the
container.
+c) Primitive types cannot be proxied by the container.
+d) Array types cannot be proxied by the container.
+
Beans.xml (all of them are deployment problems)
@@ -226,21 +234,18 @@
Unimplemented:
-5.1.3. Inconsistent specialization
-- Suppose an enabled bean X specializes a second bean Y. If there is another enabled bean
that specializes Y we say that inconsistent
- specialization exists. The container automatically detects inconsistent specialization
and treats it as a deployment problem.
+5.1.3. Inconsistent specialization
+- Suppose an enabled bean X specializes a second bean Y. If there is another enabled bean
that specializes Y we say that inconsistent
+ specialization exists. The container automatically detects inconsistent specialization
and treats it as a deployment problem.
-5.3.1. Ambiguous EL names
-- All unresolvable ambiguous EL names are detected by the container when the application
is initialized. Suppose two beans are both available for injection in a certain war, and
either:
- • the two beans have the same EL name and the name is not resolvable, or
- • the EL name of one bean is of the form x.y, where y is a valid bean EL name, and x is
the EL name of the other bean,
- the container automatically detects the problem and treats it as a deployment
problem.
-
-5.4.1. Unproxyable bean types
-- If an injection point whose declared type cannot be proxied by the container resolves
to a bean with a normal scope,
- the container automatically detects the problem and treats it as a deployment
problem.
-
-8.3. Decorator resolution
-- If a decorator matches a managed bean, and the managed bean class is declared final,
the container automatically detects
- the problem and treats it as a deployment problem.
-
+5.3.1. Ambiguous EL names
+- All unresolvable ambiguous EL names are detected by the container when the application
is initialized. Suppose two beans are both available for injection in a certain war, and
either:
+ • the two beans have the same EL name and the name is not resolvable, or
+ • the EL name of one bean is of the form x.y, where y is a valid bean EL name, and x is
the EL name of the other bean,
+ the container automatically detects the problem and treats it as a deployment
problem.
+
+8.3. Decorator resolution
+- If a decorator matches a managed bean, and the managed bean class is declared final,
the container automatically detects
+ the problem and treats it as a deployment problem.
+- If a decorator matches a managed bean with a non-static, non-private, final method, and
the decorator also implements that method,
+ the container automatically detects the problem and treats it as a deployment problem.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2010-12-01
13:28:17 UTC (rev 27048)
@@ -11,6 +11,8 @@
UNPROXYABLE_BEAN_TYPE_WITH_NPC=Injection point declares a class {0} with a non-private
constructor with no parameters (such a class cannot be proxied by the container) resolves
to a bean {1} with a normal scope [JSR-299 �5.4.1]
UNPROXYABLE_BEAN_FINAL_TYPE=Injection point declares a final class {0} that cannot be
proxied by the container resolves to a bean {1} with a normal scope [JSR-299 �5.4.1]
UNPROXYABLE_BEAN_TYPE_WITH_FM=Injection point declares a class {0} with final methods
(such a class cannot be proxied by the container) resolves to a bean {1} with a normal
scope [JSR-299 �5.4.1]
+DECORATOR_RESOLVES_TO_FINAL_CLASS=Decorator must not be bound to a managed bean
implemented by a class {0} which is declared final [JSR-299 �8.3]
+DECORATOR_RESOLVES_TO_FINAL_METHOD=Decorator matches a managed bean {0} with a
non-static, non-private, final method {1}, and the decorator also implements that method
[JSR-299 �8.3]
ILLEGAL_TYPE_IN_TYPED_DECLARATION=Bean specifies a @Typed annotation, and the value
member specifies a class which does not correspond to a type in the unrestricted set of
bean types of a bean [JSR-299 �2.2.2]
ILLEGAL_TYPE_IN_TYPED_DECLARATION_IN_BEAN_CLASS=Bean class specifies a @Typed annotation,
and the value member specifies a class which does not correspond to a type in the
unrestricted set of bean types of a bean [JSR-299 �2.2.2]
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-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIConfigurationBlock.java 2010-12-01
13:28:17 UTC (rev 27048)
@@ -119,6 +119,7 @@
{CDIPreferences.MISSING_INTERCEPTOR_BINDING,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_missingInterceptorBinding_label},
{CDIPreferences.INJECTED_DECORATOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_injectedDecorator_label},
{CDIPreferences.INJECTED_INTERCEPTOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_injectedInterceptor_label},
+ {CDIPreferences.INJECTED_INTERCEPTOR,
CDIPreferencesMessages.CDIValidatorConfigurationBlock_pb_decoratorResolvesToFinalBean_label},
},
CDICorePlugin.PLUGIN_ID
);
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.java 2010-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.java 2010-12-01
13:28:17 UTC (rev 27048)
@@ -106,6 +106,7 @@
public static String CDIValidatorConfigurationBlock_pb_missingInterceptorBinding_label;
public static String CDIValidatorConfigurationBlock_pb_injectedDecorator_label;
public static String CDIValidatorConfigurationBlock_pb_injectedInterceptor_label;
+ public static String
CDIValidatorConfigurationBlock_pb_decoratorResolvesToFinalBean_label;
// Specializing
public static String CDIValidatorConfigurationBlock_section_specializing;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.properties 2010-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/preferences/CDIPreferencesMessages.properties 2010-12-01
13:28:17 UTC (rev 27048)
@@ -95,6 +95,7 @@
CDIValidatorConfigurationBlock_pb_missingInterceptorBinding_label=Missing interceptor
binding:
CDIValidatorConfigurationBlock_pb_injectedDecorator_label=Decorator can not be injected:
CDIValidatorConfigurationBlock_pb_injectedInterceptor_label=Interceptor can not be
injected:
+CDIValidatorConfigurationBlock_pb_decoratorResolvesToFinalBean_label=Decorator bound to
managed bean w/ final method/class:
##Specializing
CDIValidatorConfigurationBlock_section_specializing=Specializing
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DeploymentProblemsValidationTests.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DeploymentProblemsValidationTests.java 2010-12-01
12:58:18 UTC (rev 27047)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/DeploymentProblemsValidationTests.java 2010-12-01
13:28:17 UTC (rev 27048)
@@ -133,4 +133,28 @@
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/lookup/clientProxy/unproxyable/finalMethod/FishFarm.java");
assertMarkerIsCreated(file,
MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_FM,
"Tuna_Broken", "Tuna_Broken"), 23);
}
+
+ /**
+ * 8.3 - Decorator resolution
+ * - If a decorator matches a managed bean, and the managed bean class is declared
final, the container automatically detects
+ * the problem and treats it as a deployment problem.
+ *
+ * @throws Exception
+ */
+ public void testAppliesToFinalManagedBeanClass() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/decorators/definition/broken/finalBeanClass/TimestampLogger.java");
+ assertMarkerIsCreated(file,
MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_CLASS,
"MockLogger"), 31);
+ }
+
+ /**
+ * 8.3 - Decorator resolution
+ * - If a decorator matches a managed bean with a non-static, non-private, final
method, and the decorator also implements that method,
+ * the container automatically detects the problem and treats it as a deployment
problem.
+ *
+ * @throws Exception
+ */
+ public void testAppliesToFinalMethodOnManagedBeanClass() throws Exception {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/decorators/definition/broken/finalBeanMethod/TimestampLogger.java");
+ assertMarkerIsCreated(file,
MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_METHOD,
"MockLogger", "log(String string)"), 31);
+ }
}
\ No newline at end of file