/** * @return either a class or an interface (parameterized or not), if no bounds declared Object is returned. */ public Type firstBound() { return typeVariable.getBounds()[0]; // }
private boolean equalsTypeVariable(TypeVariable<?> that) { return var.getGenericDeclaration().equals(that.getGenericDeclaration()) && var.getName().equals(that.getName()); } }
/** * Format a {@link TypeVariable} as a {@link String}. * @param v {@code TypeVariable} to format * @return String * @since 3.2 */ private static String typeVariableToString(final TypeVariable<?> v) { final StringBuilder buf = new StringBuilder(v.getName()); final Type[] bounds = v.getBounds(); if (bounds.length > 0 && !(bounds.length == 1 && Object.class.equals(bounds[0]))) { buf.append(" extends "); appendAllTo(buf, " & ", v.getBounds()); } return buf.toString(); }
private static void assertEqualTypeVariable(TypeVariable<?> expected, TypeVariable<?> actual) { assertEquals(expected.toString(), actual.toString()); assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getGenericDeclaration(), actual.getGenericDeclaration()); if (!Types.NativeTypeVariableEquals.NATIVE_TYPE_VARIABLE_ONLY) { assertEquals(actual.toString(), expected.hashCode(), actual.hashCode()); } assertThat(actual.getBounds()) .asList() .containsExactlyElementsIn(asList(expected.getBounds())) .inOrder(); }
/** * {@inheritDoc} */ public String getSymbol() { return typeVariable.getName(); }
/** * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by * a class. */ private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null; }
Type type = map.get(new TypeVariableKey(var)); if (type == null) { Type[] bounds = var.getBounds(); if (bounds.length == 0) { return var; var.getGenericDeclaration(), var.getName(), resolvedBounds);
@Override public String toString() { return variable.getName(); }
/** * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by * a class. */ private static Class<?> declaringClassOf(TypeVariable typeVariable) { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null; }
/** * On a Type Variable (typeVar extends C_0 & I_1 & I_2 & etc), will return an array * containing I_1 and I_2. * * @return other bounds for this type, these bounds can only be only interfaces as the JLS says, * empty array if no other bound declared. */ public Type[] interfaceBounds() { Type[] interfaceBounds = new Type[typeVariable.getBounds().length - 1]; System.arraycopy(typeVariable.getBounds(), 1, interfaceBounds, 0, typeVariable.getBounds().length - 1); return interfaceBounds; }
@Override public int hashCode() { return Objects.hashCode(var.getGenericDeclaration(), var.getName()); }
/** @see #get(java.lang.reflect.TypeVariable, Map) */ static TypeVariableName get(java.lang.reflect.TypeVariable<?> type, Map<Type, TypeVariableName> map) { TypeVariableName result = map.get(type); if (result == null) { List<TypeName> bounds = new ArrayList<>(); List<TypeName> visibleBounds = Collections.unmodifiableList(bounds); result = new TypeVariableName(type.getName(), visibleBounds); map.put(type, result); for (Type bound : type.getBounds()) { bounds.add(TypeName.get(bound, map)); } bounds.remove(OBJECT); } return result; } }
private void assertEqualTypeVariables(TypeVariable<?> expected, TypeVariable<?> actual) { Assert.assertEquals(expected.getName(), actual.getName()); assertEqualTypeArrays(expected.getBounds(), actual.getBounds()); //order not relevant: this check is stronger than it needs to be assertEqualGenericDecl(expected.getGenericDeclaration(), actual.getGenericDeclaration()); }
public String getVariableName() { return variable.getName(); } }
@Override public Type resolveInternal(TypeVariable<?> intermediateVar, TypeTable forDependent) { if (intermediateVar.getGenericDeclaration().equals(var.getGenericDeclaration())) { return intermediateVar; } return unguarded.resolveInternal(intermediateVar, forDependent); } };
@Override void visitTypeVariable(TypeVariable<?> t) { result.set(subtypeOfComponentType(t.getBounds())); }
private boolean equalsTypeVariable(TypeVariable<?> that) { return var.getGenericDeclaration().equals(that.getGenericDeclaration()) && var.getName().equals(that.getName()); } }
protected JavaType _fromVariable(ClassStack context, TypeVariable<?> var, TypeBindings bindings) { // ideally should find it via bindings: final String name = var.getName(); if (bindings == null) throw new Error("No Bindings!"); JavaType type = bindings.findBoundType(name); if (type != null) { return type; } // but if not, use bounds... note that approach here is simplistic; not taking // into account possible multiple bounds, nor consider upper bounds. if (bindings.hasUnbound(name)) { return CORE_TYPE_OBJECT; } bindings = bindings.withUnboundVariable(name); Type[] bounds = var.getBounds(); return _fromAny(context, bounds[0], bindings); }
public static int getGenericTypeIndex(TypeVariable<?>[] typeParameters, final String parameterName) { for (int i = 0; i < typeParameters.length; i++) { if (typeParameters[i].getName().equals(parameterName)) { return i; } } return -1; }