Search in sources :

Example 1 with Node

use of org.hibernate.hql.internal.ast.tree.Node in project hibernate-orm by hibernate.

the class HqlParserTest method testLineAndColumnNumber.

@Test
public void testLineAndColumnNumber() throws Exception {
    AST ast = doParse("from Foo f\nwhere f.name = 'fred'", false);
    // Find some of the nodes and check line and column values.
    ASTIterator iter = new ASTIterator(ast);
    boolean foundFoo = false;
    boolean foundName = false;
    while (iter.hasNext()) {
        AST n = iter.nextNode();
        if ("Foo".equals(n.getText())) {
            if (foundFoo)
                fail("Already found 'Foo'!");
            foundFoo = true;
            Node node = (Node) n;
            assertEquals(1, node.getLine());
            assertEquals(6, node.getColumn());
        } else if ("name".equals(n.getText())) {
            if (foundName)
                fail("Already found 'name'!");
            foundName = true;
            Node node = (Node) n;
            assertEquals(2, node.getLine());
            assertEquals(9, node.getColumn());
        }
    }
    assertTrue(foundFoo);
    assertTrue(foundName);
}
Also used : AST(antlr.collections.AST) Node(org.hibernate.hql.internal.ast.tree.Node) ASTIterator(org.hibernate.hql.internal.ast.util.ASTIterator) Test(org.junit.Test)

Aggregations

AST (antlr.collections.AST)1 Node (org.hibernate.hql.internal.ast.tree.Node)1 ASTIterator (org.hibernate.hql.internal.ast.util.ASTIterator)1 Test (org.junit.Test)1