Skip to content

Commit

Permalink
WELD-476 First phase; we get past reflection and start deploying many…
Browse files Browse the repository at this point in the history
… beans, but still too much memory is used
  • Loading branch information
drallen committed May 10, 2010
1 parent f5c2192 commit 38d7e08
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 98 deletions.
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
Expand Up @@ -217,7 +217,7 @@ else if (decoratedType instanceof ParameterizedType)
}
}
}
annotatedDelegateItem = WeldClassImpl.of(delegateInjectionPoint.getJavaClass(), beanManager.getServices().get(ClassTransformer.class));
annotatedDelegateItem = beanManager.getServices().get(ClassTransformer.class).loadClass(delegateInjectionPoint.getJavaClass());
}

private void checkAbstractMethods()
Expand Down
Expand Up @@ -18,6 +18,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Set;

public abstract class ForwardingWeldClass<T> extends ForwardingWeldAnnotated<T, Class<T>> implements WeldClass<T>
Expand All @@ -26,17 +27,17 @@ public abstract class ForwardingWeldClass<T> extends ForwardingWeldAnnotated<T,
@Override
protected abstract WeldClass<T> delegate();

public Set<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType)
public Collection<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType)
{
return delegate().getWeldConstructors(annotationType);
}

public Set<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType)
public Collection<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType)
{
return delegate().getWeldFields(annotationType);
}

public Set<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType)
public Collection<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType)
{
return delegate().getWeldMethods(annotationType);
}
Expand All @@ -46,27 +47,27 @@ public WeldConstructor<T> getNoArgsWeldConstructor()
return delegate().getNoArgsWeldConstructor();
}

public Set<WeldMethod<?, ?>> getWeldMethods()
public Collection<WeldMethod<?, ?>> getWeldMethods()
{
return delegate().getWeldMethods();
}

public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
public Collection<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType)
{
return delegate().getDeclaredWeldFields(annotationType);
}

public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType)
{
return delegate().getDeclaredWeldMethods(annotationType);
}

public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
{
return delegate().getDeclaredWeldMethodsWithAnnotatedParameters(annotationType);
}

public Set<WeldField<?, ?>> getWeldFields()
public Collection<WeldField<?, ?>> getWeldFields()
{
return delegate().getWeldFields();
}
Expand Down Expand Up @@ -164,7 +165,7 @@ public String getSimpleName()
return delegate().getSimpleName();
}

public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
public Collection<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
return delegate().getDeclaredMetaAnnotations(metaAnnotationType);
}
Expand Down
21 changes: 11 additions & 10 deletions impl/src/main/java/org/jboss/weld/introspector/WeldClass.java
Expand Up @@ -18,6 +18,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Set;

import javax.enterprise.inject.spi.AnnotatedType;
Expand All @@ -36,21 +37,21 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
*
* @return A set of abstracted fields
*/
public Set<WeldField<?, ?>> getWeldFields();
public Collection<WeldField<?, ?>> getWeldFields();

/**
* Gets all fields on the type
*
* @return A set of abstracted fields
*/
public Set<WeldMethod<?, ?>> getWeldMethods();
public Collection<WeldMethod<?, ?>> getWeldMethods();

/**
* Gets all fields on the type
*
* @return A set of abstracted fields
*/
public Set<WeldMethod<?, ?>> getDeclaredWeldMethods();
public Collection<WeldMethod<?, ?>> getDeclaredWeldMethods();

/**
* Get a field by name
Expand All @@ -69,7 +70,7 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
* @return A set of abstracted fields with the given annotation. Returns an
* empty set if there are no matches
*/
public Set<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType);
public Collection<WeldField<?, ?>> getWeldFields(Class<? extends Annotation> annotationType);

/**
* Gets all fields which are annotated with the given annotation type on this
Expand All @@ -79,7 +80,7 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
* @return A set of abstracted fields with the given annotation. Returns an
* empty set if there are no matches
*/
public Set<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType);
public Collection<WeldField<?, ? super T>> getDeclaredWeldFields(Class<? extends Annotation> annotationType);

/**
* Gets all constructors which are annotated with annotationType
Expand All @@ -88,7 +89,7 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
* @return A set of abstracted fields with the given annotation. Returns an
* empty set if there are no matches
*/
public Set<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType);
public Collection<WeldConstructor<T>> getWeldConstructors(Class<? extends Annotation> annotationType);

/**
* Gets the no-args constructor
Expand All @@ -112,7 +113,7 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
* @return A set of abstracted methods with the given annotation. Returns an
* empty set if there are no matches
*/
public Set<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType);
public Collection<WeldMethod<?, ?>> getWeldMethods(Class<? extends Annotation> annotationType);

/**
* Gets all methods annotated with annotationType
Expand All @@ -121,7 +122,7 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
* @return A set of abstracted methods with the given annotation. Returns an
* empty set if there are no matches
*/
public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType);
public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethods(Class<? extends Annotation> annotationType);

/**
* Find the annotated method for a given methodDescriptor
Expand Down Expand Up @@ -163,7 +164,7 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
* @return A set of abstracted methods with the given annotation. Returns an
* empty set if there are no matches
*/
public Set<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType);
public Collection<WeldMethod<?, ? super T>> getDeclaredWeldMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType);

/**
* Gets the superclass.
Expand Down Expand Up @@ -210,6 +211,6 @@ public interface WeldClass<T> extends WeldAnnotated<T, Class<T>>, AnnotatedType<
* @return A set of matching meta-annotations. Returns an empty set if there
* are no matches.
*/
public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType);
public Collection<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType);

}
Expand Up @@ -42,9 +42,11 @@
import org.jboss.weld.util.collections.HashSetSupplier;
import org.jboss.weld.util.reflection.HierarchyDiscovery;

import com.google.common.collect.BiMap;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.MutableClassToInstanceMap;
import com.google.common.collect.SetMultimap;

/**
Expand Down Expand Up @@ -100,23 +102,23 @@ protected static Map<Class<? extends Annotation>, Annotation> buildAnnotationMap
}


protected static void addMetaAnnotations(SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Annotation[] metaAnnotations, boolean declared)
protected static void addMetaAnnotations(Multimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Annotation[] metaAnnotations, boolean declared)
{
for (Annotation metaAnnotation : metaAnnotations)
{
addMetaAnnotation(metaAnnotationMap, annotation, metaAnnotation.annotationType(), declared);
}
}

protected static void addMetaAnnotations(SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Iterable<Annotation> metaAnnotations, boolean declared)
protected static void addMetaAnnotations(Multimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Iterable<Annotation> metaAnnotations, boolean declared)
{
for (Annotation metaAnnotation : metaAnnotations)
{
addMetaAnnotation(metaAnnotationMap, annotation, metaAnnotation.annotationType(), declared);
}
}

private static void addMetaAnnotation(SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Class<? extends Annotation> metaAnnotationType, boolean declared)
private static void addMetaAnnotation(Multimap<Class<? extends Annotation>, Annotation> metaAnnotationMap, Annotation annotation, Class<? extends Annotation> metaAnnotationType, boolean declared)
{
// Only map meta-annotations we are interested in
if (declared ? MAPPED_DECLARED_METAANNOTATIONS.contains(metaAnnotationType) : MAPPED_METAANNOTATIONS.contains(metaAnnotationType))
Expand All @@ -126,7 +128,7 @@ private static void addMetaAnnotation(SetMultimap<Class<? extends Annotation>, A
}

// The annotation map (annotation type -> annotation) of the item
private final BiMap<Class<? extends Annotation>, Annotation> annotationMap;
private final Map<Class<? extends Annotation>, Annotation> annotationMap;
// The meta-annotation map (annotation type -> set of annotations containing
// meta-annotation) of the item
private final SetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap;
Expand All @@ -152,13 +154,12 @@ public AbstractWeldAnnotated(Map<Class<? extends Annotation>, Annotation> annota
{
throw new WeldException(ANNOTATION_MAP_NULL);
}
this.annotationMap = HashBiMap.create(annotationMap.size());
this.annotationMap = annotationMap;
this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation>instance());
for (Annotation annotation : annotationMap.values())
{
addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
addMetaAnnotations(metaAnnotationMap, annotation, classTransformer.getTypeStore().get(annotation.annotationType()), false);
this.annotationMap.put(annotation.annotationType(), annotation);
}

if (declaredAnnotationMap == null)
Expand All @@ -185,13 +186,12 @@ protected AbstractWeldAnnotated(Map<Class<? extends Annotation>, Annotation> ann
{
throw new WeldException(ANNOTATION_MAP_NULL);
}
this.annotationMap = HashBiMap.create(annotationMap.size());
this.annotationMap = annotationMap;
this.metaAnnotationMap = Multimaps.newSetMultimap(new HashMap<Class<? extends Annotation>, Collection<Annotation>>(), HashSetSupplier.<Annotation>instance());
for (Annotation annotation : annotationMap.values())
{
addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
addMetaAnnotations(metaAnnotationMap, annotation, typeStore.get(annotation.annotationType()), false);
this.annotationMap.put(annotation.annotationType(), annotation);
}

if (declaredAnnotationMap == null)
Expand Down Expand Up @@ -261,7 +261,7 @@ public Set<Type> getTypeClosure()

public Set<Annotation> getAnnotations()
{
return Collections.unmodifiableSet(annotationMap.values());
return Collections.unmodifiableSet(new HashSet<Annotation>(annotationMap.values()));
}

public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
Expand Down

0 comments on commit 38d7e08

Please sign in to comment.