@Test public void equivalence() { Types types = compilationRule.getTypes(); Elements elements = compilationRule.getElements(); TypeMirror objectType = elements.getTypeElement(Object.class.getCanonicalName()).asType(); TypeMirror stringType = elements.getTypeElement(String.class.getCanonicalName()).asType(); TypeElement mapElement = elements.getTypeElement(Map.class.getCanonicalName()); TypeElement setElement = elements.getTypeElement(Set.class.getCanonicalName()); TypeElement enumElement = elements.getTypeElement(Enum.class.getCanonicalName()); TypeElement container = elements.getTypeElement(Container.class.getCanonicalName()); TypeElement contained = elements.getTypeElement(Container.Contained.class.getCanonicalName()); TypeElement funkyBounds = elements.getTypeElement(FunkyBounds.class.getCanonicalName()); TypeElement funkyBounds2 = elements.getTypeElement(FunkyBounds2.class.getCanonicalName()); TypeElement funkierBounds = elements.getTypeElement(FunkierBounds.class.getCanonicalName()); TypeMirror funkyBoundsVar = ((DeclaredType) funkyBounds.asType()).getTypeArguments().get(0); TypeMirror funkyBounds2Var = ((DeclaredType) funkyBounds2.asType()).getTypeArguments().get(0); TypeMirror funkierBoundsVar = ((DeclaredType) funkierBounds.asType()).getTypeArguments().get(0); DeclaredType mapOfObjectToObjectType = types.getDeclaredType(mapElement, objectType, objectType); TypeMirror mapType = mapElement.asType(); DeclaredType setOfSetOfObject = types.getDeclaredType(setElement, types.getDeclaredType(setElement, objectType)); DeclaredType setOfSetOfString = types.getDeclaredType(setElement, types.getDeclaredType(setElement, stringType)); DeclaredType setOfSetOfSetOfObject = types.getDeclaredType(setElement, setOfSetOfObject); DeclaredType setOfSetOfSetOfString = types.getDeclaredType(setElement, setOfSetOfString); WildcardType wildcard = types.getWildcardType(null, null); DeclaredType containerOfObject = types.getDeclaredType(container, objectType); DeclaredType containerOfString = types.getDeclaredType(container, stringType); TypeMirror containedInObject = types.asMemberOf(containerOfObject, contained); TypeMirror containedInString = types.asMemberOf(containerOfString, contained); EquivalenceTester<TypeMirror> tester = EquivalenceTester.<TypeMirror>of(MoreTypes.equivalence()) .addEquivalenceGroup(types.getNullType()) .addEquivalenceGroup(types.getNoType(NONE)) .addEquivalenceGroup(types.getNoType(VOID)) .addEquivalenceGroup(objectType) .addEquivalenceGroup(stringType) .addEquivalenceGroup(containedInObject) .addEquivalenceGroup(containedInString) .addEquivalenceGroup(funkyBounds.asType()) .addEquivalenceGroup(funkyBounds2.asType()) .addEquivalenceGroup(funkierBounds.asType()) .addEquivalenceGroup(funkyBoundsVar, funkyBounds2Var) .addEquivalenceGroup(funkierBoundsVar) .addEquivalenceGroup(enumElement.asType()) .addEquivalenceGroup(mapType) .addEquivalenceGroup(mapOfObjectToObjectType) .addEquivalenceGroup(types.getDeclaredType(mapElement, wildcard, wildcard)) .addEquivalenceGroup(types.erasure(mapType), types.erasure(mapOfObjectToObjectType)) .addEquivalenceGroup(types.getDeclaredType(mapElement, objectType, stringType)) .addEquivalenceGroup(types.getDeclaredType(mapElement, stringType, objectType)) .addEquivalenceGroup(types.getDeclaredType(mapElement, stringType, stringType)) .addEquivalenceGroup(setOfSetOfObject) .addEquivalenceGroup(setOfSetOfString) .addEquivalenceGroup(setOfSetOfSetOfObject) .addEquivalenceGroup(setOfSetOfSetOfString) .addEquivalenceGroup(wildcard) .addEquivalenceGroup(types.getWildcardType(objectType, null)) .addEquivalenceGroup(types.getWildcardType(stringType, null)) .addEquivalenceGroup(types.getWildcardType(null, stringType)) .addEquivalenceGroup(types.getDeclaredType(mapElement, stringType, types.getDeclaredType(mapElement, stringType, types.getDeclaredType(setElement, objectType)))) .addEquivalenceGroup(FAKE_ERROR_TYPE) ; for (TypeKind kind : TypeKind.values()) { if (kind.isPrimitive()) { PrimitiveType primitiveType = types.getPrimitiveType(kind); TypeMirror boxedPrimitiveType = types.boxedClass(primitiveType).asType(); tester.addEquivalenceGroup(primitiveType, types.unboxedType(boxedPrimitiveType)); tester.addEquivalenceGroup(boxedPrimitiveType); tester.addEquivalenceGroup(types.getArrayType(primitiveType)); tester.addEquivalenceGroup(types.getArrayType(boxedPrimitiveType)); } } ImmutableSet<Class<?>> testClasses = ImmutableSet.of( ExecutableElementsGroupA.class, ExecutableElementsGroupB.class, ExecutableElementsGroupC.class, ExecutableElementsGroupD.class, ExecutableElementsGroupE.class); for (Class<?> testClass : testClasses) { ImmutableList<TypeMirror> equivalenceGroup = FluentIterable.from( elements.getTypeElement(testClass.getCanonicalName()).getEnclosedElements()) .transform(new Function<Element, TypeMirror>() { @Override public TypeMirror apply(Element input) { return input.asType(); } }) .toList(); tester.addEquivalenceGroup(equivalenceGroup); } tester.test(); }
public static Equivalence<TypeMirror> equivalence() { return TypeEquivalence.INSTANCE; }
MoreTypes { public static Equivalence<TypeMirror> equivalence() { return TypeEquivalence.INSTANCE; } }
MoreTypes { public static Equivalence<TypeMirror> equivalence() { return TypeEquivalence.INSTANCE; } private  MoreTypes(); }
MoreTypes { public static Equivalence<TypeMirror> equivalence() { return TypeEquivalence.INSTANCE; } 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 Equivalence<TypeMirror> equivalence() { return TypeEquivalence.INSTANCE; } 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);  }