ASTIteratorTest.java
1 |
import static com.goldencode.p2j.persist.orm.FQLParserTokenTypes.WHERE; |
---|---|
2 |
|
3 |
import java.io.StringReader; |
4 |
import java.util.Iterator; |
5 |
import java.util.logging.Level; |
6 |
|
7 |
import com.goldencode.ast.Aast; |
8 |
import com.goldencode.ast.AstWalkListener; |
9 |
import com.goldencode.p2j.persist.orm.FQLAst; |
10 |
import com.goldencode.p2j.persist.orm.FQLLexer; |
11 |
import com.goldencode.p2j.persist.orm.FQLParser; |
12 |
|
13 |
import antlr.RecognitionException; |
14 |
import antlr.TokenStreamException; |
15 |
|
16 |
public class ASTIteratorTest |
17 |
{ |
18 |
|
19 |
public static void main(String[] args) |
20 |
{ |
21 |
FQLParser parser = new FQLParser(new FQLLexer(new StringReader("select tt1.recid from tt1 where true"))); |
22 |
try
|
23 |
{ |
24 |
parser.statement(); |
25 |
} |
26 |
catch (RecognitionException | TokenStreamException e)
|
27 |
{ |
28 |
e.printStackTrace(); |
29 |
} |
30 |
|
31 |
AstWalkListener listener = new AstWalkListener()
|
32 |
{ |
33 |
@Override
|
34 |
public void nextChild(Aast ast, int index) { } |
35 |
|
36 |
@Override
|
37 |
public void descent(Aast ast) { } |
38 |
|
39 |
@Override
|
40 |
public void ascent(Aast ast) { } |
41 |
}; |
42 |
|
43 |
FQLAst root = (FQLAst) parser.getAST(); |
44 |
FQLAst where = (FQLAst) root.getImmediateChild(WHERE, null);
|
45 |
FQLAst child = (FQLAst) where.getFirstChild(); |
46 |
Iterator<Aast> iter = child.iterator(0, listener); |
47 |
while (iter.hasNext())
|
48 |
{ |
49 |
System.out.println(iter.next());
|
50 |
} |
51 |
} |
52 |
|
53 |
} |