@Test public void should_skip_nodes() { char[] input = "foo".toCharArray(); MutableParsingRule ruleMatcher1 = mockRuleMatcher("rule1"); when(ruleMatcher1.hasToBeSkippedFromAst(Mockito.any(AstNode.class))).thenReturn(true); MutableParsingRule ruleMatcher2 = mockRuleMatcher("rule2"); AstNodeType realAstNodeType = mock(AstNodeType.class); when(ruleMatcher2.getRealAstNodeType()).thenReturn(realAstNodeType); ParseNode node = new ParseNode(0, 3, Collections.<ParseNode>emptyList(), ruleMatcher1); ParseNode parseTreeRoot = new ParseNode(0, 3, ImmutableList.of(node), ruleMatcher2); InputBuffer inputBuffer = new ImmutableInputBuffer(input); ParsingResult parsingResult = new ParsingResult(inputBuffer, true, parseTreeRoot, null); AstNode astNode = AstCreator.create(parsingResult, new LocatedText(null, input)); System.out.println(AstXmlPrinter.print(astNode)); assertThat(astNode.getType()).isSameAs(realAstNodeType); assertThat(astNode.getName()).isEqualTo("rule2"); assertThat(astNode.getFromIndex()).isEqualTo(0); assertThat(astNode.getToIndex()).isEqualTo(3); assertThat(astNode.hasChildren()).isFalse(); assertThat(astNode.getToken()).isNull(); }
public static AstNode create(ParsingResult parsingResult, LocatedText input) { AstNode astNode = new AstCreator(input).visit(parsingResult.getParseTreeRoot()); astNode.hasToBeSkippedFromAst(); return astNode; }
AstCreator { public static AstNode create(ParsingResult parsingResult, LocatedText input) { AstNode astNode = new AstCreator(input).visit(parsingResult.getParseTreeRoot()); astNode.hasToBeSkippedFromAst(); return astNode; } }
AstCreator { public static AstNode create(ParsingResult parsingResult, LocatedText input) { AstNode astNode = new AstCreator(input).visit(parsingResult.getParseTreeRoot()); astNode.hasToBeSkippedFromAst(); return astNode; } private  AstCreator(LocatedText input); }
AstCreator { public static AstNode create(ParsingResult parsingResult, LocatedText input) { AstNode astNode = new AstCreator(input).visit(parsingResult.getParseTreeRoot()); astNode.hasToBeSkippedFromAst(); return astNode; } private  AstCreator(LocatedText input); static AstNode create(ParsingResult parsingResult, LocatedText input); }
AstCreator { public static AstNode create(ParsingResult parsingResult, LocatedText input) { AstNode astNode = new AstCreator(input).visit(parsingResult.getParseTreeRoot()); astNode.hasToBeSkippedFromAst(); return astNode; } private  AstCreator(LocatedText input); static AstNode create(ParsingResult parsingResult, LocatedText input);  }