@Test public void testParser_annotations() throws IOException { copyResourceTo("/parser/tests/annotations.thrift", tmp.getRoot()); File annotations = new File(tmp.getRoot(), "annotations.thrift"); ThriftProgramParser parser = new ThriftProgramParser(); ProgramType program = parser.parse(new FileInputStream(annotations), annotations, new TreeSet<>()); assertThat(debugString(program), is("{\n" + " program_name = \"annotations\"\n" + " namespaces = {\n" + " \"java\": \"net.morimekta.test.annotations\"\n" + " }\n" + " decl = [\n" + " {\n" + " decl_enum = {\n" + " name = \"E\"\n" + " values = [\n" + " {\n" + " name = \"VAL\"\n" + " id = 0\n" + " annotations = {\n" + " \"anno\": \"str\"\n" + " \"anno.other\": \"other\"\n" + " }\n" + " start_pos = {\n" + " line_no = 4\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 4\n" + " line_pos = 45\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"e.anno\": \"E\"\n" + " }\n" + " start_pos = {\n" + " line_no = 3\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 5\n" + " line_pos = 17\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_message = {\n" + " variant = EXCEPTION\n" + " name = \"S\"\n" + " fields = [\n" + " {\n" + " id = 1\n" + " type = \"bool\"\n" + " name = \"val\"\n" + " annotations = {\n" + " \"anno\": \"str\"\n" + " }\n" + " start_pos = {\n" + " line_no = 8\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 8\n" + " line_pos = 31\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"other\": \"\"\n" + " }\n" + " start_pos = {\n" + " line_no = 7\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 9\n" + " line_pos = 10\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_service = {\n" + " name = \"Srv\"\n" + " methods = [\n" + " {\n" + " name = \"method\"\n" + " params = [\n" + " {\n" + " id = 1\n" + " type = \"i32\"\n" + " name = \"param\"\n" + " annotations = {\n" + " \"abba\": \"7\"\n" + " }\n" + " start_pos = {\n" + " line_no = 12\n" + " line_pos = 17\n" + " }\n" + " end_pos = {\n" + " line_no = 12\n" + " line_pos = 42\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"anno\": \"anno\"\n" + " }\n" + " start_pos = {\n" + " line_no = 12\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 12\n" + " line_pos = 59\n" + " }\n" + " },\n" + " {\n" + " name = \"method2\"\n" + " params = [\n" + " {\n" + " id = 1\n" + " type = \"i32\"\n" + " name = \"param\"\n" + " annotations = {\n" + " \"abba\": \"7\"\n" + " }\n" + " start_pos = {\n" + " line_no = 13\n" + " line_pos = 18\n" + " }\n" + " end_pos = {\n" + " line_no = 13\n" + " line_pos = 43\n" + " }\n" + " }\n" + " ]\n" + " exceptions = [\n" + " {\n" + " id = 1\n" + " type = \"S\"\n" + " name = \"e\"\n" + " annotations = {\n" + " \"ex\": \"667\"\n" + " }\n" + " start_pos = {\n" + " line_no = 14\n" + " line_pos = 15\n" + " }\n" + " end_pos = {\n" + " line_no = 14\n" + " line_pos = 34\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"anno\": \"anno\"\n" + " }\n" + " start_pos = {\n" + " line_no = 13\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 15\n" + " line_pos = 22\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"bin\": \"bin\"\n" + " \"src\": \"src\"\n" + " }\n" + " start_pos = {\n" + " line_no = 11\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 16\n" + " line_pos = 29\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}")); }
@Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } ThriftProgramParser();  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue);  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue,
                               boolean allowLanguageReservedNames); }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } ThriftProgramParser();  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue);  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue,
                               boolean allowLanguageReservedNames); @Override ProgramType parse(InputStream in, File file, Collection<File> includeDirs); }
ThriftProgramParser implements ProgramParser { @Override public ProgramType parse(InputStream in, File file, Collection<File> includeDirs) throws IOException { try { return parseInternal(in, file, includeDirs); } catch (TokenizerException e) { if (e.getFile() == null) { e.setFile(file.getName()); } throw e; } } ThriftProgramParser();  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue);  ThriftProgramParser(boolean requireFieldId,
                               boolean requireEnumValue,
                               boolean allowLanguageReservedNames); @Override ProgramType parse(InputStream in, File file, Collection<File> includeDirs); static final Pattern VALID_NAMESPACE; static final Pattern VALID_SDI_NAMESPACE; }