TypeLiteralParser { static Parser<TypeLiteral> elementTypeLiteral() { Parser.Reference<TypeLiteral> ref = Parser.newReference(); Parser<TypeLiteral> lazy = ref.lazy(); Parser<TypeLiteral> arg = wildcard(lazy).or(lazy); Parser<String> nativeTypeName = TerminalParser.oneOf( "byte", "short", "int", "long", "boolean", "char", "float", "double", "void") .map(Object::toString); Parser<String> typeName = nativeTypeName.or(Terminals.Identifier.PARSER); Parser<TypeLiteral> parser = Parsers.sequence( typeName.sepBy1(term(".")), TypeLiteralParser.optionalTypeArgs(arg), SimpleTypeLiteral::new); ref.set(parser.postfix(ARRAY_OF)); return parser; }    }
@Test public void testElementTypeLiteral() { Parser<TypeLiteral> parser = TypeLiteralParser.ELEMENT_TYPE_LITERAL; TerminalParserTest.assertResult(parser, "int", SimpleTypeLiteral.class, "int"); TerminalParserTest.assertFailure(parser, "int[]", 1, 4); }