/** * 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; }
private boolean equalsTypeVariable(TypeVariable<?> that) { return var.getGenericDeclaration().equals(that.getGenericDeclaration()) && var.getName().equals(that.getName()); } }
@Override public int hashCode() { return Objects.hashCode(var.getGenericDeclaration(), var.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; }
@Override public Type resolveInternal(TypeVariable<?> intermediateVar, TypeTable forDependent) { if (intermediateVar.getGenericDeclaration().equals(var.getGenericDeclaration())) { return intermediateVar; } return unguarded.resolveInternal(intermediateVar, forDependent); } };
private boolean equalsTypeVariable(TypeVariable<?> that) { return var.getGenericDeclaration().equals(that.getGenericDeclaration()) && var.getName().equals(that.getName()); } }
/** * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by * a class. */ static @Nullable Class<?> declaringClassOf(TypeVariable<?> typeVariable) { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null; }
/** * Checks whether two types are type variables describing the same. */ public static boolean sameTypeVars(Type t1, Type t2) { return t1 instanceof TypeVariable && t2 instanceof TypeVariable && ((TypeVariable<?>) t1).getName().equals(((TypeVariable<?>) t2).getName()) && ((TypeVariable<?>) t1).getGenericDeclaration().equals(((TypeVariable<?>) t2).getGenericDeclaration()); }
@Override public Type resolveInternal(TypeVariable<?> intermediateVar, TypeTable forDependent) { if (intermediateVar.getGenericDeclaration().equals(var.getGenericDeclaration())) { return intermediateVar; } return unguarded.resolveInternal(intermediateVar, forDependent); } };
private boolean equalsTypeVariable(TypeVariable<?> that) { return var.getGenericDeclaration().equals(that.getGenericDeclaration()) && var.getName().equals(that.getName()); } }
@Override public int hashCode() { return Objects.hashCode(var.getGenericDeclaration(), var.getName()); }
@Override public Type resolveInternal(TypeVariable<?> intermediateVar, TypeTable forDependent) { if (intermediateVar.getGenericDeclaration().equals(var.getGenericDeclaration())) { return intermediateVar; } return unguarded.resolveInternal(intermediateVar, forDependent); } };
@Override public Type resolveInternal(TypeVariable<?> intermediateVar, TypeTable forDependent) { if (intermediateVar.getGenericDeclaration().equals(var.getGenericDeclaration())) { return intermediateVar; } return unguarded.resolveInternal(intermediateVar, forDependent); } };
@Override public int hashCode() { return Objects.hashCode(var.getGenericDeclaration(), var.getName()); }
TypeVariable<?> va = (TypeVariable<?>) a; TypeVariable<?> vb = (TypeVariable<?>) b; return va.getGenericDeclaration() == vb.getGenericDeclaration() && va.getName().equals(vb.getName());
@Override public boolean equals(Object obj) { if (NativeTypeVariableEquals.NATIVE_TYPE_VARIABLE_ONLY) { // equal only to our TypeVariable implementation with identical bounds if (obj != null && Proxy.isProxyClass(obj.getClass()) && Proxy.getInvocationHandler(obj) instanceof TypeVariableInvocationHandler) { TypeVariableInvocationHandler typeVariableInvocationHandler = (TypeVariableInvocationHandler) Proxy.getInvocationHandler(obj); TypeVariableImpl<?> that = typeVariableInvocationHandler.typeVariableImpl; return name.equals(that.getName()) && genericDeclaration.equals(that.getGenericDeclaration()) && bounds.equals(that.bounds); } return false; } else { // equal to any TypeVariable implementation regardless of bounds if (obj instanceof TypeVariable) { TypeVariable<?> that = (TypeVariable<?>) obj; return name.equals(that.getName()) && genericDeclaration.equals(that.getGenericDeclaration()); } return false; } } }
private static <D extends GenericDeclaration> TypeVariable<D> withBounds( TypeVariable<D> typeVariable, Type... bounds) { return Types.newArtificialTypeVariable( typeVariable.getGenericDeclaration(), typeVariable.getName(), bounds); }
/** * {@inheritDoc} */ public TypeVariableSource getTypeVariableSource() { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); if (genericDeclaration instanceof Class) { return TypeDescription.ForLoadedType.of((Class<?>) genericDeclaration); } else if (genericDeclaration instanceof Method) { return new MethodDescription.ForLoadedMethod((Method) genericDeclaration); } else if (genericDeclaration instanceof Constructor) { return new MethodDescription.ForLoadedConstructor((Constructor<?>) genericDeclaration); } else { throw new IllegalStateException("Unknown declaration: " + genericDeclaration); } }
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(); }
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()); }