[jbosstools-commits] JBoss Tools SVN: r42009 - trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Jun 15 20:45:27 EDT 2012
Author: scabanovich
Date: 2012-06-15 20:45:27 -0400 (Fri, 15 Jun 2012)
New Revision: 42009
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
Log:
JBIDE-11460
https://issues.jboss.org/browse/JBIDE-11460
Validation of injection with unproxyable type resolved to a bean with a normal scope is fixed.
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-06-16 00:45:10 UTC (rev 42008)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2012-06-16 00:45:27 UTC (rev 42009)
@@ -1671,104 +1671,101 @@
addError(CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS, CDIPreferences.UNSATISFIED_OR_AMBIGUOUS_INJECTION_POINTS, reference, injection.getResource(), AMBIGUOUS_INJECTION_POINTS_ID);
} else if(beans.size()==1) {
IBean bean = beans.iterator().next();
- if(shouldValidateType(bean.getBeanClass())) {
- /*
- * 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
- */
- if(bean.isNullable() && injection.getType()!=null && injection.getType().isPrimitive()) {
- addError(CDIValidationMessages.INJECT_RESOLVES_TO_NULLABLE_BEAN, CDIPreferences.INJECT_RESOLVES_TO_NULLABLE_BEAN, reference, injection.getResource());
- }
- /*
- * 5.1.4. Inter-module injection
- * - a decorator can not be injected
- * - an interceptor can not be injected
- * It is not an error - container just never attempts to inject them.
- */
-
- /*
- * 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.
- */
- if(bean.getScope()!=null && bean.getScope().isNorlmalScope() && injection.getType()!=null) {
- // - Array types cannot be proxied by the container.
- String typeSignature = injection.getType().getSignature();
- int kind = Signature.getTypeSignatureKind(typeSignature);
- if(kind == Signature.ARRAY_TYPE_SIGNATURE) {
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_ARRAY_TYPE, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- } else if(injection.getType().isPrimitive()) {
- // - Primitive types cannot be proxied by the container.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_PRIMITIVE_TYPE, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- } else if(bean instanceof IClassBean) {
- try {
- if(Flags.isFinal(bean.getBeanClass().getFlags())) {
- // - Classes which are declared final cannot be proxied by the container.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_FINAL_TYPE, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- } else {
- IMethod[] methods = bean.getBeanClass().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.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_FM, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- hasDefaultConstructor = true;
- break;
- }
+ /*
+ * 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
+ */
+ if(bean.isNullable() && injection.getType()!=null && injection.getType().isPrimitive()) {
+ addError(CDIValidationMessages.INJECT_RESOLVES_TO_NULLABLE_BEAN, CDIPreferences.INJECT_RESOLVES_TO_NULLABLE_BEAN, reference, injection.getResource());
+ }
+ /*
+ * 5.1.4. Inter-module injection
+ * - a decorator can not be injected
+ * - an interceptor can not be injected
+ * It is not an error - container just never attempts to inject them.
+ */
+ /*
+ * 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.
+ */
+ if(bean.getScope()!=null && bean.getScope().isNorlmalScope() && injection.getType()!=null) {
+ // - Array types cannot be proxied by the container.
+ String typeSignature = injection.getType().getSignature();
+ int kind = Signature.getTypeSignatureKind(typeSignature);
+ if(kind == Signature.ARRAY_TYPE_SIGNATURE) {
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_ARRAY_TYPE, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ } else if(injection.getType().isPrimitive()) {
+ // - Primitive types cannot be proxied by the container.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_PRIMITIVE_TYPE, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ } else if(injection.getType().getType().exists()){
+ try {
+ if(Flags.isFinal(injection.getType().getType().getFlags())) {
+ // - Classes which are declared final cannot be proxied by the container.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_FINAL_TYPE, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ } else {
+ IMethod[] methods = injection.getType().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.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_FM, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.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.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_NPC, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- }
}
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
+ if(!hasDefaultConstructor && hasConstructor) {
+ // - Classes which don't have a non-private constructor with no parameters cannot be proxied by the container.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_NPC, injection.getType().getSimpleName(), bean.getElementName()), CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ }
}
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
}
}
- 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.getElementName()), 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.getElementName(), methodName), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN, reference, injection.getResource());
- reported = true;
- break;
- }
- }
- if(reported) {
+ }
+ if(injection.getClassBean() instanceof IDecorator && injection.isDelegate() && bean instanceof IClassBean && bean.getBeanClass().exists()) {
+ 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.getElementName()), 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.getElementName(), methodName), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN, reference, injection.getResource());
+ reported = true;
break;
}
}
+ if(reported) {
+ break;
+ }
}
}
}
}
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
}
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
}
}
}
More information about the jbosstools-commits
mailing list