ZeroUtil { public static boolean references(TypeName type, TypeVariableName test) { if (!maybeTypevars(type)) { return false; } if (type instanceof TypeVariableName && ((TypeVariableName) type).bounds.isEmpty()) { return type.equals(test); } TypeWalk walk = new TypeWalk(type); while (walk.hasNext()) { if (walk.next().equals(test)) { return true; } } return false; } private  ZeroUtil(); static String upcase(String s); static String downcase(String s); static CodeBlock statement(String format, Object... args); static ParameterSpec parameterSpec(TypeName type, String name); static FieldSpec fieldSpec(TypeName type, String name, Modifier... modifiers); static ClassName rawClassName(TypeName typeName); static List<E> transform(Collection<? extends X> input, Function<X, E> function); static List<P> cons(P first, List<? extends P> list); static List<P> concat(List<? extends P> left, List<? extends P> right); static Collector<CodeBlock, List<CodeBlock>, CodeBlock> joinCodeBlocks(String delimiter); static Collector<List<E>, List<E>, List<E>> flatList(); static MethodSpec constructor(Modifier... modifiers); static String simpleName(TypeName type); static TypeName parameterizedTypeName(ClassName raw, List<TypeVariableName> typeVars); static Modifier[] modifiers(Access access, Modifier modifiers); static Modifier[] modifiers(Access access); static boolean references(TypeName type, TypeVariableName test); static List<TypeVariableName> extractTypeVars(TypeName type); static List<E> reverse(List<E> in); static final CodeBlock emptyCodeBlock; static final Collector<CodeBlock, List<CodeBlock>, CodeBlock> joinCodeBlocks; }
@Test public void testReferences() throws Exception { assertTrue(references(LIST_OF_K, K)); assertFalse(references(LIST_OF_K, V)); assertTrue(references(MAP_K_V, V)); assertTrue(references(MAP_V_LIST_OF_K, K)); }
@Test public void testReferencesS_V() throws Exception { TypeVariableName s = TypeVariableName.get("S", String.class); TypeVariableName v = TypeVariableName.get("V", s); assertTrue(references(v, s)); }
@Test public void testReferencesS_V_K() throws Exception { TypeVariableName s = TypeVariableName.get("S", String.class); TypeVariableName v = TypeVariableName.get("V", s); TypeVariableName k = TypeVariableName.get("K", v); assertTrue(references(k, s)); }