@Test public void test_foo2() throws IOException { CharStream cs = CharStreams.fromFileName("src/test/resources/test_ternary.sol"); SolidityParsingPhase parser = new SolidityParsingPhase(); SourceUnitContext suc = parser.parse(cs); assertThat(suc).isNotNull(); ContractDefinitionContext cdc = suc.contractDefinition().get(0); assertThat(cdc).isNotNull(); List<ContractPartContext> cpList = cdc.contractPart(); assertThat(cpList).isNotEmpty(); FunctionDefinitionContext functionCtx = cpList.get(0).functionDefinition(); assertThat(functionCtx).isNotNull(); assertThat(functionCtx.modifierList()).isNotNull(); List<StatementContext> stmtCtx = functionCtx.block().statement(); ReturnStatementContext retStmt = stmtCtx.get(0).returnStatement(); assertThat(retStmt).isNotNull(); ExpressionContext expr = retStmt.expression(); assertThat(expr).isNotNull(); }
public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); SourceUnitContext parse(String fileContents); SourceUnitContext parse(CharStream cs); void addCommentsToSet(List<? extends Token> tokens); Integer getEmptyLines(); void setEmptyLines(Integer emptyLines); Integer getLinesOfComments(); TokenStream getTokens(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); SourceUnitContext parse(String fileContents); SourceUnitContext parse(CharStream cs); void addCommentsToSet(List<? extends Token> tokens); Integer getEmptyLines(); void setEmptyLines(Integer emptyLines); Integer getLinesOfComments(); TokenStream getTokens(); final Set<Token> comments; }