Author: akazakov
Date: 2010-03-09 12:30:08 -0500 (Tue, 09 Mar 2010)
New Revision: 20708
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/internal/core/impl/CDIProject.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanDefinitionTest.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.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/IBeanManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-03-09
17:27:13 UTC (rev 20707)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-03-09
17:30:08 UTC (rev 20708)
@@ -108,6 +108,28 @@
Set<IBean> getBeans(boolean attemptToResolveAmbiguousDependency, IType beanType,
IType... qualifiers);
/**
+ * Returns the set of beans which have the given required type and qualifier
+ * type If no qualifiers are given, the
+ * {@linkplain javax.enterprise.inject.Default default qualifier} is
+ * assumed.
+ *
+ * @param fullQualifiedBeanType
+ * the required bean type
+ * @param fullQualifiedQualifiersTypes
+ * the required qualifiers
+ * @param attemptToResolveAmbiguousDependency
+ * if there are a few beans with the given type and qualifiers
+ * and attemptToResolveAmbiguousDependency==true the manager
+ * should try to resolve the ambiguity. If any of the beans are
+ * alternatives, the manager will eliminate all beans that are
+ * not alternatives, expect for producer methods and fields of
+ * beans that are alternatives.
+ *
+ * @return the resulting set of beans
+ */
+ Set<IBean> getBeans(boolean attemptToResolveAmbiguousDependency, String
fullQualifiedBeanType, String... fullQualifiedQualifiersTypes);
+
+ /**
* Returns the set of beans which are eligible for the given injection
* points.
*
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-09
17:27:13 UTC (rev 20707)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-03-09
17:30:08 UTC (rev 20708)
@@ -11,6 +11,7 @@
package org.jboss.tools.cdi.internal.core.impl;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -41,7 +42,6 @@
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;
-import org.jboss.tools.cdi.internal.core.impl.definition.ParametedTypeFactory;
import org.jboss.tools.cdi.internal.core.impl.definition.TypeDefinition;
import org.jboss.tools.common.text.INodeReference;
@@ -692,6 +692,17 @@
public Set<IBean> getBeans(boolean attemptToResolveAmbiguousDependency,
IType beanType, IType... qualifiers) {
// TODO
- return null;
+ return Collections.emptySet();
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IBeanManager#getBeans(boolean, java.lang.String,
java.lang.String[])
+ */
+ public Set<IBean> getBeans(boolean attemptToResolveAmbiguousDependency,
+ String fullQualifiedBeanType,
+ String... fullQualifiedQualifiersTypes) {
+ // TODO
+ return Collections.emptySet();
+ }
}
\ No newline at end of file
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanDefinitionTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanDefinitionTest.java 2010-03-09
17:27:13 UTC (rev 20707)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanDefinitionTest.java 2010-03-09
17:30:08 UTC (rev 20708)
@@ -13,7 +13,6 @@
import java.util.Set;
import org.eclipse.core.resources.IFile;
-import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IQualifier;
@@ -29,11 +28,14 @@
/**
* Section 2 - Concepts
* a) A bean comprises of a (nonempty) set of bean types.
+ * @throws JavaModelException
*/
- public void testBeanTypesNonEmpty() {
+ public void testBeanTypesNonEmpty() throws JavaModelException {
IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/bean/RedSnapper.java");
Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
assertEquals("There should be the only bean in
org.jboss.jsr299.tck.tests.definition.bean.RedSnapper", 1, beans.size());
+ beans = cdiProject.getBeans(true,
"org.jboss.jsr299.tck.tests.definition.bean.RedSnapper");
+ assertEquals("There should be the only bean in
org.jboss.jsr299.tck.tests.definition.bean.RedSnapper", 1, beans.size());
IBean bean = beans.iterator().next();
assertTrue("No legal types were found for
org.jboss.jsr299.tck.tests.definition.bean.RedSnapper bean.",
bean.getLegalTypes().size() > 0);
Set<ITypeDeclaration> declarations = bean.getAllTypeDeclarations();
@@ -47,10 +49,12 @@
* b) A bean comprises of a (nonempty) set of qualifiers.
* Section 11.1 - The Bean interface
* ba) getTypes(), getQualifiers(), getScope(), getName() and getStereotypes() must
return the bean types, qualifiers, scope type, EL name and stereotypes of the bean, as
defined in Chapter 2, Concepts.
+ * @throws JavaModelException
*/
- public void testQualifiersNonEmpty() {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/bean/RedSnapper.java");
- Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+ public void testQualifiersNonEmpty() throws JavaModelException {
+// IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/bean/RedSnapper.java");
+// Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+ Set<IBean> beans =
getBeans("org.jboss.jsr299.tck.tests.definition.bean.RedSnapper");
Set<IQualifier> qs = beans.iterator().next().getQualifiers();
assertTrue("No qualifiers were found for
org.jboss.jsr299.tck.tests.definition.bean.RedSnapper bean.", qs.size() > 0);
@@ -84,11 +88,13 @@
* ba) Test a bean with a scope.
* Section 11.1 - The Bean interface
* ba) getTypes(), getQualifiers(), getScope(), getName() and getStereotypes() must
return the bean types, qualifiers, scope type, EL name and stereotypes of the bean, as
defined in Chapter 2, Concepts.
+ * @throws JavaModelException
*
*/
- public void testHasScopeType() {
- IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/bean/RedSnapper.java");
- Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+ public void testHasScopeType() throws JavaModelException {
+// IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/bean/RedSnapper.java");
+// Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+ Set<IBean> beans =
getBeans("org.jboss.jsr299.tck.tests.definition.bean.RedSnapper");
IBean bean = beans.iterator().next();
IScope scope = bean.getScope();
assertNotNull("org.jboss.jsr299.tck.tests.definition.bean.RedSnapper bean
desn't have a scope.", scope);
@@ -103,16 +109,22 @@
* @throws JavaModelException
*/
public void testPrivitiveTypes() throws JavaModelException {
- IType type = getType("java.lang.Integer");
- Set<IBean> beans = cdiProject.getBeans(true, type, new IType[0]);
- assertNotNull("There should be the only bean with int type", beans);
- assertEquals("There should be the only bean with int type", 1,
beans.size());
- type = getType("org.jboss.jsr299.tck.tests.definition.bean.Animal");
- beans = cdiProject.getBeans(true, type, new IType[0]);
- assertNotNull("There should be the only bean with
org.jboss.jsr299.tck.tests.definition.bean.Animal type", beans);
- assertEquals("There should be the only bean with
org.jboss.jsr299.tck.tests.definition.bean.Animal type", 1, beans.size());
+ assertTheOnlyBean("java.lang.Integer");
+ assertTheOnlyBean("org.jboss.jsr299.tck.tests.definition.bean.Animal");
}
+ public void testBeanTypes() {
+// assert getBeans(Tarantula.class).size() == 1;
+// Bean<Tarantula> bean = getBeans(Tarantula.class).iterator().next();
+// assert bean.getTypes().size() == 6;
+// assert bean.getTypes().contains(Tarantula.class);
+// assert bean.getTypes().contains(Spider.class);
+// assert bean.getTypes().contains(Animal.class);
+// assert bean.getTypes().contains(Object.class);
+// assert bean.getTypes().contains(DeadlySpider.class);
+// assert bean.getTypes().contains(DeadlyAnimal.class);
+ }
+
/**
* e) A bean comprises of an optional bean EL name.
*/
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java 2010-03-09
17:27:13 UTC (rev 20707)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java 2010-03-09
17:30:08 UTC (rev 20708)
@@ -2,6 +2,7 @@
import java.io.File;
import java.io.FileFilter;
+import java.util.Set;
import junit.framework.TestCase;
@@ -14,6 +15,7 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
@@ -94,6 +96,19 @@
return project;
}
+ protected Set<IBean> getBeans(String typeName) throws JavaModelException {
+ IType type = getType(typeName);
+ assertNotNull("Can't find " + typeName + " type.", type);
+ Set<IBean> beans = cdiProject.getBeans(true, type, new IType[0]);
+ assertNotNull("There is no eny beans with " + typeName + " type",
beans);
+ return beans;
+ }
+
+ protected void assertTheOnlyBean(String typeName) throws JavaModelException {
+ Set<IBean> beans = getBeans(typeName);
+ assertEquals("There should be the only bean with " + typeName + "
type", 1, beans.size());
+ }
+
static class JavaFileFilter implements FileFilter {
public boolean accept(File pathname) {
String name = pathname.getName();