Search in sources :

Example 6 with IntersectionType

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);
}
Also used : IntersectionType(javax.lang.model.type.IntersectionType) Test(org.junit.Test)

Example 7 with IntersectionType

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));
}
Also used : IntersectionType(javax.lang.model.type.IntersectionType) TypeMirror(javax.lang.model.type.TypeMirror) TypeVariable(javax.lang.model.type.TypeVariable) Test(org.junit.Test)

Example 8 with IntersectionType

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);
}
Also used : IntersectionType(javax.lang.model.type.IntersectionType) Test(org.junit.Test)

Aggregations

IntersectionType (javax.lang.model.type.IntersectionType)8 Test (org.junit.Test)7 TypeMirror (javax.lang.model.type.TypeMirror)3 TypeVariable (javax.lang.model.type.TypeVariable)1 WildcardType (javax.lang.model.type.WildcardType)1