Search in sources :

Example 1 with IntersectionType

use of com.github.javaparser.ast.type.IntersectionType in project javaparser by javaparser.

the class JavaParserTest method parseIntersectionType.

@Test
public void parseIntersectionType() {
    String code = "(Runnable & Serializable) (() -> {})";
    Expression expression = JavaParser.parseExpression(code);
    Type type = expression.asCastExpr().getType();
    assertTrue(type instanceof IntersectionType);
    IntersectionType intersectionType = type.asIntersectionType();
    assertEquals(2, intersectionType.getElements().size());
    assertTrue(intersectionType.getElements().get(0) instanceof ClassOrInterfaceType);
    assertEquals("Runnable", intersectionType.getElements().get(0).asClassOrInterfaceType().getNameAsString());
    assertTrue(intersectionType.getElements().get(1) instanceof ClassOrInterfaceType);
    assertEquals("Serializable", intersectionType.getElements().get(1).asClassOrInterfaceType().getNameAsString());
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) IntersectionType(com.github.javaparser.ast.type.IntersectionType) Type(com.github.javaparser.ast.type.Type) IntersectionType(com.github.javaparser.ast.type.IntersectionType) Expression(com.github.javaparser.ast.expr.Expression) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Test(org.junit.Test)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)1 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1 IntersectionType (com.github.javaparser.ast.type.IntersectionType)1 Type (com.github.javaparser.ast.type.Type)1 Test (org.junit.Test)1