@Test public void testReferencedTypes() { Elements elements = compilationRule.getElements(); TypeElement testDataElement = elements .getTypeElement(ReferencedTypesTestData.class.getCanonicalName()); ImmutableMap<String, VariableElement> fieldIndex = FluentIterable.from(ElementFilter.fieldsIn(testDataElement.getEnclosedElements())) .uniqueIndex(new Function<VariableElement, String>() { @Override public String apply(VariableElement input) { return input.getSimpleName().toString(); } }); TypeElement objectElement = elements.getTypeElement(Object.class.getCanonicalName()); TypeElement stringElement = elements.getTypeElement(String.class.getCanonicalName()); TypeElement integerElement = elements.getTypeElement(Integer.class.getCanonicalName()); TypeElement setElement = elements.getTypeElement(Set.class.getCanonicalName()); TypeElement mapElement = elements.getTypeElement(Map.class.getCanonicalName()); TypeElement charSequenceElement = elements.getTypeElement(CharSequence.class.getCanonicalName()); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f1").asType())) .containsExactly(objectElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f2").asType())) .containsExactly(setElement, stringElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f3").asType())) .containsExactly(mapElement, stringElement, objectElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f4").asType())) .containsExactly(integerElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f5").asType())) .containsExactly(setElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f6").asType())) .containsExactly(setElement, charSequenceElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f7").asType())) .containsExactly(mapElement, stringElement, setElement, charSequenceElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f8").asType())) .containsExactly(stringElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f9").asType())) .containsExactly(stringElement); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f10").asType())).isEmpty(); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f11").asType())).isEmpty(); assertThat(MoreTypes.referencedTypes(fieldIndex.get("f12").asType())) .containsExactly(setElement, stringElement); }
public static ImmutableSet<TypeElement> referencedTypes(TypeMirror type) { checkNotNull(type); ImmutableSet.Builder<TypeElement> elements = ImmutableSet.builder(); type.accept(ReferencedTypes.INSTANCE, elements); return elements.build(); }
MoreTypes { public static ImmutableSet<TypeElement> referencedTypes(TypeMirror type) { checkNotNull(type); ImmutableSet.Builder<TypeElement> elements = ImmutableSet.builder(); type.accept(ReferencedTypes.INSTANCE, elements); return elements.build(); } }
MoreTypes { public static ImmutableSet<TypeElement> referencedTypes(TypeMirror type) { checkNotNull(type); ImmutableSet.Builder<TypeElement> elements = ImmutableSet.builder(); type.accept(ReferencedTypes.INSTANCE, elements); return elements.build(); } private  MoreTypes(); }
MoreTypes { public static ImmutableSet<TypeElement> referencedTypes(TypeMirror type) { checkNotNull(type); ImmutableSet.Builder<TypeElement> elements = ImmutableSet.builder(); type.accept(ReferencedTypes.INSTANCE, elements); return elements.build(); } private  MoreTypes(); static Equivalence<TypeMirror> equivalence(); static ImmutableSet<TypeElement> referencedTypes(TypeMirror type); static Element asElement(TypeMirror typeMirror); static TypeElement asTypeElement(TypeMirror mirror); static ImmutableSet<TypeElement> asTypeElements(Iterable<? extends TypeMirror> mirrors); static ArrayType asArray(TypeMirror maybeArrayType); static DeclaredType asDeclared(TypeMirror maybeDeclaredType); static ErrorType asError(TypeMirror maybeErrorType); static ExecutableType asExecutable(TypeMirror maybeExecutableType); static IntersectionType asIntersection(TypeMirror maybeIntersectionType); static NoType asNoType(TypeMirror maybeNoType); static NullType asNullType(TypeMirror maybeNullType); static PrimitiveType asPrimitiveType(TypeMirror maybePrimitiveType); static TypeVariable asTypeVariable(TypeMirror maybeTypeVariable); static WildcardType asWildcard(TypeMirror maybeWildcardType); static boolean isType(TypeMirror type); static boolean isTypeOf(final Class<?> clazz, TypeMirror type); static Optional<DeclaredType> nonObjectSuperclass(Types types, Elements elements,
      DeclaredType type); static TypeMirror asMemberOf(Types types, DeclaredType container,
      VariableElement variable); static boolean isConversionFromObjectUnchecked(TypeMirror type); }
MoreTypes { public static ImmutableSet<TypeElement> referencedTypes(TypeMirror type) { checkNotNull(type); ImmutableSet.Builder<TypeElement> elements = ImmutableSet.builder(); type.accept(ReferencedTypes.INSTANCE, elements); return elements.build(); } private  MoreTypes(); static Equivalence<TypeMirror> equivalence(); static ImmutableSet<TypeElement> referencedTypes(TypeMirror type); static Element asElement(TypeMirror typeMirror); static TypeElement asTypeElement(TypeMirror mirror); static ImmutableSet<TypeElement> asTypeElements(Iterable<? extends TypeMirror> mirrors); static ArrayType asArray(TypeMirror maybeArrayType); static DeclaredType asDeclared(TypeMirror maybeDeclaredType); static ErrorType asError(TypeMirror maybeErrorType); static ExecutableType asExecutable(TypeMirror maybeExecutableType); static IntersectionType asIntersection(TypeMirror maybeIntersectionType); static NoType asNoType(TypeMirror maybeNoType); static NullType asNullType(TypeMirror maybeNullType); static PrimitiveType asPrimitiveType(TypeMirror maybePrimitiveType); static TypeVariable asTypeVariable(TypeMirror maybeTypeVariable); static WildcardType asWildcard(TypeMirror maybeWildcardType); static boolean isType(TypeMirror type); static boolean isTypeOf(final Class<?> clazz, TypeMirror type); static Optional<DeclaredType> nonObjectSuperclass(Types types, Elements elements,
      DeclaredType type); static TypeMirror asMemberOf(Types types, DeclaredType container,
      VariableElement variable); static boolean isConversionFromObjectUnchecked(TypeMirror type);  }