Skip to content

Commit

Permalink
WELD-819
Browse files Browse the repository at this point in the history
* remove conversions to/from set
  • Loading branch information
pmuir committed Jan 12, 2011
1 parent 24ce66f commit db6f6d1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
Expand Up @@ -17,13 +17,12 @@
package org.jboss.weld.bean.builtin;

import static org.jboss.weld.logging.messages.BeanMessage.TYPE_PARAMETER_MUST_BE_CONCRETE;
import static org.jboss.weld.util.reflection.Reflections.EMPTY_ANNOTATIONS;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Set;

import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.InjectionPoint;
Expand Down Expand Up @@ -72,9 +71,9 @@ protected BeanManagerImpl getBeanManager()
return beanManager.getCurrent();
}

protected Annotation[] getQualifiers()
protected Set<Annotation> getQualifiers()
{
return injectionPoint.getQualifiers().toArray(EMPTY_ANNOTATIONS);
return injectionPoint.getQualifiers();
}

protected Type getType()
Expand All @@ -98,7 +97,7 @@ public boolean equals(Object obj)
if (obj instanceof AbstractFacade<?, ?>)
{
AbstractFacade<?, ?> that = (AbstractFacade<?, ?>) obj;
return this.getType().equals(that.getType()) && Arrays.equals(this.getQualifiers(), that.getQualifiers());
return this.getType().equals(that.getType()) && this.getQualifiers().equals(that.getQualifiers());
}
else
{
Expand All @@ -111,7 +110,7 @@ public int hashCode()
{
int hashCode = 17;
hashCode += getType().hashCode() * 5;
hashCode += Arrays.hashCode(getQualifiers()) * 7;
hashCode += getQualifiers().hashCode() * 7;
return hashCode;
}

Expand Down
@@ -1,6 +1,6 @@
package org.jboss.weld.bean.builtin;

import static org.jboss.weld.util.Beans.mergeInQualifiersAsSet;
import static org.jboss.weld.util.Beans.mergeInQualifiers;

import java.io.Serializable;
import java.lang.annotation.Annotation;
Expand All @@ -22,11 +22,11 @@ public class FacadeInjectionPoint extends ForwardingInjectionPoint implements Se
private final Type type;
private final Set<Annotation> qualifiers;

public FacadeInjectionPoint(InjectionPoint injectionPoint, Type subtype, Annotation[] existingQualifiers, Annotation[] newQualifiers)
public FacadeInjectionPoint(InjectionPoint injectionPoint, Type subtype, Set<Annotation> existingQualifiers, Annotation[] newQualifiers)
{
this.injectionPoint = injectionPoint;
this.type = new ParameterizedTypeImpl(Instance.class, new Type[] {subtype}, null);
this.qualifiers = mergeInQualifiersAsSet(existingQualifiers, newQualifiers);
this.qualifiers = mergeInQualifiers(existingQualifiers, newQualifiers);
}

@Override
Expand Down
Expand Up @@ -64,11 +64,11 @@ private static class InstanceInjectionPoint extends ForwardingInjectionPoint imp
private final Type type;
private final Set<Annotation> qualifiers;

public InstanceInjectionPoint(InjectionPoint injectionPoint, Type type, Annotation[] qualifiers)
public InstanceInjectionPoint(InjectionPoint injectionPoint, Type type, Set<Annotation> qualifiers)
{
this.injectionPoint = injectionPoint;
this.type = type;
this.qualifiers = asSet(qualifiers);
this.qualifiers = qualifiers;
}

@Override
Expand Down
17 changes: 17 additions & 0 deletions impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java
Expand Up @@ -468,6 +468,12 @@ public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(Type eventType,
return cast(observerResolver.resolve(new ResolvableBuilder().addTypes(new HierarchyDiscovery(eventType).getTypeClosure()).addType(Object.class).addQualifiers(qualifiers).addQualifierIfAbsent(AnyLiteral.INSTANCE).create(), true));
}

public <T> Set<ObserverMethod<? super T>> resolveObserverMethods(Type eventType, Set<Annotation> qualifiers)
{
// We can always cache as this is only ever called by Weld where we avoid non-static inner classes for annotation literals
return cast(observerResolver.resolve(new ResolvableBuilder().addTypes(new HierarchyDiscovery(eventType).getTypeClosure()).addType(Object.class).addQualifiers(qualifiers).addQualifierIfAbsent(AnyLiteral.INSTANCE).create(), true));
}

/**
* Enabled Alternatives, Interceptors and Decorators
*
Expand All @@ -487,6 +493,11 @@ public Set<Bean<?>> getBeans(Type beanType, Annotation... qualifiers)
{
return beanResolver.resolve(new ResolvableBuilder(beanType).addQualifiers(qualifiers).create(), isCacheable(qualifiers));
}

public Set<Bean<?>> getBeans(Type beanType, Set<Annotation> qualifiers)
{
return beanResolver.resolve(new ResolvableBuilder(beanType).addQualifiers(qualifiers).create(), isCacheable(qualifiers));
}

public Set<Bean<?>> getBeans(InjectionPoint injectionPoint)
{
Expand Down Expand Up @@ -607,6 +618,12 @@ public void fireEvent(Type eventType, Object event, Annotation... qualifiers)
Observers.checkEventObjectType(event);
notifyObservers(event, resolveObserverMethods(eventType, qualifiers));
}

public void fireEvent(Type eventType, Object event, Set<Annotation> qualifiers)
{
Observers.checkEventObjectType(event);
notifyObservers(event, resolveObserverMethods(eventType, qualifiers));
}

private <T> void notifyObservers(final T event, final Set<ObserverMethod<? super T>> observers)
{
Expand Down
7 changes: 4 additions & 3 deletions impl/src/main/java/org/jboss/weld/util/Beans.java
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.weld.util;

import static java.util.Arrays.asList;
import static org.jboss.weld.logging.Category.BEAN;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.BeanMessage.FOUND_DEFAULT_CONSTRUCTOR;
Expand Down Expand Up @@ -910,13 +911,13 @@ public static <T> boolean isDecorator(WeldClass<T> annotatedItem)

public static Annotation[] mergeInQualifiers(Annotation[] qualifiers, Annotation[] newQualifiers)
{
return mergeInQualifiersAsSet(qualifiers, newQualifiers).toArray(Reflections.EMPTY_ANNOTATIONS);
return mergeInQualifiers(asList(qualifiers), newQualifiers).toArray(Reflections.EMPTY_ANNOTATIONS);
}

public static Set<Annotation> mergeInQualifiersAsSet(Annotation[] qualifiers, Annotation[] newQualifiers)
public static Set<Annotation> mergeInQualifiers(Collection<Annotation> qualifiers, Annotation[] newQualifiers)
{
Set<Annotation> result = new HashSet<Annotation>();
result.addAll(Arrays.asList(qualifiers));
result.addAll(qualifiers);
Set<Annotation> checkedNewQualifiers = new HashSet<Annotation>();
for (Annotation qualifier : newQualifiers)
{
Expand Down

0 comments on commit db6f6d1

Please sign in to comment.