public static TypeVariable[] callGetTypeParameters(Constructor thiz) { return thiz.getTypeParameters(); }
/** * {@inheritDoc} * * <p>{@code [<E>]} will be returned for ArrayList's constructor. When both the class and the * constructor have type parameters, the class parameters are prepended before those of the * constructor's. This is an arbitrary rule since no existing language spec mandates one way or * the other. From the declaration syntax, the class type parameter appears first, but the call * syntax may show up in opposite order such as {@code new <A>Foo<B>()}. */ @Override public final TypeVariable<?>[] getTypeParameters() { TypeVariable<?>[] declaredByClass = getDeclaringClass().getTypeParameters(); TypeVariable<?>[] declaredByConstructor = constructor.getTypeParameters(); TypeVariable<?>[] result = new TypeVariable<?>[declaredByClass.length + declaredByConstructor.length]; System.arraycopy(declaredByClass, 0, result, 0, declaredByClass.length); System.arraycopy( declaredByConstructor, 0, result, declaredByClass.length, declaredByConstructor.length); return result; }
/** * {@inheritDoc} * * <p>{@code [<E>]} will be returned for ArrayList's constructor. When both the class and the * constructor have type parameters, the class parameters are prepended before those of the * constructor's. This is an arbitrary rule since no existing language spec mandates one way or * the other. From the declaration syntax, the class type parameter appears first, but the call * syntax may show up in opposite order such as {@code new <A>Foo<B>()}. */ @Override public final TypeVariable<?>[] getTypeParameters() { TypeVariable<?>[] declaredByClass = getDeclaringClass().getTypeParameters(); TypeVariable<?>[] declaredByConstructor = constructor.getTypeParameters(); TypeVariable<?>[] result = new TypeVariable<?>[declaredByClass.length + declaredByConstructor.length]; System.arraycopy(declaredByClass, 0, result, 0, declaredByClass.length); System.arraycopy( declaredByConstructor, 0, result, declaredByClass.length, declaredByConstructor.length); return result; }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * {@inheritDoc} * * <p>{@code [<E>]} will be returned for ArrayList's constructor. When both the class and the * constructor have type parameters, the class parameters are prepended before those of the * constructor's. This is an arbitrary rule since no existing language spec mandates one way or * the other. From the declaration syntax, the class type parameter appears first, but the call * syntax may show up in opposite order such as {@code new <A>Foo<B>()}. */ @Override public final TypeVariable<?>[] getTypeParameters() { TypeVariable<?>[] declaredByClass = getDeclaringClass().getTypeParameters(); TypeVariable<?>[] declaredByConstructor = constructor.getTypeParameters(); TypeVariable<?>[] result = new TypeVariable<?>[declaredByClass.length + declaredByConstructor.length]; System.arraycopy(declaredByClass, 0, result, 0, declaredByClass.length); System.arraycopy( declaredByConstructor, 0, result, declaredByClass.length, declaredByConstructor.length); return result; }
public void testConstructor_returnType_hasTypeParameter() throws Exception { @SuppressWarnings("rawtypes") // Foo.class for Foo<T> is always raw type Class<WithConstructorAndTypeParameter> type = WithConstructorAndTypeParameter.class; @SuppressWarnings("rawtypes") // Foo.class Constructor<WithConstructorAndTypeParameter> constructor = type.getDeclaredConstructor(); Invokable<?, ?> factory = Invokable.from(constructor); assertThat(factory.getTypeParameters()).hasLength(2); assertEquals(type.getTypeParameters()[0], factory.getTypeParameters()[0]); assertEquals(constructor.getTypeParameters()[0], factory.getTypeParameters()[1]); ParameterizedType returnType = (ParameterizedType) factory.getReturnType().getType(); assertEquals(type, returnType.getRawType()); assertEquals( ImmutableList.copyOf(type.getTypeParameters()), ImmutableList.copyOf(returnType.getActualTypeArguments())); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
@Override public <T> void visitConstructor(Constructor<T> constructor) { for (Annotation annotation : constructor.getDeclaredAnnotations()) { visitAnnotation(annotation); } int nrEnclosingClasses = getNumberOfEnclosingClasses(constructor.getDeclaringClass()); for (RtParameter parameter : RtParameter.parametersOf(constructor)) { //ignore implicit parameters of enclosing classes if (nrEnclosingClasses > 0) { nrEnclosingClasses--; continue; } visitParameter(parameter); } for (TypeVariable<Constructor<T>> aTypeParameter : constructor.getTypeParameters()) { visitTypeParameter(aTypeParameter); } for (Class<?> exceptionType : constructor.getExceptionTypes()) { visitTypeReference(CtRole.THROWN, exceptionType); } }
@Override public MetaTypeVariable[] getTypeParameters() { if (_typeParameters != null) return _typeParameters; return _typeParameters = JavaReflectionUtil.fromTypeVariable(constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
@Override public MetaTypeVariable[] getTypeParameters() { if (_typeParameters != null) return _typeParameters; return _typeParameters = JavaReflectionUtil.fromTypeVariable(constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * As per [JACKSON-468], we need to also allow declaration of local * type bindings; mostly it will allow defining bounds. */ @Override public JavaType getType(TypeBindings bindings) { return getType(bindings, _constructor.getTypeParameters()); }
/** * Generates the signature for the given constructor */ public static String signature(Constructor<?> constructor) { StringBuilder builder = new StringBuilder(); visitFormalTypeParameters(builder, constructor.getTypeParameters()); visitParameters(builder, constructor.getGenericParameterTypes()); builder.append("V"); visitExceptions(builder, constructor.getGenericExceptionTypes()); return builder.toString(); }