@Test public void testParse_calculator() throws IOException, ParseException { copyResourceTo("/parser/calculator/number.thrift", tmp.getRoot()); copyResourceTo("/parser/calculator/calculator.thrift", tmp.getRoot()); File calculator = new File(tmp.getRoot(), "calculator.thrift"); ThriftProgramParser parser = new ThriftProgramParser(); ProgramType program = parser.parse(new FileInputStream(calculator), calculator, new TreeSet<>()); assertEquals( "{\n" + " program_name = \"calculator\"\n" + " includes = [\n" + " \"number.thrift\"\n" + " ]\n" + " namespaces = {\n" + " \"java\": \"net.morimekta.test.calculator\"\n" + " }\n" + " decl = [\n" + " {\n" + " decl_enum = {\n" + " documentation = \"Block comment on type.\"\n" + " name = \"Operator\"\n" + " values = [\n" + " {\n" + " name = \"IDENTITY\"\n" + " id = 1\n" + " start_pos = {\n" + " line_no = 10\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 10\n" + " line_pos = 17\n" + " }\n" + " },\n" + " {\n" + " documentation = \"Block comment on enum.\"\n" + " name = \"ADD\"\n" + " id = 2\n" + " start_pos = {\n" + " line_no = 14\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 14\n" + " line_pos = 8\n" + " }\n" + " },\n" + " {\n" + " name = \"SUBTRACT\"\n" + " id = 3\n" + " start_pos = {\n" + " line_no = 15\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 15\n" + " line_pos = 13\n" + " }\n" + " },\n" + " {\n" + " name = \"MULTIPLY\"\n" + " id = 4\n" + " start_pos = {\n" + " line_no = 16\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 16\n" + " line_pos = 13\n" + " }\n" + " },\n" + " {\n" + " name = \"DIVIDE\"\n" + " id = 5\n" + " start_pos = {\n" + " line_no = 17\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 17\n" + " line_pos = 11\n" + " }\n" + " }\n" + " ]\n" + " start_pos = {\n" + " line_no = 8\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 18\n" + " line_pos = 2\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_message = {\n" + " variant = UNION\n" + " name = \"Operand\"\n" + " fields = [\n" + " {\n" + " id = 1\n" + " type = \"Operation\"\n" + " name = \"operation\"\n" + " start_pos = {\n" + " line_no = 24\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 24\n" + " line_pos = 27\n" + " }\n" + " },\n" + " {\n" + " documentation = \"Block comment\\n - with formatting.\\nOn field.\"\n" + " id = 2\n" + " type = \"double\"\n" + " name = \"number\"\n" + " start_pos = {\n" + " line_no = 30\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 30\n" + " line_pos = 21\n" + " }\n" + " },\n" + " {\n" + " id = 3\n" + " type = \"number.Imaginary\"\n" + " name = \"imaginary\"\n" + " start_pos = {\n" + " line_no = 31\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 31\n" + " line_pos = 34\n" + " }\n" + " }\n" + " ]\n" + " start_pos = {\n" + " line_no = 21\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 32\n" + " line_pos = 2\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_message = {\n" + " name = \"Operation\"\n" + " fields = [\n" + " {\n" + " id = 1\n" + " type = \"Operator\"\n" + " name = \"operator\"\n" + " start_pos = {\n" + " line_no = 35\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 35\n" + " line_pos = 25\n" + " }\n" + " },\n" + " {\n" + " id = 2\n" + " type = \"list<Operand>\"\n" + " name = \"operands\"\n" + " start_pos = {\n" + " line_no = 36\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 36\n" + " line_pos = 30\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"compact\": \"\"\n" + " }\n" + " start_pos = {\n" + " line_no = 34\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 37\n" + " line_pos = 17\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_message = {\n" + " variant = EXCEPTION\n" + " name = \"CalculateException\"\n" + " fields = [\n" + " {\n" + " id = 1\n" + " requirement = REQUIRED\n" + " type = \"string\"\n" + " name = \"message\"\n" + " start_pos = {\n" + " line_no = 40\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 40\n" + " line_pos = 31\n" + " }\n" + " },\n" + " {\n" + " id = 2\n" + " type = \"Operation\"\n" + " name = \"operation\"\n" + " start_pos = {\n" + " line_no = 41\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 41\n" + " line_pos = 27\n" + " }\n" + " }\n" + " ]\n" + " start_pos = {\n" + " line_no = 39\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 42\n" + " line_pos = 2\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_service = {\n" + " name = \"BaseCalculator\"\n" + " methods = [\n" + " {\n" + " one_way = true\n" + " name = \"iamalive\"\n" + " params = []\n" + " start_pos = {\n" + " line_no = 46\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 46\n" + " line_pos = 27\n" + " }\n" + " },\n" + " {\n" + " return_type = \"i32\"\n" + " name = \"numCalls\"\n" + " params = [\n" + " {\n" + " id = 1\n" + " requirement = REQUIRED\n" + " type = \"i32\"\n" + " name = \"minus\"\n" + " start_pos = {\n" + " line_no = 47\n" + " line_pos = 18\n" + " }\n" + " end_pos = {\n" + " line_no = 47\n" + " line_pos = 39\n" + " }\n" + " },\n" + " {\n" + " id = 2\n" + " requirement = OPTIONAL\n" + " type = \"i32\"\n" + " name = \"inAdditionTo\"\n" + " start_pos = {\n" + " line_no = 47\n" + " line_pos = 41\n" + " }\n" + " end_pos = {\n" + " line_no = 47\n" + " line_pos = 69\n" + " }\n" + " }\n" + " ]\n" + " start_pos = {\n" + " line_no = 47\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 47\n" + " line_pos = 70\n" + " }\n" + " }\n" + " ]\n" + " annotations = {\n" + " \"deprecated\": \"Because reasons\"\n" + " }\n" + " start_pos = {\n" + " line_no = 44\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 48\n" + " line_pos = 35\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_service = {\n" + " documentation = \"Block comment on service\"\n" + " name = \"Calculator\"\n" + " extend = \"BaseCalculator\"\n" + " methods = [\n" + " {\n" + " documentation = \"Block comment on method.\"\n" + " return_type = \"Operand\"\n" + " name = \"calculate\"\n" + " params = [\n" + " {\n" + " id = 1\n" + " type = \"Operation\"\n" + " name = \"op\"\n" + " start_pos = {\n" + " line_no = 57\n" + " line_pos = 23\n" + " }\n" + " end_pos = {\n" + " line_no = 57\n" + " line_pos = 38\n" + " }\n" + " }\n" + " ]\n" + " exceptions = [\n" + " {\n" + " id = 1\n" + " type = \"CalculateException\"\n" + " name = \"ce\"\n" + " start_pos = {\n" + " line_no = 57\n" + " line_pos = 48\n" + " }\n" + " end_pos = {\n" + " line_no = 57\n" + " line_pos = 72\n" + " }\n" + " }\n" + " ]\n" + " start_pos = {\n" + " line_no = 57\n" + " line_pos = 5\n" + " }\n" + " end_pos = {\n" + " line_no = 57\n" + " line_pos = 73\n" + " }\n" + " }\n" + " ]\n" + " start_pos = {\n" + " line_no = 53\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 58\n" + " line_pos = 1\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_const = {\n" + " documentation = \"Block comment on constant.\"\n" + " type = \"Operand\"\n" + " name = \"PI\"\n" + " value = \"{\\n \\\"number\\\": 3.141592\\n}\"\n" + " value_start_pos = {\n" + " line_no = 63\n" + " line_pos = 20\n" + " }\n" + " start_pos = {\n" + " line_no = 63\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 65\n" + " line_pos = 2\n" + " }\n" + " }\n" + " },\n" + " {\n" + " decl_const = {\n" + " type = \"set<Operator>\"\n" + " name = \"kComplexOperands\"\n" + " value = \"[\\n Operator.MULTIPLY,\\n Operator.DIVIDE\\n]\"\n" + " value_start_pos = {\n" + " line_no = 68\n" + " line_pos = 40\n" + " }\n" + " start_pos = {\n" + " line_no = 68\n" + " line_pos = 1\n" + " }\n" + " end_pos = {\n" + " line_no = 71\n" + " line_pos = 2\n" + " }\n" + " }\n" + " }\n" + " ]\n" + "}", debugString(program)); }
@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; }