Search in sources :

Example 1 with IntersectionType

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

Example 2 with IntersectionType

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

Example 3 with IntersectionType

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

Example 4 with IntersectionType

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

Example 5 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)

Aggregations

IntersectionType (javax.lang.model.type.IntersectionType)9 Test (org.junit.Test)7 TypeMirror (javax.lang.model.type.TypeMirror)4 TypeVariable (javax.lang.model.type.TypeVariable)2 WildcardType (javax.lang.model.type.WildcardType)2 Tree (com.sun.source.tree.Tree)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 Type (com.sun.tools.javac.code.Type)1 JCTree (com.sun.tools.javac.tree.JCTree)1 JCAnnotatedType (com.sun.tools.javac.tree.JCTree.JCAnnotatedType)1 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)1 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)1 JCTypeApply (com.sun.tools.javac.tree.JCTree.JCTypeApply)1 ArrayType (javax.lang.model.type.ArrayType)1 DeclaredType (javax.lang.model.type.DeclaredType)1