use of javax.lang.model.type.IntersectionType in project buck by facebook.
the class TreeBackedTypesTest method testIsSameTypeIntersectionTypeDifferentOrder.
/**
* We're not exactly sure why intersection types with the same bounds but in a different order
* are considered the same type; after all, they can have different erasures. However, the javac
* implementation behaves that way, so we must as well.
*
* The relevant JLS8 sections are 4.4 and 4.9, if any future person wants to go see if they
* can grok why this behavior is correct.
*/
@Test
public void testIsSameTypeIntersectionTypeDifferentOrder() throws IOException {
compile(Joiner.on('\n').join("class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }", "class Bar<T extends java.lang.Runnable & java.lang.CharSequence> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertSameType(fooType, barType);
}
use of javax.lang.model.type.IntersectionType in project buck by facebook.
the class StandaloneTypeVariableTest method testGetUpperBoundMultipleBounds.
@Test
public void testGetUpperBoundMultipleBounds() throws IOException {
compile("class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }");
TypeMirror charSequenceType = elements.getTypeElement("java.lang.CharSequence").asType();
TypeMirror runnableType = elements.getTypeElement("java.lang.Runnable").asType();
TypeVariable tVar = (TypeVariable) elements.getTypeElement("Foo").getTypeParameters().get(0).asType();
IntersectionType upperBound = (IntersectionType) tVar.getUpperBound();
List<? extends TypeMirror> bounds = upperBound.getBounds();
assertSame(2, bounds.size());
assertSameType(charSequenceType, bounds.get(0));
assertSameType(runnableType, bounds.get(1));
}
use of javax.lang.model.type.IntersectionType in project buck by facebook.
the class TreeBackedTypesTest method testIsNotSameTypeIntersectionTypeDifferentSize.
@Test
public void testIsNotSameTypeIntersectionTypeDifferentSize() throws IOException {
compile(Joiner.on('\n').join("class Foo<T extends java.lang.CharSequence & java.lang.Runnable> { }", "class Bar<T extends java.lang.CharSequence & java.lang.Runnable & java.io.Closeable> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertNotSameType(fooType, barType);
}
Aggregations