Author: akazakov
Date: 2010-06-07 13:46:33 -0400 (Mon, 07 Jun 2010)
New Revision: 22606
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ResolutionByTypeTest.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/browse/JBIDE-6418
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2010-06-07
17:05:44 UTC (rev 22605)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/MethodDefinition.java 2010-06-07
17:46:33 UTC (rev 22606)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * Copyright (c) 2009 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java 2010-06-07
17:05:44 UTC (rev 22605)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/ParametedTypeFactory.java 2010-06-07
17:46:33 UTC (rev 22606)
@@ -1,6 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.cdi.internal.core.impl.definition;
-
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
@@ -11,6 +20,7 @@
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.internal.core.impl.ParametedType;
import org.jboss.tools.cdi.internal.core.impl.TypeDeclaration;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
@@ -36,7 +46,7 @@
try {
r = type.getNameRange();
} catch (CoreException e) {
- //ignore
+ CDICorePlugin.getDefault().logError(e);
}
if(r != null) {
parametedType = new TypeDeclaration(parametedType, r.getOffset(), r.getLength());
@@ -138,5 +148,4 @@
public void clean() {
cache.clear();
}
-
}
\ No newline at end of file
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ResolutionByTypeTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ResolutionByTypeTest.java 2010-06-07
17:05:44 UTC (rev 22605)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/ResolutionByTypeTest.java 2010-06-07
17:46:33 UTC (rev 22606)
@@ -13,9 +13,12 @@
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IType;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.common.EclipseUtil;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
/**
* @author Alexey Kazakov
@@ -24,6 +27,60 @@
/**
* Section 5.2 - Typesafe resolution
+ * lb) Test with beans without required qualifiers.
+ *
+ * @throws CoreException
+ */
+ public void testDefaultBindingTypeAssumed() throws CoreException {
+ Set<IBean> beans =
getBeans("org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Tuna");
+ assertEquals("Wrong number of the beans", 1, beans.size());
+ assertContainsBeanType(beans.iterator().next(),
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Tuna");
+ }
+
+ /**
+ * Section 5.2 - Typesafe resolution
+ * hc) Check multiple types resolve to a single getBeans().
+ *
+ * @throws CoreException
+ */
+ public void testResolveByType() throws CoreException {
+ Set<IBean> beans =
getBeans("org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Tuna",
"javax.enterprise.inject.Default");
+ assertEquals("Wrong number of the beans", 1, beans.size());
+ beans =
getBeans("org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Animal",
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.FishILike");
+ assertEquals("Wrong number of the beans", 3, beans.size());
+ assertContainsBeanClasses(beans,
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Salmon",
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.SeaBass",
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Haddock");
+ }
+
+ /**
+ * Section 5.2 - Typesafe resolution
+ * lc) Test with matching beans with matching qualifier with same type.
+ *
+ * @throws CoreException
+ */
+ public void testAllQualifiersSpecifiedForResolutionMustAppearOnBean() throws
CoreException {
+ Set<IBean> beans =
getBeans("org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Animal",
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Chunky",
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Whitefish");
+ assertEquals("Wrong number of the beans", 1, beans.size());
+ beans =
getBeans("org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.ScottishFish",
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Whitefish");
+ assertEquals("Wrong number of the beans", 2, beans.size());
+ assertContainsBeanClasses(beans,
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Cod",
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.Sole");
+ }
+
+ /**
+ * Section 5.2 - Typesafe resolution
+ * ka) Test with a parameterized type.
+ *
+ * @throws CoreException
+ */
+ public void testResolveByTypeWithTypeParameter() throws CoreException {
+ IType type =
EclipseJavaUtil.findType(EclipseUtil.getJavaProject(cdiProject.getNature().getProject()),
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.ScottishFishFarmer");
+ IParametedType parametedType =
cdiProject.getNature().getTypeFactory().getParametedType(type,
"QFarmer<QScottishFish;>;");
+ Set<IBean> beans = cdiProject.getBeans(true, parametedType, new
IQualifierDeclaration[0]);
+ assertEquals("Wrong number of the beans", 1, beans.size());
+ assertContainsBeanClasses(beans,
"org.jboss.jsr299.tck.tests.lookup.typesafe.resolution.ScottishFishFarmer");
+ }
+
+ /**
+ * Section 5.2 - Typesafe resolution
* ld) Test with matching beans with matching qualifier with same annotation member
value for each member which is not annotated @javax.enterprise.util.NonBinding.
*
* @throws CoreException
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-06-07
17:05:44 UTC (rev 22605)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java 2010-06-07
17:46:33 UTC (rev 22606)
@@ -2,6 +2,7 @@
import java.io.File;
import java.io.FileFilter;
+import java.util.HashSet;
import java.util.Set;
import junit.framework.TestCase;
@@ -108,11 +109,17 @@
return project;
}
- protected Set<IBean> getBeans(String typeName) throws JavaModelException {
+ protected Set<IBean> getBeans(String typeName, String... qualifierNames) throws
JavaModelException {
IParametedType 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);
+ Set<IType> qualifiers = new HashSet<IType>();
+ for (String name : qualifierNames) {
+ IType qualifier =
EclipseJavaUtil.findType(EclipseUtil.getJavaProject(cdiProject.getNature().getProject()),
name);
+ assertNotNull("Can't find " + name + " type.", qualifier);
+ qualifiers.add(qualifier);
+ }
+ Set<IBean> beans = cdiProject.getBeans(true, type, qualifiers.toArray(new
IType[0]));
+ assertNotNull("There is no beans with " + typeName + " type",
beans);
return beans;
}