Skip to content

Commit

Permalink
Simplify BackedAnnotatedTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Oct 30, 2012
1 parent 1ca6631 commit 7b8f71b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Set;

import org.jboss.weld.annotated.slim.BaseAnnotated;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.ReflectionCache;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.LazyValueHolder;
Expand All @@ -15,9 +14,9 @@ public abstract class BackedAnnotated extends BaseAnnotated {

private final LazyValueHolder<Set<Type>> typeClosure;

public BackedAnnotated(Type baseType, ClassTransformer transformer) {
public BackedAnnotated(Type baseType, SharedObjectCache sharedObjectCache) {
super(baseType);
this.typeClosure = initTypeClosure(baseType, transformer.getSharedObjectCache());
this.typeClosure = initTypeClosure(baseType, sharedObjectCache);
}

protected LazyValueHolder<Set<Type>> initTypeClosure(Type baseType, SharedObjectCache cache) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
import javax.enterprise.inject.spi.AnnotatedCallable;
import javax.enterprise.inject.spi.AnnotatedParameter;

import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.SharedObjectCache;

public abstract class BackedAnnotatedCallable<X, M extends Member> extends BackedAnnotatedMember<X> implements AnnotatedCallable<X> {

private final List<AnnotatedParameter<X>> parameters;

public BackedAnnotatedCallable(M member, Type baseType, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(baseType, declaringType, transformer);
this.parameters = initParameters(member, transformer);
public BackedAnnotatedCallable(M member, Type baseType, BackedAnnotatedType<X> declaringType, SharedObjectCache sharedObjectCache) {
super(baseType, declaringType, sharedObjectCache);
this.parameters = initParameters(member, sharedObjectCache);
}

protected abstract List<AnnotatedParameter<X>> initParameters(M member, ClassTransformer transformer);
protected abstract List<AnnotatedParameter<X>> initParameters(M member, SharedObjectCache sharedObjectCache);

@Override
public List<AnnotatedParameter<X>> getParameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import org.jboss.weld.Container;
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.MemberTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.serialization.ConstructorHolder;
import org.jboss.weld.util.reflection.Formats;
import org.jboss.weld.util.reflection.Reflections;
Expand All @@ -30,19 +30,19 @@
@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedConstructor<X> extends BackedAnnotatedCallable<X, Constructor<X>> implements AnnotatedConstructor<X>, Serializable {

public static <X> AnnotatedConstructor<X> of(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
return new BackedAnnotatedConstructor<X>(constructor, declaringType, transformer);
public static <X> AnnotatedConstructor<X> of(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, SharedObjectCache sharedObjectCache) {
return new BackedAnnotatedConstructor<X>(constructor, declaringType, sharedObjectCache);
}

private final Constructor<X> constructor;

public BackedAnnotatedConstructor(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(constructor, constructor.getDeclaringClass(), declaringType, transformer);
public BackedAnnotatedConstructor(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, SharedObjectCache sharedObjectCache) {
super(constructor, constructor.getDeclaringClass(), declaringType, sharedObjectCache);
this.constructor = constructor;
}

@Override
protected List<AnnotatedParameter<X>> initParameters(Constructor<X> member, ClassTransformer transformer) {
protected List<AnnotatedParameter<X>> initParameters(Constructor<X> member, SharedObjectCache sharedObjectCache) {
final Class<?>[] parameterTypes = member.getParameterTypes();
final Type[] genericParameterTypes = member.getGenericParameterTypes();
Annotation[][] parameterAnnotations = member.getParameterAnnotations();
Expand All @@ -63,7 +63,7 @@ protected List<AnnotatedParameter<X>> initParameters(Constructor<X> member, Clas
parameterType = clazz;
position = i;
}
parameters.add(new BackedAnnotatedParameter<X>(parameterType, parameterAnnotations[position], position, this, transformer));
parameters.add(new BackedAnnotatedParameter<X>(parameterType, parameterAnnotations[position], position, this, sharedObjectCache));
}
return immutableList(parameters);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

import org.jboss.weld.Container;
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.MemberTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.serialization.FieldHolder;
import org.jboss.weld.util.reflection.Formats;

Expand All @@ -25,15 +25,15 @@
@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedField<X> extends BackedAnnotatedMember<X> implements AnnotatedField<X>, Serializable {

public static <X, Y extends X> AnnotatedField<X> of(Field field, BackedAnnotatedType<Y> declaringType, ClassTransformer transformer) {
public static <X, Y extends X> AnnotatedField<X> of(Field field, BackedAnnotatedType<Y> declaringType, SharedObjectCache sharedObjectCache) {
BackedAnnotatedType<X> downcastDeclaringType = cast(declaringType);
return new BackedAnnotatedField<X>(field.getGenericType(), field, downcastDeclaringType, transformer);
return new BackedAnnotatedField<X>(field.getGenericType(), field, downcastDeclaringType, sharedObjectCache);
}

private final Field field;

public BackedAnnotatedField(Type baseType, Field field, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(baseType, declaringType, transformer);
public BackedAnnotatedField(Type baseType, Field field, BackedAnnotatedType<X> declaringType, SharedObjectCache sharedObjectCache) {
super(baseType, declaringType, sharedObjectCache);
this.field = field;
}

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

import javax.enterprise.inject.spi.AnnotatedMember;

import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.ReflectionCache;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.LazyValueHolder;
Expand All @@ -16,8 +15,8 @@ public abstract class BackedAnnotatedMember<X> extends BackedAnnotated implement

private BackedAnnotatedType<X> declaringType;

public BackedAnnotatedMember(Type baseType, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(baseType, transformer);
public BackedAnnotatedMember(Type baseType, BackedAnnotatedType<X> declaringType, SharedObjectCache sharedObjectCache) {
super(baseType, sharedObjectCache);
this.declaringType = declaringType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import org.jboss.weld.Container;
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.MemberTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.serialization.MethodHolder;
import org.jboss.weld.util.reflection.Formats;

Expand All @@ -29,28 +29,28 @@
@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedMethod<X> extends BackedAnnotatedCallable<X, Method> implements AnnotatedMethod<X>, Serializable {

public static <X, Y extends X> AnnotatedMethod<X> of(Method method, BackedAnnotatedType<Y> declaringType, ClassTransformer transformer) {
public static <X, Y extends X> AnnotatedMethod<X> of(Method method, BackedAnnotatedType<Y> declaringType, SharedObjectCache sharedObjectCache) {
BackedAnnotatedType<X> downcastDeclaringType = cast(declaringType);
return new BackedAnnotatedMethod<X>(method, downcastDeclaringType, transformer);
return new BackedAnnotatedMethod<X>(method, downcastDeclaringType, sharedObjectCache);
}

private final Method method;

public BackedAnnotatedMethod(Method method, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(method, method.getGenericReturnType(), declaringType, transformer);
public BackedAnnotatedMethod(Method method, BackedAnnotatedType<X> declaringType, SharedObjectCache sharedObjectCache) {
super(method, method.getGenericReturnType(), declaringType, sharedObjectCache);
this.method = method;
}

@Override
protected List<AnnotatedParameter<X>> initParameters(Method method, ClassTransformer transformer) {
protected List<AnnotatedParameter<X>> initParameters(Method method, SharedObjectCache sharedObjectCache) {
final Type[] genericParameterTypes = method.getGenericParameterTypes();

List<AnnotatedParameter<X>> parameters = new ArrayList<AnnotatedParameter<X>>(genericParameterTypes.length);

Annotation[][] parameterAnnotations = method.getParameterAnnotations();
for (int i = 0; i < genericParameterTypes.length; i++) {
Type parameterType = genericParameterTypes[i];
parameters.add(BackedAnnotatedParameter.of(parameterType, parameterAnnotations[i], i, this, transformer));
parameters.add(BackedAnnotatedParameter.of(parameterType, parameterAnnotations[i], i, this, sharedObjectCache));
}
return immutableList(parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,26 @@
import javax.enterprise.inject.spi.AnnotatedParameter;

import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.ReflectionCache;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.LazyValueHolder;
import org.jboss.weld.util.reflection.Formats;
import org.jboss.weld.util.reflection.RawType;

import com.google.common.collect.ImmutableSet;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedParameter<X> extends BackedAnnotated implements AnnotatedParameter<X>, Serializable {

public static <X> AnnotatedParameter<X> of(Type baseType, Annotation[] annotations, int position, BackedAnnotatedCallable<X, ?> declaringCallable, ClassTransformer transformer) {
return new BackedAnnotatedParameter<X>(baseType, annotations, position, declaringCallable, transformer);
public static <X> AnnotatedParameter<X> of(Type baseType, Annotation[] annotations, int position, BackedAnnotatedCallable<X, ?> declaringCallable, SharedObjectCache sharedObjectCache) {
return new BackedAnnotatedParameter<X>(baseType, annotations, position, declaringCallable, sharedObjectCache);
}

private final int position;
private final BackedAnnotatedCallable<X, ?> declaringCallable;

public BackedAnnotatedParameter(Type baseType, Annotation[] annotations, int position, BackedAnnotatedCallable<X, ?> declaringCallable, ClassTransformer transformer) {
super(baseType, transformer);
public BackedAnnotatedParameter(Type baseType, Annotation[] annotations, int position, BackedAnnotatedCallable<X, ?> declaringCallable, SharedObjectCache sharedObjectCache) {
super(baseType, sharedObjectCache);
this.position = position;
this.declaringCallable = declaringCallable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.ReflectionCache;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.LazyValueHolder;
import org.jboss.weld.util.collections.ArraySet;
import org.jboss.weld.util.reflection.Formats;
Expand All @@ -48,11 +49,15 @@ public static <X> BackedAnnotatedType<X> of(Class<X> javaClass, Type baseType, C
private final LazyValueHolder<Set<AnnotatedMethod<? super X>>> methods;
private final LazyValueHolder<Set<AnnotatedField<? super X>>> fields;
private final ClassTransformer transformer;
private final SharedObjectCache sharedObjectCache;
private final ReflectionCache reflectionCache;

public BackedAnnotatedType(Class<X> rawType, Type baseType, ClassTransformer classTransformer) {
super(baseType, classTransformer);
super(baseType, classTransformer.getSharedObjectCache());
this.javaClass = rawType;
this.transformer = classTransformer;
this.sharedObjectCache = classTransformer.getSharedObjectCache();
this.reflectionCache = classTransformer.getReflectionCache();

this.constructors = new BackedAnnotatedConstructors();
this.fields = new BackedAnnotatedFields();
Expand Down Expand Up @@ -173,7 +178,7 @@ protected Set<AnnotatedConstructor<X>> computeValue() {
ArraySet<AnnotatedConstructor<X>> constructors = new ArraySet<AnnotatedConstructor<X>>(declaredConstructors.length);
for (Constructor<?> constructor : declaredConstructors) {
Constructor<X> c = Reflections.cast(constructor);
constructors.add(BackedAnnotatedConstructor.of(c, BackedAnnotatedType.this, transformer));
constructors.add(BackedAnnotatedConstructor.of(c, BackedAnnotatedType.this, sharedObjectCache));
}
return immutableSet(constructors);
}
Expand All @@ -186,7 +191,7 @@ protected Set<AnnotatedField<? super X>> computeValue() {
Class<? super X> clazz = javaClass;
while (clazz != Object.class && clazz != null) {
for (Field field : SecureReflections.getDeclaredFields(clazz)) {
fields.add(BackedAnnotatedField.of(field, getDeclaringAnnotatedType(field, transformer), transformer));
fields.add(BackedAnnotatedField.of(field, getDeclaringAnnotatedType(field, transformer), sharedObjectCache));
}
clazz = clazz.getSuperclass();
}
Expand All @@ -201,7 +206,7 @@ protected Set<AnnotatedMethod<? super X>> computeValue() {
Class<? super X> clazz = javaClass;
while (clazz != Object.class && clazz != null) {
for (Method method : SecureReflections.getDeclaredMethods(clazz)) {
methods.add(BackedAnnotatedMethod.of(method, getDeclaringAnnotatedType(method, transformer), transformer));
methods.add(BackedAnnotatedMethod.of(method, getDeclaringAnnotatedType(method, transformer), sharedObjectCache));
}
clazz = clazz.getSuperclass();
}
Expand All @@ -210,6 +215,6 @@ protected Set<AnnotatedMethod<? super X>> computeValue() {
}

public ReflectionCache getReflectionCache() {
return transformer.getReflectionCache();
return reflectionCache;
}
}

0 comments on commit 7b8f71b

Please sign in to comment.