Navigation Menu

Skip to content

Commit

Permalink
WELD-1007 Weld SE startup fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
luksa authored and stuartwdouglas committed Apr 3, 2012
1 parent 3cdb514 commit 503751f
Showing 1 changed file with 39 additions and 26 deletions.
Expand Up @@ -26,7 +26,6 @@
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.LazyValueHolder;
import org.jboss.weld.util.reflection.Formats;
import org.jboss.weld.util.reflection.Reflections;
import org.jboss.weld.util.reflection.SecureReflections;

import javax.enterprise.inject.spi.AnnotatedConstructor;
Expand All @@ -50,6 +49,7 @@
* @param <T> exact type
* @author Pete Muir
* @author Ales Justin
* @author Marko Luksa
*/
public class WeldConstructorImpl<T> extends AbstractWeldCallable<T, T, Constructor<T>> implements WeldConstructor<T> {
private static final Annotation[] EMPTY = new Annotation[0];
Expand Down Expand Up @@ -86,31 +86,7 @@ private WeldConstructorImpl(Constructor<T> constructor, final Class<T> rawType,

final Class<?>[] parameterTypes = constructor.getParameterTypes();
if (annotatedConstructor == null) {
final Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
final Type[] genericParameterTypes = constructor.getGenericParameterTypes();
final boolean sameLength = (parameterTypes.length == genericParameterTypes.length);
// If the class is a (non-static) member class, its constructors
// parameterTypes array will prefix the
// outer class instance, whilst the genericParameterTypes array isn't
// prefix'd -- not always true ...
int nesting = Reflections.getNesting(declaringClass.getJavaClass());
for (int i = 0; i < parameterTypes.length; i++) {
int gi = i - nesting;

Annotation[] annotations = (gi >= 0 && parameterAnnotations[gi].length > 0) ? parameterAnnotations[gi] : EMPTY;
Class<?> clazz = parameterTypes[i];
Type parameterType;
if (sameLength) {
parameterType = genericParameterTypes[i];
} else {
if (gi >= 0)
parameterType = genericParameterTypes[gi];
else
parameterType = parameterTypes[i];
}
WeldParameter<?, T> parameter = WeldParameterImpl.of(annotations, clazz, parameterType, this, i, classTransformer);
this.parameters.add(parameter);
}
processParameters(classTransformer, parameterTypes);
} else {
if (annotatedConstructor.getParameters().size() != parameterTypes.length) {
throw new DefinitionException(ReflectionMessage.INCORRECT_NUMBER_OF_ANNOTATED_PARAMETERS_METHOD, annotatedConstructor.getParameters().size(), annotatedConstructor, annotatedConstructor.getParameters(), Arrays.asList(parameterTypes));
Expand All @@ -125,6 +101,43 @@ private WeldConstructorImpl(Constructor<T> constructor, final Class<T> rawType,
this.signature = new ConstructorSignatureImpl(this);
}

private void processParameters(ClassTransformer classTransformer, Class<?>[] parameterTypes) {
// If the class is a non-static inner class, the methods behave like this:
// - constructor.getParameterTypes() returns the VM signature of the constructor (in the case of non-static inner classes: outer class + the actual parameters)
// - constructor.getGenericParameterTypes() is tricky, because the array it returns depends on whether any of
// the constructor's parameters use generics (see http://bugs.sun.com/view_bug.do?bug_id=5087240):
// - if any of the constructor's parameters use generics (e.g. Constructor(List<String> list)):
// constructor.getGenericParameterTypes() returns the outer class + the actual parameters
// - if none of the constructor's parameters use generics (e.g. Constructor(List list):
// constructor.getGenericParameterTypes() returns ONLY the actual parameters
// - constructor.getParameterAnnotations() is tricky in the same way as above, but it depends on whether any of
// the parameters has an annotation or not

final Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
final Type[] genericParameterTypes = constructor.getGenericParameterTypes();

int numberOfMissingGenericParameters = parameterTypes.length - genericParameterTypes.length;
int numberOfMissingParameterAnnotations = parameterTypes.length - parameterAnnotations.length;

for (int i = 0; i < parameterTypes.length; i++) {
Type parameterType;
if (i < numberOfMissingGenericParameters) {
parameterType = parameterTypes[i];
} else {
parameterType = genericParameterTypes[i - numberOfMissingGenericParameters];
}

Annotation[] annotations;
if (i < numberOfMissingParameterAnnotations) {
annotations = EMPTY;
} else {
annotations = parameterAnnotations[i - numberOfMissingParameterAnnotations];
}

this.parameters.add(WeldParameterImpl.of(annotations, parameterTypes[i], parameterType, this, i, classTransformer));
}
}

/**
* Gets the constructor
*
Expand Down

0 comments on commit 503751f

Please sign in to comment.