use of javax.lang.model.type.IntersectionType in project buck by facebook.
the class StandaloneIntersectionTypeTest method testGetBounds.
@Test
public void testGetBounds() throws IOException {
compile("class Foo<T extends java.lang.Runnable & java.lang.CharSequence> { }");
TypeMirror runnableType = elements.getTypeElement("java.lang.Runnable").asType();
TypeMirror charSequenceType = elements.getTypeElement("java.lang.CharSequence").asType();
IntersectionType intersectionType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
List<? extends TypeMirror> bounds = intersectionType.getBounds();
assertSame(2, bounds.size());
assertSameType(runnableType, bounds.get(0));
assertSameType(charSequenceType, bounds.get(1));
}
use of javax.lang.model.type.IntersectionType in project buck by facebook.
the class TreeBackedTypesTest method testIsNotSameTypeIntersectionTypeDifferentSizeReversed.
@Test
public void testIsNotSameTypeIntersectionTypeDifferentSizeReversed() throws IOException {
compile(Joiner.on('\n').join("class Foo<T extends java.lang.CharSequence & java.lang.Runnable & java.io.Closeable> { }", "class Bar<T extends java.lang.CharSequence & java.lang.Runnable> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertNotSameType(fooType, barType);
}
use of javax.lang.model.type.IntersectionType in project buck by facebook.
the class TreeBackedTypesTest method testIsSameTypeIntersectionType.
@Test
public void testIsSameTypeIntersectionType() 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> { }"));
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 TreeBackedTypesTest method testIsNotSameTypeIntersectionTypeDifferentContents.
@Test
public void testIsNotSameTypeIntersectionTypeDifferentContents() 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.io.Closeable> { }"));
IntersectionType fooType = (IntersectionType) getTypeParameterUpperBound("Foo", 0);
IntersectionType barType = (IntersectionType) getTypeParameterUpperBound("Bar", 0);
assertNotSameType(fooType, barType);
}
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);
}
Aggregations