Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Apr 13, 2012
1 parent 1516403 commit 0fa3336
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ public class EnhancedAnnotatedTypeImpl<T> extends AbstractEnhancedAnnotated<T, C
private final AnnotatedType<T> slim;

public static <T> EnhancedAnnotatedType<T> of(SlimAnnotatedType<T> annotatedType, ClassTransformer classTransformer) {
return new EnhancedAnnotatedTypeImpl<T>(annotatedType, buildAnnotationMap(annotatedType.getAnnotations()), buildAnnotationMap(annotatedType.getAnnotations()), classTransformer);
if (annotatedType instanceof BackedAnnotatedType<?>) {
return new EnhancedAnnotatedTypeImpl<T>(annotatedType, buildAnnotationMap(annotatedType.getAnnotations()), buildAnnotationMap(annotatedType.getJavaClass().getDeclaredAnnotations()), classTransformer);
} else {
return new EnhancedAnnotatedTypeImpl<T>(annotatedType, buildAnnotationMap(annotatedType.getAnnotations()), buildAnnotationMap(annotatedType.getAnnotations()), classTransformer);
}
}

protected EnhancedAnnotatedTypeImpl(SlimAnnotatedType<T> annotatedType, Map<Class<? extends Annotation>, Annotation> annotationMap, Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap, ClassTransformer classTransformer) {
Expand Down Expand Up @@ -218,14 +222,20 @@ protected EnhancedAnnotatedTypeImpl(SlimAnnotatedType<T> annotatedType, Map<Clas
this.annotatedMethods = ArrayListMultimap.<Class<? extends Annotation>, EnhancedAnnotatedMethod<?, ?>> create();
methodsTemp = new HashSet<EnhancedAnnotatedMethod<?, ? super T>>();
for (AnnotatedMethod<? super T> method : annotatedType.getMethods()) {
EnhancedAnnotatedMethod<?, ? super T> enhancedMethod = EnhancedAnnotatedMethodImpl.of(method, this, classTransformer);
methodsTemp.add(enhancedMethod);
if (method.getJavaMember().getDeclaringClass().equals(javaClass)) {
EnhancedAnnotatedMethod<?, ? super T> enhancedMethod = EnhancedAnnotatedMethodImpl.of(method, this, classTransformer);
declaredMethodsTemp.add(enhancedMethod);
for (Annotation annotation : enhancedMethod.getAnnotations()) {
}
for (Annotation annotation : enhancedMethod.getAnnotations()) {
annotatedMethods.put(annotation.annotationType(), enhancedMethod);
if (method.getJavaMember().getDeclaringClass().equals(javaClass)) {
this.declaredAnnotatedMethods.put(annotation.annotationType(), enhancedMethod);
}
for (Class<? extends Annotation> annotationType : EnhancedAnnotatedMethod.MAPPED_PARAMETER_ANNOTATIONS) {
if (enhancedMethod.getEnhancedParameters(annotationType).size() > 0) {
}
for (Class<? extends Annotation> annotationType : EnhancedAnnotatedMethod.MAPPED_PARAMETER_ANNOTATIONS) {
if (enhancedMethod.getEnhancedParameters(annotationType).size() > 0) {
if (method.getJavaMember().getDeclaringClass().equals(javaClass)) {
this.declaredMethodsByAnnotatedParameters.put(annotationType, enhancedMethod);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public BackedAnnotatedMethod(Method method, BackedAnnotatedType<X> declaringType
Type parameterType = genericParameterTypes[i];
Set<Annotation> annotations = null;
if (parameterAnnotations[i].length > 0) {
annotations = ImmutableSet.copyOf(parameterAnnotations[0]);
annotations = ImmutableSet.copyOf(parameterAnnotations[i]);
} else {
annotations = Collections.emptySet();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.jboss.weld.annotated.slim.backed;

import static org.jboss.weld.util.reflection.Reflections.cast;

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collections;
Expand All @@ -13,6 +16,7 @@
import javax.enterprise.inject.spi.AnnotatedMethod;

import org.jboss.weld.annotated.slim.SlimAnnotatedType;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.collections.ArraySet;
import org.jboss.weld.util.reflection.Formats;
import org.jboss.weld.util.reflection.Reflections;
Expand All @@ -22,20 +26,20 @@

public class BackedAnnotatedType<X> extends BackedAnnotated implements SlimAnnotatedType<X> {

public static <X> BackedAnnotatedType<X> of(Class<X> javaClass) {
return new BackedAnnotatedType<X>(javaClass, javaClass);
public static <X> BackedAnnotatedType<X> of(Class<X> javaClass, ClassTransformer classTransformer) {
return of(javaClass, javaClass, classTransformer);
}

public static <X> BackedAnnotatedType<X> of(Class<X> javaClass, Type baseType) {
return new BackedAnnotatedType<X>(javaClass, baseType);
public static <X> BackedAnnotatedType<X> of(Class<X> javaClass, Type baseType, ClassTransformer classTransformer) {
return new BackedAnnotatedType<X>(javaClass, baseType, classTransformer);
}

private final Class<X> javaClass;
private final Set<AnnotatedConstructor<X>> constructors;
private final Set<AnnotatedMethod<? super X>> methods;
private final Set<AnnotatedField<? super X>> fields;

public BackedAnnotatedType(Class<X> rawType, Type baseType) {
public BackedAnnotatedType(Class<X> rawType, Type baseType, ClassTransformer classTransformer) {
super(baseType);
this.javaClass = rawType;
// TODO this all should be initialized lazily so that we can serialize the AnnotatedType
Expand All @@ -52,10 +56,10 @@ public BackedAnnotatedType(Class<X> rawType, Type baseType) {
Class<? super X> clazz = javaClass;
while (clazz != Object.class && clazz != null) {
for (Method method : SecureReflections.getDeclaredMethods(clazz)) {
methods.add(BackedAnnotatedMethod.of(method, this));
methods.add(BackedAnnotatedMethod.of(method, getDeclaringAnnotatedType(method, classTransformer)));
}
for (Field field : SecureReflections.getDeclaredFields(clazz)) {
fields.add(BackedAnnotatedField.of(field, this));
fields.add(BackedAnnotatedField.of(field, getDeclaringAnnotatedType(field, classTransformer)));
}
clazz = clazz.getSuperclass();
}
Expand All @@ -64,6 +68,14 @@ public BackedAnnotatedType(Class<X> rawType, Type baseType) {
this.fields = Collections.unmodifiableSet(fields.trimToSize());
}

private <T> BackedAnnotatedType<T> getDeclaringAnnotatedType(Member member, ClassTransformer transformer) {
if (member.getDeclaringClass().equals(getJavaClass())) {
return cast(this);
} else {
return transformer.getAnnotatedType(Reflections.<Class<T>>cast(member.getDeclaringClass()));
}
}

public Class<X> getJavaClass() {
return javaClass;
}
Expand Down Expand Up @@ -92,6 +104,31 @@ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
return javaClass.isAnnotationPresent(annotationType);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getBaseType() == null) ? 0 : getBaseType().hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BackedAnnotatedType<?> other = (BackedAnnotatedType<?>) obj;
if (getBaseType() == null) {
if (other.getBaseType() != null)
return false;
} else if (!getBaseType().equals(other.getBaseType()))
return false;
return true;
}

@Override
public String toString() {
return Formats.formatAnnotatedType(this);
Expand Down
4 changes: 2 additions & 2 deletions impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected Map<Class<? extends Annotation>, Annotation> mergeMethodInterceptorBin
}

// The item representation
protected final AnnotatedType<T> slimAnnotatedType;
protected final AnnotatedType<T> annotatedType;
protected volatile EnhancedAnnotatedType<T> enhancedAnnotatedItem;

// The injectable fields of each type in the type hierarchy, with the actual
Expand Down Expand Up @@ -178,7 +178,7 @@ protected Map<Class<? extends Annotation>, Annotation> mergeMethodInterceptorBin
protected AbstractClassBean(BeanAttributes<T> attributes, EnhancedAnnotatedType<T> type, String idSuffix, BeanManagerImpl beanManager, ServiceRegistry services) {
super(attributes, idSuffix, beanManager, services);
this.enhancedAnnotatedItem = type;
this.slimAnnotatedType = type.slim();
this.annotatedType = type.slim();
}

/**
Expand Down
19 changes: 14 additions & 5 deletions impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.jboss.weld.Container;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.annotated.slim.SlimAnnotatedType;
import org.jboss.weld.annotated.slim.backed.BackedAnnotatedType;
import org.jboss.weld.annotated.slim.unbacked.UnbackedAnnotatedType;
import org.jboss.weld.bean.AbstractBean;
Expand Down Expand Up @@ -98,15 +99,23 @@ public BeanDeployer addClass(String className) {
}

if (clazz != null && !clazz.isAnnotation()) {
AnnotatedType<?> annotatedType = BackedAnnotatedType.of(clazz);
getEnvironment().addAnnotatedType(annotatedType);
AnnotatedType<?> annotatedType = null;
try {
annotatedType = classTransformer.getAnnotatedType(clazz);
} catch (ResourceLoadingException e) {
log.info(IGNORING_CLASS_DUE_TO_LOADING_ERROR, className);
xlog.catching(INFO, e);
}
if (annotatedType != null) {
getEnvironment().addAnnotatedType(annotatedType);
}
}
return this;
}

public <T> BeanDeployer addSyntheticClass(AnnotatedType<T> annotatedType, Extension extension) {
AnnotatedType<T> unbacked = UnbackedAnnotatedType.of(annotatedType);
getEnvironment().addSyntheticAnnotatedType(unbacked, extension);
SlimAnnotatedType<T> slim = ClassTransformer.instance(getManager()).getAnnotatedType(annotatedType);
getEnvironment().addSyntheticAnnotatedType(slim, extension);
return this;
}

Expand Down Expand Up @@ -144,7 +153,7 @@ public void processAnnotatedTypes() {
if (modifiedType instanceof BackedAnnotatedType || modifiedType instanceof UnbackedAnnotatedType) {
annotatedType = modifiedType;
} else {
annotatedType = UnbackedAnnotatedType.of(modifiedType);
annotatedType = classTransformer.getAnnotatedType(modifiedType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType;
import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod;
import org.jboss.weld.annotated.slim.SlimAnnotatedType;
import org.jboss.weld.annotated.slim.backed.BackedAnnotatedType;
import org.jboss.weld.bean.AbstractBean;
import org.jboss.weld.bean.AbstractClassBean;
Expand Down Expand Up @@ -79,7 +80,7 @@ public static BeanDeployerEnvironment newConcurrentEnvironment(EjbDescriptors ej
Sets.newSetFromMap(new ConcurrentHashMap<AnnotatedType<?>, Boolean>()),
new ConcurrentHashMap<AnnotatedType<?>, Extension>(),
Sets.newSetFromMap(new ConcurrentHashMap<Class<?>, Boolean>()),
new ConcurrentHashMap<EnhancedAnnotatedType<?>, AbstractClassBean<?>>(),
new ConcurrentHashMap<AnnotatedType<?>, AbstractClassBean<?>>(),
Sets.newSetFromMap(new ConcurrentHashMap<ProducerField<?, ?>, Boolean>()),
new ConcurrentHashMap<WeldMethodKey<?, ?>, ProducerMethod<?, ?>>(),
Sets.newSetFromMap(new ConcurrentHashMap<RIBean<?>, Boolean>()),
Expand All @@ -97,7 +98,7 @@ public static BeanDeployerEnvironment newConcurrentEnvironment(EjbDescriptors ej
private final Set<AnnotatedType<?>> annotatedTypes;
private final Map<AnnotatedType<?>, Extension> annotatedTypeSource;
private final Set<Class<?>> vetoedClasses;
private final Map<EnhancedAnnotatedType<?>, AbstractClassBean<?>> classBeanMap;
private final Map<AnnotatedType<?>, AbstractClassBean<?>> classBeanMap;
private final Map<WeldMethodKey<?, ?>, ProducerMethod<?, ?>> producerMethodBeanMap;
private final Set<ProducerField<?, ?>> producerFields;
private final Set<RIBean<?>> beans;
Expand All @@ -116,7 +117,7 @@ protected BeanDeployerEnvironment(
Set<AnnotatedType<?>> annotatedTypes,
Map<AnnotatedType<?>, Extension> annotatedTypeSource,
Set<Class<?>> vetoedClasses,
Map<EnhancedAnnotatedType<?>, AbstractClassBean<?>> classBeanMap,
Map<AnnotatedType<?>, AbstractClassBean<?>> classBeanMap,
Set<ProducerField<?, ?>> producerFields,
Map<WeldMethodKey<?, ?>, ProducerMethod<?, ?>> producerMethodBeanMap,
Set<RIBean<?>> beans,
Expand Down Expand Up @@ -153,7 +154,7 @@ protected BeanDeployerEnvironment(EjbDescriptors ejbDescriptors, BeanManagerImpl
new HashSet<AnnotatedType<?>>(),
new HashMap<AnnotatedType<?>, Extension>(),
new HashSet<Class<?>>(),
new HashMap<EnhancedAnnotatedType<?>, AbstractClassBean<?>>(),
new HashMap<AnnotatedType<?>, AbstractClassBean<?>>(),
new HashSet<ProducerField<?, ?>>(),
new HashMap<WeldMethodKey<?, ?>, ProducerMethod<?, ?>>(),
new HashSet<RIBean<?>>(),
Expand All @@ -176,7 +177,7 @@ public void addAnnotatedTypes(Collection<AnnotatedType<?>> annotatedTypes) {
this.annotatedTypes.addAll(annotatedTypes);
}

public void addSyntheticAnnotatedType(AnnotatedType<?> annotatedType, Extension extension) {
public void addSyntheticAnnotatedType(SlimAnnotatedType<?> annotatedType, Extension extension) {
addAnnotatedType(annotatedType);
annotatedTypeSource.put(annotatedType, extension);
}
Expand Down Expand Up @@ -231,8 +232,12 @@ public <X, T> ProducerMethod<X, T> getProducerMethod(EnhancedAnnotatedMethod<X,
return cast(bean);
}

public AbstractClassBean<?> getClassBean(EnhancedAnnotatedType<?> clazz) {
AbstractClassBean<?> bean = classBeanMap.get(clazz);
public AbstractClassBean<?> getClassBean(AnnotatedType<?> clazz) {
AnnotatedType<?> type = clazz;
if (clazz instanceof EnhancedAnnotatedType<?>) {
type = Reflections.<EnhancedAnnotatedType<?>>cast(clazz).slim();
}
AbstractClassBean<?> bean = classBeanMap.get(type);
if (bean != null) {
bean.preInitialize();
}
Expand All @@ -259,7 +264,7 @@ public void addBuiltInBean(AbstractBuiltInBean<?> bean) {

protected void addAbstractClassBean(AbstractClassBean<?> bean) {
if (!(bean instanceof NewBean)) {
classBeanMap.put(bean.getEnhancedAnnotated(), bean);
classBeanMap.put(bean.getEnhancedAnnotated().slim(), bean);
}
addAbstractBean(bean);
}
Expand Down Expand Up @@ -405,7 +410,7 @@ public int hashCode() {
public void vetoBean(AbstractBean<?, ?> bean) {
beans.remove(bean);
if (bean instanceof AbstractClassBean<?>) {
classBeanMap.remove(bean.getEnhancedAnnotated());
classBeanMap.remove(bean.getEnhancedAnnotated().slim());
if (bean instanceof InterceptorImpl<?>) {
interceptors.remove(bean);
}
Expand All @@ -421,7 +426,7 @@ public void vetoBean(AbstractBean<?, ?> bean) {
}
}

public Map<EnhancedAnnotatedType<?>, AbstractClassBean<?>> getClassBeanMap() {
public Map<AnnotatedType<?>, AbstractClassBean<?>> getClassBeanMap() {
return Collections.unmodifiableMap(classBeanMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void addAnnotatedType(AnnotatedType<?> type) {
throw new IllegalStateException("BeforeBeanDiscovery receiver is not an extension");
}
BeanDeployer deployer = getOrCreateBeanDeployment(type.getJavaClass()).getBeanDeployer();
deployer.addSyntheticClass(UnbackedAnnotatedType.of(type), (Extension) receiver);
deployer.addSyntheticClass(type, (Extension) receiver);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -70,7 +71,7 @@ public ResolvableBuilder(Type type) {
this();
if (type != null) {
this.rawType = Reflections.getRawType(type);
if (rawType == null) {
if (rawType == null || type instanceof TypeVariable<?>) {
throw new IllegalArgumentException(CANNOT_EXTRACT_RAW_TYPE, type);
}
this.types.add(type);
Expand Down
Loading

0 comments on commit 0fa3336

Please sign in to comment.