Search in sources :

Example 1 with UnionType

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

the class Java7ValidatorTest method multiCatchWithoutElements.

@Test
public void multiCatchWithoutElements() {
    UnionType unionType = new UnionType();
    List<Problem> problems = new ArrayList<>();
    new Java7Validator().accept(unionType, new ProblemReporter(problems::add));
    assertProblems(problems, "UnionType.elements can not be empty.");
}
Also used : UnionType(com.github.javaparser.ast.type.UnionType) Problem(com.github.javaparser.Problem) Test(org.junit.Test)

Example 2 with UnionType

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

the class Java7ValidatorTest method multiCatchWithOneElement.

@Test
public void multiCatchWithOneElement() {
    UnionType unionType = new UnionType();
    unionType.getElements().add(new ClassOrInterfaceType());
    List<Problem> problems = new ArrayList<>();
    new Java7Validator().accept(unionType, new ProblemReporter(problems::add));
    assertProblems(problems, "Union type (multi catch) must have at least two elements.");
}
Also used : UnionType(com.github.javaparser.ast.type.UnionType) Problem(com.github.javaparser.Problem) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Test(org.junit.Test)

Example 3 with UnionType

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

the class LexicalPreservingPrinterTest method printUnionType.

@Test
public void printUnionType() {
    String code = "class A {{try { doit(); } catch (Exception | AssertionError e) {}}}";
    considerCode(code);
    InitializerDeclaration initializerDeclaration = (InitializerDeclaration) cu.getType(0).getMembers().get(0);
    TryStmt tryStmt = (TryStmt) initializerDeclaration.getBody().getStatements().get(0);
    CatchClause catchClause = tryStmt.getCatchClauses().get(0);
    UnionType unionType = (UnionType) catchClause.getParameter().getType();
    assertEquals("Exception | AssertionError", LexicalPreservingPrinter.print(unionType));
}
Also used : UnionType(com.github.javaparser.ast.type.UnionType) Test(org.junit.Test)

Aggregations

UnionType (com.github.javaparser.ast.type.UnionType)3 Test (org.junit.Test)3 Problem (com.github.javaparser.Problem)2 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)1