Skip to content

Commit

Permalink
ordering for specializing producer methods
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2142 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Mar 23, 2009
1 parent 0b9a945 commit 12d37b8
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 14 deletions.
Expand Up @@ -15,24 +15,10 @@ public int compare(RIBean<?> o1, RIBean<?> o2)
{
if (o1 instanceof AbstractClassBean && o2 instanceof AbstractProducerBean)
{
// AbstractProducerBean<?, ?> b2 = (AbstractProducerBean<?, ?>) o2;
// System.out.println(" declaring bean " + b2.getDeclaringBean().getType());
// if (b2.getDeclaringBean().equals(o1))
// {
// System.out.println(" class " + o1.getType() + " < producer " + o2.getType());
// return -1;
// }
return -1;
}
else if (o1 instanceof AbstractProducerBean && o2 instanceof AbstractClassBean)
{
// AbstractProducerBean<?, ?> b1 = (AbstractProducerBean<?, ?>) o1;
// System.out.println(" declaring bean " + b1.getDeclaringBean().getType());
// if (b1.getDeclaringBean().equals(o2))
// {
// System.out.println(" class " + o2.getType() + " < producer " + o1.getType());
// return 1;
// }
return 1;
}

Expand All @@ -52,6 +38,20 @@ else if (b2.getSuperclasses().contains(b1.getType().getName()))
}
}

if (o1 instanceof AbstractProducerBean && o2 instanceof AbstractProducerBean)
{
AbstractProducerBean<?, ?> b1 = (AbstractProducerBean<?, ?>) o1;
AbstractProducerBean<?, ?> b2 = (AbstractProducerBean<?, ?>) o2;
if (b1.getDeclaringBean().getSuperclasses().contains(b2.getDeclaringBean().getType().getName()))
{
return 1;
}
else if (b2.getDeclaringBean().getSuperclasses().contains(b1.getDeclaringBean().getType().getName()))
{
return -1;
}
}

if (o1 instanceof AbstractStandardBean && !(o2 instanceof AbstractStandardBean))
{
return -1;
Expand Down
@@ -0,0 +1,20 @@
package org.jboss.webbeans.test.unit.bootstrap.ordering;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.DeploymentType;

@Target( { TYPE, METHOD })
@Retention(RUNTIME)
@Documented
@DeploymentType
@interface AnotherDeploymentType
{

}
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.Arrays;

import javax.inject.AnnotationLiteral;

import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.EnterpriseBean;
Expand Down Expand Up @@ -189,5 +191,43 @@ public void testClassHierarchies()
assert indexOfDefangedTarantula > indexOfTarantula;
assert indexOfTarantula > indexOfSpider;
}

@Test(groups="bootstrap")
public void testClassHierarchiesForMethods()
{
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Shop.class, JewelryShop.class, Tuna.class));
beanDeployer.createBeans();
assert beanDeployer.getBeans().size() == 8;
int indexOfShop = 0;
int indexOfJewelryShop = 0;
int indexOfExpensiveGift = 0;
int indexOfNecklace = 0;
int i = 0;
for (RIBean<?> bean : beanDeployer.getBeans())
{
if (bean.getType().equals(Shop.class) && !bean.getBindings().contains(new NewLiteral()))
{
indexOfShop = i;
}
if (bean.getType().equals(JewelryShop.class) && !bean.getBindings().contains(new NewLiteral()))
{
indexOfJewelryShop = i;
}
if (bean.getType().equals(Product.class) && bean.getBindings().contains(new AnnotationLiteral<Sparkly>() {}))
{
indexOfNecklace = i;
}
if (bean.getType().equals(Product.class) && !bean.getBindings().contains(new AnnotationLiteral<Sparkly>() {}))
{
indexOfExpensiveGift = i;
}
i++;
}
assert indexOfJewelryShop > indexOfShop;
assert indexOfExpensiveGift > indexOfShop;
assert indexOfNecklace > indexOfJewelryShop;
assert indexOfNecklace > indexOfExpensiveGift;
}

}
@@ -0,0 +1,22 @@
package org.jboss.webbeans.test.unit.bootstrap.ordering;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.BindingType;

@Target( { TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
@BindingType
@interface Expensive
{

}
@@ -0,0 +1,15 @@
package org.jboss.webbeans.test.unit.bootstrap.ordering;

import javax.inject.Produces;
import javax.inject.Specializes;

class JewelryShop extends Shop
{

@Override @Produces @Specializes @Sparkly @AnotherDeploymentType
public Product getExpensiveGift()
{
return new Necklace();
}

}
@@ -0,0 +1,6 @@
package org.jboss.webbeans.test.unit.bootstrap.ordering;

class Necklace extends Product
{

}
@@ -0,0 +1,6 @@
package org.jboss.webbeans.test.unit.bootstrap.ordering;

class Product
{

}
@@ -0,0 +1,16 @@
package org.jboss.webbeans.test.unit.bootstrap.ordering;

import javax.annotation.Named;
import javax.inject.Produces;


class Shop
{

@Produces @Expensive @Named
public Product getExpensiveGift()
{
return new Product();
}

}
@@ -0,0 +1,22 @@
package org.jboss.webbeans.test.unit.bootstrap.ordering;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.inject.BindingType;

@Target( { TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
@BindingType
@interface Sparkly
{

}

0 comments on commit 12d37b8

Please sign in to comment.