Author: akazakov
Date: 2010-03-01 12:01:45 -0500 (Mon, 01 Mar 2010)
New Revision: 20541
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/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/DefinitionTest.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-01
13:38:01 UTC (rev 20540)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBean.java 2010-03-01
17:01:45 UTC (rev 20541)
@@ -81,13 +81,22 @@
Set<ITypeDeclaration> getRestrictedTypeDeclaratios();
/**
- * Obtains the qualifiers of the bean class or producer method or field.
+ * Obtains the qualifier declarations of the bean class or producer method or field.
*
* @return the qualifiers
*/
Set<IAnnotationDeclaration> getQualifierDeclarations();
/**
+ * Obtains the qualifiers of the bean class or producer method or field.
+ * Note a Bean has @Any (except for the special @New) and @Default qualifiers even
+ * if there is not any Qualifier declarations.
+ *
+ * @return the qualifiers
+ */
+ Set<IType> getQualifiers();
+
+ /**
* Obtains the stereotype declarations 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-01
13:38:01 UTC (rev 20540)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/IBeanManager.java 2010-03-01
17:01:45 UTC (rev 20541)
@@ -86,6 +86,28 @@
Set<IBean> getBeans(boolean attemptToResolveAmbiguousDependency, IType beanType,
IAnnotationDeclaration... 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 beanType
+ * the required bean type
+ * @param qualifiers
+ * 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, IType beanType,
IType... qualifiers);
+
+ /**
* 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/AbstractBeanElement.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-03-01
13:38:01 UTC (rev 20540)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/AbstractBeanElement.java 2010-03-01
17:01:45 UTC (rev 20541)
@@ -100,6 +100,12 @@
return result;
}
+ public Set<IType> getQualifiers() {
+ Set<IType> result = new HashSet<IType>();
+ // TODO
+ return result;
+ }
+
public Set<IScopeDeclaration> getScopeDeclarations() {
return getScopeDeclarations(getCDIProject().getNature(), definition.getAnnotations());
}
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-01
13:38:01 UTC (rev 20540)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-03-01
17:01:45 UTC (rev 20541)
@@ -684,4 +684,14 @@
}
return result;
}
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.cdi.core.IBeanManager#getBeans(boolean,
org.eclipse.jdt.core.IType, org.eclipse.jdt.core.IType[])
+ */
+ public Set<IBean> getBeans(boolean attemptToResolveAmbiguousDependency,
+ IType beanType, IType... qualifiers) {
+ // TODO
+ return null;
+ }
}
\ No newline at end of file
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/DefinitionTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/DefinitionTest.java 2010-03-01
13:38:01 UTC (rev 20540)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/DefinitionTest.java 2010-03-01
17:01:45 UTC (rev 20541)
@@ -14,6 +14,8 @@
import org.eclipse.core.resources.IFile;
import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.ITypeDeclaration;
+import org.jboss.tools.common.text.ITextSourceReference;
/**
* Section 2 - Concepts
@@ -29,6 +31,39 @@
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());
- assertTrue("No legal types were found for
org.jboss.jsr299.tck.tests.definition.bean.RedSnapper bean.",
beans.iterator().next().getLegalTypes().size() > 0);
+ 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();
+ assertEquals("There should be two type declarations in
org.jboss.jsr299.tck.tests.definition.bean.RedSnapper bean.", declarations.size(),
2);
+ assertLocationEquals(declarations, 0, 10);
+ assertLocationEquals(declarations, 0, 6);
}
+
+ /**
+ * b) A bean comprises of a (nonempty) set of qualifiers.
+ */
+ public void testQualifiersNonEmpty() {
+ IFile file =
tckProject.getFile("JavaSource/org/jboss/jsr299/tck/tests/definition/bean/RedSnapper.java");
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+ assertTrue("No qualifiers were found for
org.jboss.jsr299.tck.tests.definition.bean.RedSnapper bean.",
beans.iterator().next().getQualifiers().size() > 0);
+ }
+
+ private void assertLocationEquals(Set<? extends ITextSourceReference> references,
int startPosition, int length) {
+ for (ITextSourceReference reference : references) {
+ if(reference.getStartPosition()==startPosition) {
+ assertLocationEquals(reference, startPosition, length);
+ return;
+ }
+ }
+ StringBuffer message = new StringBuffer("Location [start
positopn=").append(startPosition).append(",
lengt=").append(length).append("] has not been found among ");
+ for (ITextSourceReference reference : references) {
+ message.append("[").append(reference.getStartPosition()).append(",
").append(reference.getLength()).append("] ");
+ }
+ fail(message.toString());
+ }
+
+ private void assertLocationEquals(ITextSourceReference reference, int startPosition, int
length) {
+ assertEquals("Wrong start position", reference.getStartPosition(),
startPosition);
+ assertEquals("Wrong length", reference.getLength(), length);
+ }
}
\ No newline at end of file