Author: akazakov
Date: 2011-06-02 19:12:37 -0400 (Thu, 02 Jun 2011)
New Revision: 31790
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/projects/SeamFacesTest/src/org/jboss/beans/validation/test/Validation2.java
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/internal/core/validation/CDICoreValidator.java
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/src/org/jboss/tools/cdi/seam/faces/core/test/SeamFacesValidationTest.java
Log:
https://issues.jboss.org/browse/JBIDE-8576
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 2011-06-02
20:29:02 UTC (rev 31789)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIConstants.java 2011-06-02
23:12:37 UTC (rev 31790)
@@ -94,4 +94,5 @@
public String WELD_BEAN_MANAGER_TYPE_NAME =
"org.jboss.weld.manager.BeanManagerImpl";
public String SEAM_FACES_INPUT_FIELD_TYPE_NAME =
"org.jboss.seam.faces.validation.InputField";
+ public String SEAM_FACES_INPUT_ELEMENT_TYPE_NAME =
"org.jboss.seam.faces.validation.InputElement";
}
\ 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 2011-06-02
20:29:02 UTC (rev 31789)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2011-06-02
23:12:37 UTC (rev 31790)
@@ -1408,128 +1408,130 @@
* - If an unsatisfied or unresolvable ambiguous dependency exists, the container
automatically detects the problem and treats it as a deployment problem.
*/
IType type = getTypeOfInjection(injection);
- IAnnotationDeclaration faces =
injection.getAnnotation(CDIConstants.SEAM_FACES_INPUT_FIELD_TYPE_NAME);
- // If the injection point annotated @InputField then don't try to resolve it.
+ // If the injection point annotated @InputField then don't try to resolve it. Also
ignore @Inject InputElement field.
// Despite this annotation is from Seam Faces module and is not part of JSR-299
it's much easy to check this annotation here instead of moving this check to Seam
Faces plug-in.
// See
https://issues.jboss.org/browse/JBIDE-8576
- if(faces==null && injection instanceof IInjectionPointParameter) {
- IInjectionPointParameter param = (IInjectionPointParameter)injection;
- faces =
param.getBeanMethod().getAnnotation(CDIConstants.SEAM_FACES_INPUT_FIELD_TYPE_NAME);
- }
- if(faces==null) {
- boolean instance = type!=null &&
CDIConstants.INSTANCE_TYPE_NAME.equals(type.getFullyQualifiedName());
- Set<IBean> allBeans = cdiProject.getBeans(false, injection);
- for (IBean bean : allBeans) {
- if(!bean.getBeanClass().isReadOnly()) {
- getValidationContext().addLinkedCoreResource(SHORT_ID,
injection.getSourcePath().toOSString(), bean.getResource().getFullPath(), false);
- }
+ if(type==null ||
!CDIConstants.SEAM_FACES_INPUT_ELEMENT_TYPE_NAME.equals(type.getFullyQualifiedName())) {
+ IAnnotationDeclaration faces =
injection.getAnnotation(CDIConstants.SEAM_FACES_INPUT_FIELD_TYPE_NAME);
+ if(faces==null && injection instanceof IInjectionPointParameter) {
+ IInjectionPointParameter param = (IInjectionPointParameter)injection;
+ faces =
param.getBeanMethod().getAnnotation(CDIConstants.SEAM_FACES_INPUT_FIELD_TYPE_NAME);
}
- if(type!=null && beans.isEmpty() && !instance) {
- addError(CDIValidationMessages.UNSATISFIED_INJECTION_POINTS,
CDIPreferences.UNSATISFIED_INJECTION_POINTS, reference, injection.getResource(),
UNSATISFIED_INJECTION_POINTS_ID);
- } else if(beans.size()>1 && !instance) {
- addError(CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS,
CDIPreferences.AMBIGUOUS_INJECTION_POINTS, reference, injection.getResource(),
AMBIGUOUS_INJECTION_POINTS_ID);
- } else if(beans.size()==1) {
- IBean bean = beans.iterator().next();
- if(!bean.getBeanClass().isReadOnly()) {
- /*
- * 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());
+ if(faces==null) {
+ boolean instance = type!=null &&
CDIConstants.INSTANCE_TYPE_NAME.equals(type.getFullyQualifiedName());
+ Set<IBean> allBeans = cdiProject.getBeans(false, injection);
+ for (IBean bean : allBeans) {
+ if(!bean.getBeanClass().isReadOnly()) {
+ getValidationContext().addLinkedCoreResource(SHORT_ID,
injection.getSourcePath().toOSString(), bean.getResource().getFullPath(), false);
}
- /*
- * 5.1.4. Inter-module injection
- * - a decorator can not be injected
- * - an interceptor can not be injected
- */
- if(bean instanceof IDecorator) {
- addError(CDIValidationMessages.INJECTED_DECORATOR,
CDIPreferences.INJECTED_DECORATOR, reference, injection.getResource());
- } else if(bean instanceof IInterceptor) {
- addError(CDIValidationMessages.INJECTED_INTERCEPTOR,
CDIPreferences.INJECTED_INTERCEPTOR, reference, injection.getResource());
- }
- /*
- * 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.getSimpleJavaName()),
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.getSimpleJavaName()),
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.getSimpleJavaName()),
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.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- hasDefaultConstructor = true;
- break;
+ }
+ if(type!=null && beans.isEmpty() && !instance) {
+ addError(CDIValidationMessages.UNSATISFIED_INJECTION_POINTS,
CDIPreferences.UNSATISFIED_INJECTION_POINTS, reference, injection.getResource(),
UNSATISFIED_INJECTION_POINTS_ID);
+ } else if(beans.size()>1 && !instance) {
+ addError(CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS,
CDIPreferences.AMBIGUOUS_INJECTION_POINTS, reference, injection.getResource(),
AMBIGUOUS_INJECTION_POINTS_ID);
+ } else if(beans.size()==1) {
+ IBean bean = beans.iterator().next();
+ if(!bean.getBeanClass().isReadOnly()) {
+ /*
+ * 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
+ */
+ if(bean instanceof IDecorator) {
+ addError(CDIValidationMessages.INJECTED_DECORATOR,
CDIPreferences.INJECTED_DECORATOR, reference, injection.getResource());
+ } else if(bean instanceof IInterceptor) {
+ addError(CDIValidationMessages.INJECTED_INTERCEPTOR,
CDIPreferences.INJECTED_INTERCEPTOR, reference, injection.getResource());
+ }
+ /*
+ * 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.getSimpleJavaName()),
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.getSimpleJavaName()),
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.getSimpleJavaName()),
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.getSimpleJavaName()),
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.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ }
}
- 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.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
}
- } 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.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;
+ 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;
}
}
- if(reported) {
- break;
- }
}
}
}
}
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
}
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
}
}
}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/projects/SeamFacesTest/src/org/jboss/beans/validation/test/Validation2.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/projects/SeamFacesTest/src/org/jboss/beans/validation/test/Validation2.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/projects/SeamFacesTest/src/org/jboss/beans/validation/test/Validation2.java 2011-06-02
23:12:37 UTC (rev 31790)
@@ -0,0 +1,17 @@
+package org.jboss.beans.validation.test;
+
+import javax.inject.Inject;
+
+import org.jboss.seam.faces.validation.InputElement;
+
+public class Validation2 {
+
+ @Inject InputElement<MyBean1> bean3Ok;
+
+ @Inject InputElement<String> bean4Ok;
+
+ @Inject
+ public void setMyBeanOk(InputElement<MyBean1> bean, InputElement<String>
bean2) {
+
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/projects/SeamFacesTest/src/org/jboss/beans/validation/test/Validation2.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/src/org/jboss/tools/cdi/seam/faces/core/test/SeamFacesValidationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/src/org/jboss/tools/cdi/seam/faces/core/test/SeamFacesValidationTest.java 2011-06-02
20:29:02 UTC (rev 31789)
+++
trunk/cdi/tests/org.jboss.tools.cdi.seam.faces.core.test/src/org/jboss/tools/cdi/seam/faces/core/test/SeamFacesValidationTest.java 2011-06-02
23:12:37 UTC (rev 31790)
@@ -17,14 +17,11 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.jboss.tools.cdi.internal.core.validation.CDIValidationMessages;
import org.jboss.tools.jst.jsp.test.TestUtil;
import org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager;
-import org.jboss.tools.test.util.JobUtils;
import org.jboss.tools.test.util.ResourcesUtils;
import org.jboss.tools.tests.AbstractResourceMarkerTest;
@@ -57,4 +54,12 @@
AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS, 14);
AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
CDIValidationMessages.UNSATISFIED_INJECTION_POINTS, 14);
}
+
+ public void testInjectionWInputElemnt() throws Exception {
+ IFile file =
getTestProject().getFile("src/org/jboss/beans/validation/test/Validation2.java");
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS, 9);
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
CDIValidationMessages.UNSATISFIED_INJECTION_POINTS, 11);
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS, 14);
+ AbstractResourceMarkerTest.assertMarkerIsNotCreated(file,
CDIValidationMessages.UNSATISFIED_INJECTION_POINTS, 14);
+ }
}
\ No newline at end of file