Author: akazakov
Date: 2010-03-17 09:53:36 -0400 (Wed, 17 Mar 2010)
New Revision: 20885
Modified:
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
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/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-17
13:23:17 UTC (rev 20884)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2010-03-17
13:53:36 UTC (rev 20885)
@@ -255,7 +255,7 @@
return true;
}
- static String getQualifierDeclarationKey(IAnnotationDeclaration d) throws CoreException
{
+ public static String getQualifierDeclarationKey(IAnnotationDeclaration d) throws
CoreException {
IType type = d.getType();
IMethod[] ms = type.getMethods();
StringBuffer result = new StringBuffer();
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-17
13:23:17 UTC (rev 20884)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/QualifierDefinitionTest.java 2010-03-17
13:53:36 UTC (rev 20885)
@@ -12,9 +12,9 @@
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-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;
@@ -76,14 +76,16 @@
/**
* section 2.3.3 a)
* section 3.1.3 be)
+ * @throws CoreException
*/
- public void testQualifiersDeclaredInJava() {
- Set<IBean> beans = cdiProject.getBeans(true,
"org.jboss.jsr299.tck.tests.definition.qualifier.Cat",
"org.jboss.jsr299.tck.tests.definition.qualifier.SynchronousQualifier");
- assertEquals("Wrong number of beans with
org.jboss.jsr299.tck.tests.definition.qualifier.Cat type and
org.jboss.jsr299.tck.tests.definition.qualifier.SynchronousQualifier qualifier.", 1,
beans.size());
+ public void testQualifiersDeclaredInJava() throws CoreException {
+ IQualifierDeclaration synchronous =
getQualifierDeclarationFromBeanClass("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/Cat.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Synchronous");
+ Set<IBean> beans = cdiProject.getBeans(true,
"org.jboss.jsr299.tck.tests.definition.qualifier.Cat",
"org.jboss.jsr299.tck.tests.definition.qualifier.Synchronous");
+ assertEquals("Wrong number of beans with
org.jboss.jsr299.tck.tests.definition.qualifier.Cat type and
org.jboss.jsr299.tck.tests.definition.qualifier.Synchronous qualifier.", 1,
beans.size());
IBean bean = beans.iterator().next();
Set<IQualifier> qualifiers = bean.getQualifiers();
assertEquals("Wrong number of qualifiers.", 2, qualifiers.size());
- assertContainsQualifierType(bean,
"org.jboss.jsr299.tck.tests.definition.qualifier.SynchronousQualifier");
+ assertContainsQualifier(bean, synchronous);
Set<IQualifierDeclaration> declarations = bean.getQualifierDeclarations();
assertEquals("Wrong number of qualifier declarations.", 1,
declarations.size());
// TODO use correct start position instead of 0.
@@ -95,8 +97,8 @@
* @throws JavaModelException
*/
public void testMultipleQualifiers() throws JavaModelException {
- IAnnotationDeclaration chunky =
getAnnotationDeclarationFromBean("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/Cod.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Chunky");
- IAnnotationDeclaration whitefish =
getAnnotationDeclarationFromBean("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/Cod.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Whitefish");
+ IQualifierDeclaration chunky =
getQualifierDeclarationFromBeanClass("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/Cod.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Chunky");
+ IQualifierDeclaration whitefish =
getQualifierDeclarationFromBeanClass("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/Cod.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Whitefish");
IType type = getType("org.jboss.jsr299.tck.tests.definition.qualifier.Cod");
Set<IBean> beans = cdiProject.getBeans(true, type, chunky, whitefish);
assertEquals("Wrong number of beans.", 1, beans.size());
@@ -140,17 +142,17 @@
/**
* section 4.1 aa)
- * @throws JavaModelException
+ * @throws CoreException
*/
- public void testQualifierDeclaredInheritedIsInherited() throws JavaModelException {
- IAnnotationDeclaration hairy =
getAnnotationDeclarationFromBean("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/LongHairedDog.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
+ public void testQualifierDeclaredInheritedIsInherited() throws CoreException {
+ IQualifierDeclaration hairy =
getQualifierDeclarationFromBeanClass("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/LongHairedDog.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
IType type =
getType("org.jboss.jsr299.tck.tests.definition.qualifier.BorderCollie");
Set<IBean> beans = cdiProject.getBeans(true, type, hairy);
assertEquals("Wrong number of beans.", 1, beans.size());
IBean bean = beans.iterator().next();
Set<IQualifier> qualifiers = bean.getQualifiers();
assertEquals("Wrong number of qualifiers for
org.jboss.jsr299.tck.tests.definition.qualifier.BorderCollie type.", 2,
qualifiers.size());
- assertContainsQualifierType(bean,
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
+ assertContainsQualifier(bean, hairy);
assertContainsQualifierType(bean, "javax.enterprise.inject.Any");
}
@@ -172,39 +174,33 @@
/**
* section 4.1 aa)
- * @throws JavaModelException
+ * @throws CoreException
*/
- public void testQualifierDeclaredInheritedIsBlockedByIntermediateClass() throws
JavaModelException {
- IAnnotationDeclaration hairy =
getAnnotationDeclarationFromBean("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/ClippedBorderCollie.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
+ public void testQualifierDeclaredInheritedIsBlockedByIntermediateClass() throws
CoreException {
+ IQualifierDeclaration hairy =
getQualifierDeclarationFromBeanClass("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/ClippedBorderCollie.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
IType type =
getType("org.jboss.jsr299.tck.tests.definition.qualifier.ClippedBorderCollie");
Set<IBean> beans = cdiProject.getBeans(true, type, hairy);
assertEquals("Wrong number of beans.", 1, beans.size());
IBean bean = beans.iterator().next();
Set<IQualifier> qualifiers = bean.getQualifiers();
assertEquals("Wrong number of qualifiers for
org.jboss.jsr299.tck.tests.definition.qualifier.ClippedBorderCollie type.", 2,
qualifiers.size());
- assertContainsQualifierType(bean,
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
+ assertContainsQualifier(bean, hairy);
assertContainsQualifierType(bean, "javax.enterprise.inject.Any");
}
/**
* section 4.1 ag)
- * @throws JavaModelException
+ * @throws CoreException
*/
- public void testQualifierDeclaredInheritedIsIndirectlyInherited() throws
JavaModelException {
- IAnnotationDeclaration hairy =
getAnnotationDeclarationFromBean("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/LongHairedDog.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
+ public void testQualifierDeclaredInheritedIsIndirectlyInherited() throws CoreException
{
+ IQualifierDeclaration hairy =
getQualifierDeclarationFromBeanClass("JavaSource/org/jboss/jsr299/tck/tests/definition/qualifier/LongHairedDog.java",
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
IType type =
getType("org.jboss.jsr299.tck.tests.definition.qualifier.EnglishBorderCollie");
Set<IBean> beans = cdiProject.getBeans(true, type, hairy);
assertEquals("Wrong number of beans.", 1, beans.size());
IBean bean = beans.iterator().next();
Set<IQualifier> qualifiers = bean.getQualifiers();
assertEquals("Wrong number of qualifiers for
org.jboss.jsr299.tck.tests.definition.qualifier.EnglishBorderCollie type.", 2,
qualifiers.size());
- assertContainsQualifierType(bean,
"org.jboss.jsr299.tck.tests.definition.qualifier.Hairy");
+ assertContainsQualifier(bean, hairy);
assertContainsQualifierType(bean, "javax.enterprise.inject.Any");
-
-// Set<? extends Annotation> bindings = getBeans(
-// EnglishBorderCollie.class, new HairyQualifier(false))
-// .iterator().next().getQualifiers();
-// assert bindings.size() == 2;
-// assert bindings.contains(new HairyQualifier(false));
}
}
\ No newline at end of file
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-17
13:23:17 UTC (rev 20884)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java 2010-03-17
13:53:36 UTC (rev 20885)
@@ -10,6 +10,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
@@ -23,6 +24,8 @@
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IQualifier;
+import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.cdi.internal.core.impl.CDIProject;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.text.ITextSourceReference;
@@ -111,10 +114,26 @@
return beans;
}
- protected IAnnotationDeclaration getAnnotationDeclarationFromBean(String
beanClassFilePath, String annotationTypeName) throws JavaModelException {
+ protected IQualifierDeclaration getQualifierDeclarationFromBeanClass(String
beanClassFilePath, String annotationTypeName) throws JavaModelException {
IFile file = tckProject.getFile(beanClassFilePath);
Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
IBean bean = beans.iterator().next();
+ Set<IQualifierDeclaration> declarations = bean.getQualifierDeclarations();
+ IType type = getType(annotationTypeName);
+ for (IQualifierDeclaration declaration : declarations) {
+ IAnnotation annotation = declaration.getDeclaration();
+ if(type.getElementName().equals(annotation.getElementName())) {
+ return declaration;
+ }
+ }
+ fail("Can't find " + annotationTypeName + " qualifier in " +
beanClassFilePath + " bean.");
+ return null;
+ }
+
+ protected IAnnotationDeclaration createAnnotationDeclarationForAnnotation(String
beanClassFilePath, String annotationTypeName) throws JavaModelException {
+ IFile file = tckProject.getFile(beanClassFilePath);
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+ IBean bean = beans.iterator().next();
final IType beanClass = bean.getBeanClass();
final IType type = getType(annotationTypeName);
final IAnnotation annotation = beanClass.getAnnotation(type.getElementName());
@@ -195,6 +214,29 @@
fail(bean.getResource().getFullPath() + " bean " + allTypes.toString() +
" should have " + typeName + " type.");
}
+ public static void assertContainsQualifier(IBean bean, IQualifierDeclaration
declaration) throws CoreException {
+ String typeName = declaration.getQualifier().getSourceType().getFullyQualifiedName();
+ Set<IQualifier> qualifiers = bean.getQualifiers();
+ StringBuffer allTypes = new StringBuffer("[");
+ boolean found = false;
+ for (IQualifier qualifier : qualifiers) {
+ allTypes.append("
").append(qualifier.getSourceType().getFullyQualifiedName()).append(";");
+ if (typeName.equals(qualifier.getSourceType().getFullyQualifiedName())) {
+ found = true;
+ break;
+ }
+ }
+ allTypes.append("]");
+ assertTrue(bean.getResource().getFullPath() + " bean (qualifiers - " +
allTypes.toString() + ") should have the qualifier with " + typeName + "
type.", found);
+ Set<IQualifierDeclaration> declarations = bean.getQualifierDeclarations(true);
+ for (IQualifierDeclaration d : declarations) {
+ if(CDIProject.getQualifierDeclarationKey(d).equals(CDIProject.getQualifierDeclarationKey(declaration))
) {
+ return;
+ }
+ }
+ fail(bean.getResource().getFullPath() + " bean (qualifiers - " +
allTypes.toString() + ") should have the qualifier declaration with " + typeName
+ " type.");
+ }
+
public static void assertContainsQualifierType(IBean bean, String typeName) {
Set<IQualifier> qualifiers = bean.getQualifiers();
StringBuffer allTypes = new StringBuffer("[");