Skip to content

Commit

Permalink
WELD-409
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Feb 2, 2010
1 parent 5ee064d commit 20f0ff1
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 99 deletions.
Expand Up @@ -53,12 +53,13 @@
import org.jboss.weld.resolution.ResolvableFactory;
import org.jboss.weld.resolution.TypeSafeDisposerResolver;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.AnnotatedTypes;

public class BeanDeployerEnvironment
{

private final Map<WeldClass<?>, AbstractClassBean<?>> classBeanMap;
private final Map<WeldMethod<?, ?>, ProducerMethod<?, ?>> producerMethodBeanMap;
private final Map<WeldMethodKey<?, ?>, ProducerMethod<?, ?>> producerMethodBeanMap;
private final Set<RIBean<?>> beans;
private final Set<ObserverMethodImpl<?, ?>> observers;
private final List<DisposalMethod<?, ?>> allDisposalBeans;
Expand All @@ -74,7 +75,7 @@ public class BeanDeployerEnvironment
public BeanDeployerEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl manager)
{
this.classBeanMap = new HashMap<WeldClass<?>, AbstractClassBean<?>>();
this.producerMethodBeanMap = new HashMap<WeldMethod<?, ?>, ProducerMethod<?, ?>>();
this.producerMethodBeanMap = new HashMap<WeldMethodKey<?, ?>, ProducerMethod<?, ?>>();
this.allDisposalBeans = new ArrayList<DisposalMethod<?, ?>>();
this.resolvedDisposalBeans = new HashSet<DisposalMethod<?, ?>>();
this.beans = new HashSet<RIBean<?>>();
Expand All @@ -100,13 +101,14 @@ public Set<InternalEjbDescriptor<?>> getNewSessionBeanDescriptors()

public <X, T> ProducerMethod<X, T> getProducerMethod(WeldMethod<X, T> method)
{
if (!producerMethodBeanMap.containsKey(method))
WeldMethodKey<X, T> key = new WeldMethodKey<X, T>(method);
if (!producerMethodBeanMap.containsKey(key))
{
return null;
}
else
{
ProducerMethod<?, ?> bean = producerMethodBeanMap.get(method);
ProducerMethod<?, ?> bean = producerMethodBeanMap.get(key);
bean.initialize(this);
return (ProducerMethod<X, T>) bean;
}
Expand All @@ -128,7 +130,7 @@ public AbstractClassBean<?> getClassBean(WeldClass<?> clazz)

public void addProducerMethod(ProducerMethod<?, ?> bean)
{
producerMethodBeanMap.put(bean.getWeldAnnotated(), bean);
producerMethodBeanMap.put(new WeldMethodKey(bean.getWeldAnnotated()), bean);
addAbstractBean(bean);
}

Expand Down Expand Up @@ -290,4 +292,31 @@ public EjbDescriptors getEjbDescriptors()
return Collections.unmodifiableSet(beans);
}

private static class WeldMethodKey<T, X>
{
final WeldMethod meth;

WeldMethodKey(WeldMethod<T, X> meth)
{
this.meth = meth;
}

@Override
public boolean equals(Object other)
{
if (other instanceof WeldMethodKey<?, ?>)
{
WeldMethodKey<?, ?> o = (WeldMethodKey<?, ?>) other;
return AnnotatedTypes.compareAnnotatedCallable(meth, o.meth);
}
return false;
}

@Override
public int hashCode()
{
return meth.getJavaMember().hashCode();
}
}

}
Expand Up @@ -46,6 +46,7 @@
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.AnnotatedTypes;

public class ConstructorInjectionPoint<T> extends ForwardingWeldConstructor<T> implements WeldInjectionPoint<T, Constructor<T>>, Serializable
{
Expand Down Expand Up @@ -85,6 +86,20 @@ protected ConstructorInjectionPoint(Bean<T> declaringBean, WeldConstructor<T> co
this.constructor = constructor;
}

@Override
public boolean equals(Object obj)
{
if (obj instanceof ConstructorInjectionPoint<?>)
{
ConstructorInjectionPoint<?> ip = (ConstructorInjectionPoint<?>) obj;
if (AnnotatedTypes.compareAnnotatedCallable(constructor, ip.constructor))
{
return true;
}
}
return false;
}

@Override
protected WeldConstructor<T> delegate()
{
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.AnnotatedTypes;

public class FieldInjectionPoint<T, X> extends ForwardingWeldField<T, X> implements WeldInjectionPoint<T, Field>, Serializable
{
Expand All @@ -63,6 +64,20 @@ protected FieldInjectionPoint(Bean<?> declaringBean, WeldField<T, X> field)
this.delegate = isAnnotationPresent(Inject.class) && isAnnotationPresent(Delegate.class) && declaringBean instanceof Decorator<?>;
}

@Override
public boolean equals(Object obj)
{
if (obj instanceof FieldInjectionPoint<?, ?>)
{
FieldInjectionPoint<?, ?> ip = (FieldInjectionPoint<?, ?>) obj;
if (AnnotatedTypes.compareAnnotatedField(field, ip.field))
{
return true;
}
}
return false;
}

@Override
protected WeldField<T, X> delegate()
{
Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.jboss.weld.introspector.WeldParameter;
import org.jboss.weld.logging.messages.ReflectionMessage;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.AnnotatedTypes;

public class MethodInjectionPoint<T, X> extends ForwardingWeldMethod<T, X> implements WeldInjectionPoint<T, Method>
{
Expand Down Expand Up @@ -82,6 +83,20 @@ protected MethodInjectionPoint(Bean<?> declaringBean, WeldMethod<T, X> method)
this.method = method;
}

@Override
public boolean equals(Object obj)
{
if (obj instanceof MethodInjectionPoint<?, ?>)
{
MethodInjectionPoint<?, ?> ip = (MethodInjectionPoint<?, ?>) obj;
if (AnnotatedTypes.compareAnnotatedCallable(method, ip.method))
{
return true;
}
}
return false;
}

@Override
protected WeldMethod<T, X> delegate()
{
Expand Down
Expand Up @@ -66,6 +66,20 @@ private ParameterInjectionPoint(Bean<?> declaringBean, WeldParameter<T, X> param
this.delegate = isAnnotationPresent(Delegate.class) && declaringBean instanceof Decorator<?>;
}

@Override
public boolean equals(Object obj)
{
if (obj instanceof ParameterInjectionPoint<?, ?>)
{
ParameterInjectionPoint<?, ?> ip = (ParameterInjectionPoint<?, ?>) obj;
if (parameter.getDeclaringWeldCallable().getJavaMember().equals(ip.parameter.getDeclaringWeldCallable().getJavaMember()) && parameter.getAnnotations().equals(ip.parameter.getAnnotations()) && parameter.getPosition() == ip.parameter.getPosition())
{
return true;
}
}
return false;
}

@Override
protected WeldParameter<T, X> delegate()
{
Expand Down
Expand Up @@ -23,7 +23,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -206,34 +205,6 @@ protected AbstractWeldAnnotated(Map<Class<? extends Annotation>, Annotation> ann
this.proxyable = false;
}

/**
* Compares two AbstractAnnotatedItems
*
* @param other The other item
* @return True if equals, false otherwise
*/
@Override
public boolean equals(Object other)
{
if (other instanceof WeldAnnotated<?, ?>)
{
WeldAnnotated<?, ?> that = (WeldAnnotated<?, ?>) other;
return this.getAnnotations().equals(that.getAnnotations()) && this.getJavaClass().equals(that.getJavaClass()) && this.getActualTypeArguments().length == that.getActualTypeArguments().length && Arrays.equals(this.getActualTypeArguments(), that.getActualTypeArguments());
}
return false;
}

/**
* Gets the hash code of the actual type
*
* @return The hash code
*/
@Override
public int hashCode()
{
return getJavaClass().hashCode();
}

/**
* Indicates if the type is proxyable to a set of pre-defined rules
*
Expand Down
Expand Up @@ -47,7 +47,6 @@
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.Names;
import org.jboss.weld.util.collections.HashSetSupplier;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
Expand Down Expand Up @@ -366,17 +365,6 @@ private <X> WeldClass<X> getDeclaringWeldClass(Member member, ClassTransformer t
}
}

@Override
public boolean equals(Object other)
{
if (other instanceof WeldClassImpl<?>)
{
WeldClassImpl<?> that = (WeldClassImpl<?>) other;
return AnnotatedTypes.compareAnnotatedTypes(this, that) && this.getActualTypeArguments().length == that.getActualTypeArguments().length && Arrays.equals(this.getActualTypeArguments(), that.getActualTypeArguments());
}
return false;
}

/**
* Gets the implementing class
*
Expand Down
Expand Up @@ -275,19 +275,6 @@ public boolean equals(Object other)
return false;
}

/**
* The overridden hashcode
*
* Gets the hash code from the delegate
*
* @return The hash code
*/
@Override
public int hashCode()
{
return getDelegate().hashCode();
}

/**
* Gets a string representation of the constructor
*
Expand Down
Expand Up @@ -135,24 +135,4 @@ public String toString()
return new StringBuilder().append("field ").append(getDeclaringType().getName()).append(".").append(field.getName()).toString();
}

@Override
public boolean equals(Object other)
{
if (super.equals(other) && other instanceof WeldField<?, ?>)
{
WeldField<?, ?> that = (WeldField<?, ?>) other;
return this.getJavaMember().equals(that.getJavaMember());
}
else
{
return false;
}
}

@Override
public int hashCode()
{
return getDelegate().hashCode();
}

}
Expand Up @@ -187,30 +187,11 @@ public List<WeldParameter<?, X>> getWeldParameters(Class<? extends Annotation> a
return Collections.unmodifiableList(annotatedParameters.get(annotationType));
}

@Override
public boolean equals(Object other)
{
if (super.equals(other) && other instanceof WeldMethod)
{
WeldMethod<?, ?> that = (WeldMethod<?, ?>) other;
return this.getJavaMember().equals(that.getJavaMember()) && this.getWeldParameters().equals(that.getWeldParameters());
}
else
{
return false;
}
}

public boolean isEquivalent(Method method)
{
return this.getDeclaringType().isEquivalent(method.getDeclaringClass()) && this.getName().equals(method.getName()) && Arrays.equals(this.getParameterTypesAsArray(), method.getParameterTypes());
}

@Override
public int hashCode()
{
return getDelegate().hashCode();
}

public T invokeOnInstance(Object instance, Object... parameters) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
{
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.jboss.weld.introspector.WeldAnnotated;
import org.jboss.weld.literal.NewLiteral;
import org.jboss.weld.test.AbstractWeldTest;
import org.jboss.weld.util.AnnotatedTypes;
import org.testng.annotations.Test;

@Artifact
Expand Down Expand Up @@ -65,7 +66,7 @@ public void testNewBeanIsSimpleWebBeanIfParameterTypeIsSimpleWebBean()
public void testNewBeanHasSameConstructorAsWrappedBean()
{
initNewBean();
assert wrappedSimpleBean.getConstructor().equals(newSimpleBean.getConstructor());
assert AnnotatedTypes.compareAnnotatedCallable(wrappedSimpleBean.getConstructor(), newSimpleBean.getConstructor());
}

@Test(groups = { "new" })
Expand Down

0 comments on commit 20f0ff1

Please sign in to comment.