Skip to content

Commit

Permalink
WELD-1380 Use member indexes for AnnotatedMember serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Sep 11, 2013
1 parent d4784d1 commit b652ff9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
Expand Up @@ -82,10 +82,10 @@ public interface ReflectionLogger extends WeldLogger {
@Message(id = 609, value = "Cleaning Javassist proxy. Class {0}", format = Format.MESSAGE_FORMAT)
String cleaningJavassistProxyClass(Object param1);

@Message(id = 610, value = "Unable to deserialize constructor. Declaring class {0}, signature {1}", format = Format.MESSAGE_FORMAT)
@Message(id = 610, value = "Unable to deserialize constructor. Declaring class {0}, index {1}", format = Format.MESSAGE_FORMAT)
WeldException unableToGetConstructorOnDeserialization(Object param1, Object param2, @Cause Throwable cause);

@Message(id = 611, value = "Unable to deserialize method. Declaring class {0}, signature {1}", format = Format.MESSAGE_FORMAT)
@Message(id = 611, value = "Unable to deserialize method. Declaring class {0}, index {1}", format = Format.MESSAGE_FORMAT)
WeldException unableToGetMethodOnDeserialization(Object param1, Object param2, @Cause Throwable cause);

@Message(id = 612, value = "Unable to deserialize field. Declaring class {0}, field name {1}", format = Format.MESSAGE_FORMAT)
Expand Down
Expand Up @@ -21,6 +21,7 @@
import java.security.PrivilegedAction;

import org.jboss.weld.logging.ReflectionLogger;
import org.jboss.weld.util.reflection.DeclaredMemberIndexer;

/**
* Serializable holder for {@link Constructor}.
Expand All @@ -37,12 +38,12 @@ public static <T> ConstructorHolder<T> of(Constructor<T> constructor) {
}

private final Class<X> declaringClass;
private final Class<?>[] parameterTypes;
private final int index;

public ConstructorHolder(Constructor<X> constructor) {
super(constructor);
this.declaringClass = constructor.getDeclaringClass();
this.parameterTypes = constructor.getParameterTypes();
this.index = DeclaredMemberIndexer.getIndexForConstructor(constructor);
}

@Override
Expand All @@ -53,9 +54,9 @@ protected Constructor<X> initialize() {
@Override
public Constructor<X> run() {
try {
return declaringClass.getDeclaredConstructor(parameterTypes);
return DeclaredMemberIndexer.getConstructorForIndex(index, declaringClass);
} catch (Exception e) {
throw ReflectionLogger.LOG.unableToGetConstructorOnDeserialization(declaringClass, parameterTypes, e);
throw ReflectionLogger.LOG.unableToGetConstructorOnDeserialization(declaringClass, index, e);
}
}
}
Expand Up @@ -24,6 +24,7 @@

import org.jboss.weld.interceptor.spi.metadata.MethodMetadata;
import org.jboss.weld.logging.ReflectionLogger;
import org.jboss.weld.util.reflection.DeclaredMemberIndexer;

import com.google.common.base.Objects;

Expand All @@ -38,14 +39,12 @@ public class MethodHolder extends AbstractSerializableHolder<Method> implements
private static final long serialVersionUID = -3033089710155551280L;

private final Class<?> declaringClass;
private final String methodName;
private final Class<?>[] parameterTypes;
private final int index;

public MethodHolder(Method method) {
super(method);
this.index = DeclaredMemberIndexer.getIndexForMethod(method);
this.declaringClass = method.getDeclaringClass();
this.methodName = method.getName();
this.parameterTypes = method.getParameterTypes();
}

public static MethodHolder of(Method method) {
Expand All @@ -68,9 +67,9 @@ protected Method initialize() {
@Override
public Method run() {
try {
return declaringClass.getDeclaredMethod(methodName, parameterTypes);
return DeclaredMemberIndexer.getMethodForIndex(index, declaringClass);
} catch (Exception e) {
throw ReflectionLogger.LOG.unableToGetMethodOnDeserialization(declaringClass, parameterTypes, e);
throw ReflectionLogger.LOG.unableToGetMethodOnDeserialization(declaringClass, index, e);
}
}

Expand Down
Expand Up @@ -16,6 +16,8 @@
*/
package org.jboss.weld.util.reflection;

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

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
Expand Down Expand Up @@ -96,8 +98,8 @@ public static int getIndexForConstructor(Constructor<?> constructor) {
* @return the declared constructor for the given index and declaring class
* @throws IndexOutOfBoundsException if the index is out of range
*/
public static Constructor<?> getConstructorForIndex(int index, Class<?> declaringClass) {
return getDeclaredConstructors(declaringClass).get(index);
public static <T> Constructor<T> getConstructorForIndex(int index, Class<T> declaringClass) {
return cast(getDeclaredConstructors(declaringClass).get(index));
}

private static <T extends Member> int getIndexForMember(T declaredMember, List<T> declaredMembers) {
Expand Down

0 comments on commit b652ff9

Please sign in to comment.