Author: scabanovich
Date: 2012-08-03 15:36:35 -0400 (Fri, 03 Aug 2012)
New Revision: 42853
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/CDIValidationMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties
Log:
JBIDE-12199
https://issues.jboss.org/browse/JBIDE-12199
Verifying legal types of a normal scoped 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 2012-08-03
14:32:10 UTC (rev 42852)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2012-08-03
19:36:35 UTC (rev 42853)
@@ -661,6 +661,7 @@
// validate
validateTyped(bean);
validateBeanScope(bean);
+ validateNormalBeanScope(bean);
if (bean instanceof IProducer) {
validateProducer(context, (IProducer) bean);
@@ -1833,6 +1834,61 @@
}
}
+ private void validateNormalBeanScope(IBean bean) {
+ if(bean.getScope()!=null && bean.getScope().isNorlmalScope()) {
+ ITextSourceReference reference = null;
+ Set<IScopeDeclaration> scopes = bean.getScopeDeclarations();
+ if(!scopes.isEmpty()) {
+ reference = scopes.iterator().next();
+ } else {
+ reference = bean.getNameLocation(false);
+ }
+ if(reference == null) {
+ return;
+ }
+ for (IParametedType type: bean.getLegalTypes()) {
+ // - Array types cannot be proxied by the container.
+ String typeSignature = type.getSignature();
+ int kind = Signature.getTypeSignatureKind(typeSignature);
+ if(kind == Signature.ARRAY_TYPE_SIGNATURE) {
+ addProblem(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_ARRAY_TYPE_2,
type.getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE,
reference, bean.getResource());
+ } else if(type.isPrimitive()) {
+ // - Primitive types cannot be proxied by the container.
+ addProblem(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_PRIMITIVE_TYPE_2,
type.getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE,
reference, bean.getResource());
+ } else if(type.getType().exists() &&
!"java.lang.Object".equals(type.getType().getFullyQualifiedName())) {
+ try {
+ if(Flags.isFinal(type.getType().getFlags())) {
+ // - Classes which are declared final cannot be proxied by the container.
+ addProblem(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_FINAL_TYPE_2,
type.getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE,
reference, bean.getResource());
+ } else {
+ IMethod[] methods = type.getType().getMethods();
+ boolean hasDefaultConstructor = false;
+ boolean hasConstructor = false;
+ for (IMethod method : methods) {
+ hasConstructor = hasConstructor || method.isConstructor();
+ hasDefaultConstructor = hasDefaultConstructor || (method.isConstructor()
&& !Flags.isPrivate(method.getFlags()) &&
method.getParameterNames().length==0);
+ if(Flags.isFinal(method.getFlags())) {
+ // - Classes which have final methods cannot be proxied by the container.
+ addProblem(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_FM_2,
type.getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE,
reference, bean.getResource());
+ hasDefaultConstructor = true;
+ break;
+ }
+ }
+ if(!hasDefaultConstructor && hasConstructor) {
+ // - Classes which don't have a non-private constructor with no parameters
cannot be proxied by the container.
+ addProblem(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_NPC_2,
type.getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE,
reference, bean.getResource());
+ }
+ }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ }
+
+ }
+ }
+
+ }
+
/**
* Validates class bean which may be both a session and decorator (or interceptor).
*
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 2012-08-03
14:32:10 UTC (rev 42852)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationMessages.java 2012-08-03
19:36:35 UTC (rev 42853)
@@ -32,6 +32,11 @@
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 UNPROXYABLE_BEAN_ARRAY_TYPE_2;
+ public static String UNPROXYABLE_BEAN_PRIMITIVE_TYPE_2;
+ public static String UNPROXYABLE_BEAN_TYPE_WITH_NPC_2;
+ public static String UNPROXYABLE_BEAN_FINAL_TYPE_2;
+ public static String UNPROXYABLE_BEAN_TYPE_WITH_FM_2;
public static String DECORATOR_RESOLVES_TO_FINAL_CLASS;
public static String DECORATOR_RESOLVES_TO_FINAL_METHOD;
public static String DUPLCICATE_EL_NAME;
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 2012-08-03
14:32:10 UTC (rev 42852)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/messages.properties 2012-08-03
19:36:35 UTC (rev 42853)
@@ -13,6 +13,13 @@
UNPROXYABLE_BEAN_TYPE_WITH_NPC=Injection point whose declared type ({0} is a class with a
non-private constructor with no parameters) 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 whose declared type ({0} is a final class)
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 whose declared type ({0} is a class with
final methods) cannot be proxied by the container resolves to a bean {1} with a normal
scope [JSR-299 �5.4.1]
+
+UNPROXYABLE_BEAN_ARRAY_TYPE_2=Bean {1} with a normal scope cannot have as legal an array
type {0} that cannot be proxied by the container [JSR-299 �5.4.1]
+UNPROXYABLE_BEAN_PRIMITIVE_TYPE_2=Bean {1} with a normal scope cannot have as legal a
primitive type {0} that cannot be proxied by the container [JSR-299 �5.4.1]
+UNPROXYABLE_BEAN_TYPE_WITH_NPC_2=Bean {1} with a normal scope cannot have as legal a type
{0} (with a non-private constructor with no parameters) that cannot be proxied by the
container [JSR-299 �5.4.1]
+UNPROXYABLE_BEAN_FINAL_TYPE_2=Bean {1} with a normal scope cannot have as legal a type
{0} (final class) that cannot be proxied by the container [JSR-299 �5.4.1]
+UNPROXYABLE_BEAN_TYPE_WITH_FM_2=Bean {1} with a normal scope cannot have as legal a type
{0} (with final methods) that cannot be proxied by the container [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]