Author: akazakov
Date: 2010-03-16 12:05:11 -0400 (Tue, 16 Mar 2010)
New Revision: 20844
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/QualifierDefinitionTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5808
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java 2010-03-16
15:27:48 UTC (rev 20843)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java 2010-03-16
16:05:11 UTC (rev 20844)
@@ -85,7 +85,7 @@
*
* @return the qualifiers
*/
- Set<IAnnotationDeclaration> getQualifierDeclarations();
+ Set<IQualifierDeclaration> getQualifierDeclarations();
/**
* Obtains the qualifiers of the bean class or producer method or field.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-03-16
15:27:48 UTC (rev 20843)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-03-16
16:05:11 UTC (rev 20844)
@@ -130,10 +130,10 @@
* Returns the set of beans which are eligible for the given injection
* points.
*
- * @param injectionPoints
+ * @param injectionPoint
* @return the resulting set of beans
*/
- Set<IBean> getBeans(IInjectionPoint injectionPoints);
+ Set<IBean> getBeans(IInjectionPoint injectionPoint);
/**
* Returns the bean which is declared in the given IType.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java 2010-03-16
15:27:48 UTC (rev 20843)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IInjectionPoint.java 2010-03-16
16:05:11 UTC (rev 20844)
@@ -12,8 +12,6 @@
import java.util.Set;
-import org.eclipse.jdt.core.IType;
-
/**
* Represents an injection point.
*
@@ -33,7 +31,7 @@
*
* @return the required qualifiers
*/
- Set<IAnnotationDeclaration> getQualifierDeclarations();
+ Set<IQualifierDeclaration> getQualifierDeclarations();
/**
* Determines if the injection point is a decorator delegate injection
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-03-16
15:27:48 UTC (rev 20843)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-03-16
16:05:11 UTC (rev 20844)
@@ -17,12 +17,10 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IAnnotation;
-import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMemberValuePair;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
@@ -38,9 +36,6 @@
import org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.AbstractTypeDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
-import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
-import org.jboss.tools.common.model.util.EclipseJavaUtil;
-import org.jboss.tools.common.util.FileUtil;
/**
*
@@ -94,12 +89,12 @@
return result;
}
- public Set<IAnnotationDeclaration> getQualifierDeclarations() {
- Set<IAnnotationDeclaration> result = new
HashSet<IAnnotationDeclaration>();
+ public Set<IQualifierDeclaration> getQualifierDeclarations() {
+ Set<IQualifierDeclaration> result = new HashSet<IQualifierDeclaration>();
for(AnnotationDeclaration a: definition.getAnnotations()) {
int k = getCDIProject().getNature().getDefinitions().getAnnotationKind(a.getType());
if(k == AnnotationDefinition.QUALIFIER) {
- result.add(a);
+ result.add((IQualifierDeclaration)a);
}
}
return result;
@@ -111,12 +106,10 @@
IQualifier name =
getCDIProject().getQualifier(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
Set<IQualifier> result = new HashSet<IQualifier>();
- Set<IAnnotationDeclaration> ds = getQualifierDeclarations();
- for (IAnnotationDeclaration d: ds) {
- if(d instanceof IQualifierDeclaration) {
- IQualifier q = ((IQualifierDeclaration)d).getQualifier();
- if(q != null) result.add(q);
- }
+ Set<IQualifierDeclaration> ds = getQualifierDeclarations();
+ for (IQualifierDeclaration d: ds) {
+ IQualifier q = d.getQualifier();
+ if(q != null) result.add(q);
}
if(this instanceof IInjectionPoint) {
if(def != null && result.isEmpty()) {
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-03-16
15:27:48 UTC (rev 20843)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-03-16
16:05:11 UTC (rev 20844)
@@ -40,6 +40,7 @@
import org.jboss.tools.cdi.core.IObserverMethod;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IProducer;
+import org.jboss.tools.cdi.core.IQualifierDeclaration;
import org.jboss.tools.cdi.core.IStereotype;
import org.jboss.tools.cdi.internal.core.impl.definition.AnnotationDefinition;
import org.jboss.tools.cdi.internal.core.impl.definition.BeansXMLDefinition;
@@ -189,7 +190,7 @@
return result;
}
- Set<IAnnotationDeclaration> qs = injectionPoints.getQualifierDeclarations();
+ Set<IQualifierDeclaration> qs = injectionPoints.getQualifierDeclarations();
Set<IBean> beans = new HashSet<IBean>();
synchronized(allBeans) {
@@ -199,7 +200,7 @@
Set<IParametedType> types = b.getLegalTypes();
if(containsType(types, type)) {
try {
- Set<IAnnotationDeclaration> qsb = b.getQualifierDeclarations();
+ Set<IQualifierDeclaration> qsb = b.getQualifierDeclarations();
if(areMatchingQualifiers(qsb, qs)) {
result.add(b);
}
@@ -219,7 +220,7 @@
return false;
}
- public static boolean areMatchingQualifiers(Set<IAnnotationDeclaration>
beanQualifiers, Set<IAnnotationDeclaration> injectionQualifiers) throws
CoreException {
+ public static boolean areMatchingQualifiers(Set<? extends IAnnotationDeclaration>
beanQualifiers, Set<? extends IAnnotationDeclaration> injectionQualifiers) throws
CoreException {
if(beanQualifiers == null || beanQualifiers.isEmpty()) {
if(injectionQualifiers == null || injectionQualifiers.isEmpty()) {
return true;
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/QualifierDefinitionTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/QualifierDefinitionTest.java 2010-03-16
15:27:48 UTC (rev 20843)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/QualifierDefinitionTest.java 2010-03-16
16:05:11 UTC (rev 20844)
@@ -17,7 +17,9 @@
import org.jboss.tools.cdi.core.IAnnotationDeclaration;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IInjectionPoint;
+import org.jboss.tools.cdi.core.IProducerMethod;
import org.jboss.tools.cdi.core.IQualifier;
+import org.jboss.tools.cdi.core.IQualifierDeclaration;
/**
* @author Alexey Kazakov
@@ -82,7 +84,7 @@
Set<IQualifier> qualifiers = bean.getQualifiers();
assertEquals("Wrong number of qualifiers.", 2, qualifiers.size());
assertContainsQualifierType(bean,
"org.jboss.jsr299.tck.tests.definition.qualifier.SynchronousQualifier");
- Set<IAnnotationDeclaration> declarations = bean.getQualifierDeclarations();
+ Set<IQualifierDeclaration> declarations = bean.getQualifierDeclarations();
assertEquals("Wrong number of qualifier declarations.", 1,
declarations.size());
// TODO use correct start position instead of 0.
assertLocationEquals(declarations, 0, 12);
@@ -101,5 +103,38 @@
IBean bean = beans.iterator().next();
Set<IQualifier> qualifiers = bean.getQualifiers();
assertEquals("Wrong number of qualifiers.", 4, qualifiers.size());
+ Set<IQualifierDeclaration> declarations = bean.getQualifierDeclarations();
+ assertEquals("Wrong number of qualifier declarations.", 2,
declarations.size());
+ // TODO use correct start position instead of 0.
+ assertLocationEquals(declarations, 0, 6);
+ assertLocationEquals(declarations, 0, 9);
}
+
+ /**
+ * section 2.3.5 a)
+ * @throws JavaModelException
+ */
+ public void testFieldInjectedFromProducerMethod() throws JavaModelException {
+ Set<IBean> beans =
getBeans("org.jboss.jsr299.tck.tests.definition.qualifier.Barn");
+ assertEquals("Wrong number of beans with
org.jboss.jsr299.tck.tests.definition.qualifier.Barn type.", 1, beans.size());
+ IBean bean = beans.iterator().next();
+ Set<IInjectionPoint> points = bean.getInjectionPoints();
+ IInjectionPoint point = points.iterator().next();
+ Set<IQualifierDeclaration> declarations = point.getQualifierDeclarations();
+ assertEquals("Wrong number of qualifier declarations.", 1,
declarations.size());
+ // TODO use correct start position instead of 0.
+ assertLocationEquals(declarations, 0, 5);
+
+ Set<IBean> injectedBeans = cdiProject.getBeans(point);
+ assertEquals("Wrong number of beans.", 1, injectedBeans.size());
+ IBean injectedBean = injectedBeans.iterator().next();
+ IType beanClass = injectedBean.getBeanClass();
+ assertEquals("Wrong bean class.",
"org.jboss.jsr299.tck.tests.definition.qualifier.SpiderProducer",
beanClass.getFullyQualifiedName());
+ assertTrue("The bean should be a producer method.", injectedBean instanceof
IProducerMethod);
+ IProducerMethod producer = (IProducerMethod)injectedBean;
+ declarations = producer.getQualifierDeclarations();
+ assertEquals("Wrong number of qualifier declarations.", 1,
declarations.size());
+ // TODO use correct start position instead of 0.
+ assertLocationEquals(declarations, 0, 5);
+ }
}
\ No newline at end of file