Author: akazakov
Date: 2010-05-27 11:47:31 -0400 (Thu, 27 May 2010)
New Revision: 22376
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanSpecializationTest.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSuite.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-5808
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-05-27
15:31:26 UTC (rev 22375)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDIUtil.java 2010-05-27
15:47:31 UTC (rev 22376)
@@ -216,32 +216,55 @@
}
/**
- * Return @Named declaration or the stereotype declaration if it declares
+ * Return @Named declaration or the stereotype declaration if it declares @Named.
*
- * @Named.
+ * @param stereotyped
+ * @return
+ */
+ public static IAnnotationDeclaration getNamedDeclaration(IBean bean) {
+ return getQualifierDeclaration(bean, CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ }
+
+ /**
+ * Return the qualifier declaration or the stereotype or @Specializes declaration if it
declares this qualifier.
*
* @param stereotyped
* @return
*/
- public static IAnnotationDeclaration getNamedDeclaration(IBean bean) {
- IAnnotationDeclaration declaration =
bean.getAnnotation(CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ public static IAnnotationDeclaration getQualifierDeclaration(IBean bean, String
qualifierTypeName) {
+ IAnnotationDeclaration declaration = bean.getAnnotation(qualifierTypeName);
if (declaration == null) {
- return getNamedStereotypeDeclaration(bean);
+ declaration = getQualifiedStereotypeDeclaration(bean, qualifierTypeName);
}
+ if(declaration == null) {
+ declaration = getQualifiedSpecializesDeclaration(bean, qualifierTypeName);
+ }
return declaration;
}
/**
- * Return the stereotype declaration which declares @Named.
+ * Returns the @Specializes declaration of the bean if the specialized bean declares the
given qualifier.
*
+ * @param bean
+ * @param qualifierTypeName
+ * @return
+ */
+ public static IAnnotationDeclaration getQualifiedSpecializesDeclaration(IBean bean,
String qualifierTypeName) {
+ IBean specializedBean = bean.getSpecializedBean();
+ return specializedBean!=null?getQualifierDeclaration(bean, qualifierTypeName):null;
+ }
+
+ /**
+ * Return the stereotype declaration which declares the given qualifier.
+ *
* @param stereotyped
* @return
*/
- public static IAnnotationDeclaration getNamedStereotypeDeclaration(IStereotyped
stereotyped) {
+ public static IAnnotationDeclaration getQualifiedStereotypeDeclaration(IStereotyped
stereotyped, String qualifierTypeName) {
Set<IStereotypeDeclaration> declarations =
stereotyped.getStereotypeDeclarations();
for (IStereotypeDeclaration declaration : declarations) {
- if
(CDIConstants.NAMED_QUALIFIER_TYPE_NAME.equals(declaration.getType().getFullyQualifiedName())
- || getNamedStereotypeDeclaration(declaration.getStereotype()) != null) {
+ if (qualifierTypeName.equals(declaration.getType().getFullyQualifiedName())
+ || getQualifiedStereotypeDeclaration(declaration.getStereotype(), qualifierTypeName)
!= null) {
return declaration;
}
}
@@ -249,6 +272,16 @@
}
/**
+ * Return the stereotype declaration which declares @Named.
+ *
+ * @param stereotyped
+ * @return
+ */
+ public static IAnnotationDeclaration getNamedStereotypeDeclaration(IStereotyped
stereotyped) {
+ return getQualifiedStereotypeDeclaration(stereotyped,
CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ }
+
+ /**
* Returns all found annotations for parameters of the method.
*
* @param method
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-27
15:31:26 UTC (rev 22375)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/errorList.txt 2010-05-27
15:47:31 UTC (rev 22376)
@@ -126,6 +126,12 @@
- X specializes Y and Y has a name and X declares a name explicitly, using @Named
- interceptor or decorator is annotated @Specializes (Non-Portable behavior)
+
+
+
+
+
+
5.2.2. Legal injection point types
- injection point type is a type variable
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSuite.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSuite.java 2010-05-27
15:31:26 UTC (rev 22375)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSuite.java 2010-05-27
15:47:31 UTC (rev 22376)
@@ -23,6 +23,7 @@
import org.jboss.tools.cdi.core.test.tck.ProducerMethodDefinitionTest;
import org.jboss.tools.cdi.core.test.tck.QualifierDefinitionTest;
import org.jboss.tools.cdi.core.test.tck.ScopeDefinitionTest;
+import org.jboss.tools.cdi.core.test.tck.BeanSpecializationTest;
import org.jboss.tools.cdi.core.test.tck.StereotypeDefinitionTest;
import org.jboss.tools.cdi.core.test.tck.StereotypeInheritenceTest;
import org.jboss.tools.cdi.core.test.tck.ValidationTest;
@@ -46,6 +47,7 @@
suite.addTestSuite(StereotypeInheritenceTest.class);
suite.addTestSuite(ProducerMethodDefinitionTest.class);
suite.addTestSuite(InjectionPointTest.class);
+ suite.addTestSuite(BeanSpecializationTest.class);
suite.addTestSuite(ValidationTest.class);
return suite;
}
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanSpecializationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanSpecializationTest.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanSpecializationTest.java 2010-05-27
15:47:31 UTC (rev 22376)
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.core.test.tck;
+
+import java.util.Set;
+
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.cdi.core.IBean;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class BeanSpecializationTest extends TCKTest {
+
+ /**
+ * Section 4.3.1 - Direct and indirect specialization
+ * j) A bean X that specializes bean Y will include all qualifiers of Y, together with
all qualifiers declared explicitly by X.
+ *
+ * @throws JavaModelException
+ */
+ public void testSimpleSpecializingBeanHasQualifiersOfSpecializedAndSpecializingBean()
throws JavaModelException {
+ Set<IBean> beans = cdiProject.getBeans(true,
"org.jboss.jsr299.tck.tests.inheritance.specialization.simple.LazyFarmer",
"org.jboss.jsr299.tck.tests.inheritance.specialization.simple.Landowner");
+ assertEquals("Wrong number of beans.", 1, beans.size());
+ IBean bean = beans.iterator().next();
+ assertContainsBeanType(bean,
"org.jboss.jsr299.tck.tests.inheritance.specialization.simple.Farmer");
+ assertContainsQualifierType(true, bean,
+ "org.jboss.jsr299.tck.tests.inheritance.specialization.simple.Landowner",
+ "org.jboss.jsr299.tck.tests.inheritance.specialization.simple.Lazy",
+ "javax.enterprise.inject.Any",
+ "javax.inject.Named");
+ }
+
+ /**
+ * Section 4.3.1 - Direct and indirect specialization
+ * j) A bean X that specializes bean Y will include all qualifiers of Y, together with
all qualifiers declared explicitly by X.
+ *
+ * @throws JavaModelException
+ */
+ public void
testEnterpriseSpecializingBeanHasQualifiersOfSpecializedAndSpecializingBean() throws
JavaModelException {
+ Set<IBean> beans = cdiProject.getBeans(true,
"org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.LazyFarmerLocal",
"org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.Landowner");
+ assertEquals("Wrong number of beans.", 1, beans.size());
+ IBean bean = beans.iterator().next();
+ assertContainsBeanType(bean,
"org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.FarmerLocal");
+ assertContainsQualifierType(true, bean,
+ "org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.Landowner",
+ "org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.Lazy",
+ "javax.enterprise.inject.Any",
+ "javax.inject.Named");
+ }
+
+ /**
+ * Section 4.3.1 - Direct and indirect specialization
+ * k) A bean X that specializes bean Y will have the same name as Y if Y has a name.
+ *
+ * @throws JavaModelException
+ */
+ public void testSimpleSpecializingBeanHasNameOfSpecializedBean() throws
JavaModelException {
+ Set<IBean> beans = cdiProject.getBeans(true,
"org.jboss.jsr299.tck.tests.inheritance.specialization.simple.LazyFarmer",
"org.jboss.jsr299.tck.tests.inheritance.specialization.simple.Landowner");
+ assertEquals("Wrong number of beans.", 1, beans.size());
+ IBean bean = beans.iterator().next();
+ assertEquals("Incorrect bean name", "farmer", bean.getName());
+ }
+
+ /**
+ * Section 4.3.1 - Direct and indirect specialization
+ * k) A bean X that specializes bean Y will have the same name as Y if Y has a name.
+ *
+ * @throws JavaModelException
+ */
+ public void testEnterpriseSpecializingBeanHasNameOfSpecializedBean() throws
JavaModelException {
+ Set<IBean> beans = cdiProject.getBeans(true,
"org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.LazyFarmerLocal",
"org.jboss.jsr299.tck.tests.inheritance.specialization.enterprise.Landowner");
+ assertEquals("Wrong number of beans.", 1, beans.size());
+ IBean bean = beans.iterator().next();
+ assertEquals("Incorrect bean name", "farmer", bean.getName());
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/BeanSpecializationTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-05-27
15:31:26 UTC (rev 22375)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java 2010-05-27
15:47:31 UTC (rev 22376)
@@ -2,7 +2,6 @@
import java.io.File;
import java.io.FileFilter;
-import java.util.HashSet;
import java.util.Set;
import junit.framework.TestCase;
@@ -24,8 +23,6 @@
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IClassBean;
-import org.jboss.tools.cdi.core.IInjectionPoint;
-import org.jboss.tools.cdi.core.IInjectionPointParameter;
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
@@ -254,17 +251,33 @@
fail(bean.getResource().getFullPath() + " bean (qualifiers - " +
allTypes.toString() + ") should have the qualifier declaration with " + typeName
+ " type.");
}
- public static void assertContainsQualifierType(IBean bean, String typeName) {
+ public static void assertContainsQualifierType(IBean bean, String... typeNames) {
+ assertContainsQualifierType(false, bean, typeNames);
+ }
+
+ public static void assertContainsQualifierType(boolean
theNumbersOfQualifierShouldBeTheSame, IBean bean, String... typeNames) {
Set<IQualifier> qualifiers = bean.getQualifiers();
+
+ if(theNumbersOfQualifierShouldBeTheSame) {
+ assertEquals("Defferent numbers of qualifiers", typeNames.length,
qualifiers.size());
+ }
+
StringBuffer allTypes = new StringBuffer("[");
for (IQualifier qualifier : qualifiers) {
allTypes.append("
").append(qualifier.getSourceType().getFullyQualifiedName()).append(";");
- if (typeName.equals(qualifier.getSourceType().getFullyQualifiedName())) {
- return;
+ }
+ allTypes.append("]");
+
+ for (String typeName : typeNames) {
+ boolean found = false;
+ for (IQualifier qualifier : qualifiers) {
+ if (typeName.equals(qualifier.getSourceType().getFullyQualifiedName())) {
+ found = true;
+ break;
+ }
}
+ assertTrue(bean.getResource().getFullPath() + " bean (qualifiers - " +
allTypes.toString() + ") should have the qualifier with " + typeName + "
type.", found);
}
- allTypes.append("]");
- fail(bean.getResource().getFullPath() + " bean (qualifiers - " +
allTypes.toString() + ") should have the qualifier with " + typeName + "
type.");
}
public static void assertLocationEquals(ITextSourceReference reference, int
startPosition, int length) {