DeclarationParser { static Parser<Declaration> classDef(Parser<Modifier> mod, Parser<Member> member) { return Parsers.sequence( mod.many(), term("class").next(Terminals.Identifier.PARSER), TYPE_PARAMETERS.optional(), term("extends").next(TypeLiteralParser.ELEMENT_TYPE_LITERAL).optional(), term("implements").next(TypeLiteralParser.ELEMENT_TYPE_LITERAL.sepBy1(term(","))).optional(), body(member), ClassDef::new); }  static Parser<Program> program(); static Program parse(String source); static Program parse(URL url);  }
@Test public void testClassDef() { Parser<Declaration> parser = DeclarationParser.classDef(StatementParser.SYSTEM_MODIFIER, FIELD); TerminalParserTest.assertResult(parser, "public final class Foo {}", ClassDef.class, "public final class Foo {}"); TerminalParserTest.assertResult(parser, "final class Foo<T> {}", ClassDef.class, "final class Foo<T> {}"); TerminalParserTest.assertResult(parser, "final class Foo<T extends Foo<T>, K> {}", ClassDef.class, "final class Foo<T extends Foo<T>, K> {}"); TerminalParserTest.assertResult(parser, "final class Foo<T extends Foo<T>> extends ArrayList<?> {}", ClassDef.class, "final class Foo<T extends Foo<T>> extends ArrayList<?> {}"); TerminalParserTest.assertResult(parser, "final class Foo<T extends Foo<T>> implements List<?> {}", ClassDef.class, "final class Foo<T extends Foo<T>> implements List<?> {}"); TerminalParserTest.assertResult(parser, "final class Foo<T extends Foo<T>> implements List<?>, Iterable<T> {}", ClassDef.class, "final class Foo<T extends Foo<T>> implements List<?>, Iterable<T> {}"); TerminalParserTest.assertResult(parser, "final class Foo<T extends Foo<T>> {public static final String S = foo;}", ClassDef.class, "final class Foo<T extends Foo<T>> {public static final String S = foo;}"); TerminalParserTest.assertResult(parser, "final class Foo<T extends Foo<T>> {int i; int j;}", ClassDef.class, "final class Foo<T extends Foo<T>> {int i; int j;}"); }