use of org.hibernate.hql.internal.ast.HqlParser in project hibernate-orm by hibernate.
the class ASTIteratorTest method testSimpleTree.
@Test
public void testSimpleTree() throws Exception {
String input = "select foo from foo in class org.hibernate.test.Foo, fee in class org.hibernate.test.Fee where foo.dependent = fee order by foo.string desc, foo.component.count asc, fee.id";
HqlParser parser = HqlParser.getInstance(input);
parser.statement();
AST ast = parser.getAST();
ASTPrinter printer = new ASTPrinter(HqlTokenTypes.class);
printer.showAst(ast, new PrintWriter(System.out));
ASTIterator iterator = new ASTIterator(ast);
int count = 0;
while (iterator.hasNext()) {
assertTrue(iterator.next() instanceof AST);
count++;
}
assertEquals(43, count);
UnsupportedOperationException uoe = null;
try {
iterator.remove();
} catch (UnsupportedOperationException e) {
uoe = e;
}
assertNotNull(uoe);
}
use of org.hibernate.hql.internal.ast.HqlParser in project hibernate-orm by hibernate.
the class EJBQLTest method parse.
private AST parse(String input, boolean logging) throws RecognitionException, TokenStreamException {
if (logging) {
System.out.println("input: ->" + input + "<-");
}
HqlParser parser = HqlParser.getInstance(input);
parser.setFilter(false);
parser.statement();
AST ast = parser.getAST();
if (logging) {
System.out.println("AST : " + ast.toStringTree() + "");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
parser.showAst(ast, new PrintStream(baos));
System.out.println(baos.toString());
}
assertEquals("At least one error occurred during parsing!", 0, parser.getParseErrorHandler().getErrorCount());
return ast;
}
use of org.hibernate.hql.internal.ast.HqlParser in project hibernate-orm by hibernate.
the class HqlParserTest method testNoFrom.
@Test
public void testNoFrom() throws Exception {
System.out.println("***** This test ensures that an error is detected ERROR MESSAGES ARE OKAY! *****");
HqlParser parser = HqlParser.getInstance("");
parser.setFilter(false);
parser.statement();
assertEquals("Parser allowed no FROM clause!", 1, parser.getParseErrorHandler().getErrorCount());
System.out.println("***** END OF ERROR TEST *****");
}
use of org.hibernate.hql.internal.ast.HqlParser in project hibernate-orm by hibernate.
the class HqlParserTest method doParse.
private AST doParse(String input, boolean filter) throws RecognitionException, TokenStreamException {
System.out.println("input: ->" + ASTPrinter.escapeMultibyteChars(input) + "<-");
HqlParser parser = HqlParser.getInstance(input);
parser.setFilter(filter);
parser.statement();
AST ast = parser.getAST();
System.out.println("AST : " + ast.toStringTree() + "");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
parser.showAst(ast, new PrintStream(baos));
System.out.println(baos.toString());
assertEquals("At least one error occurred during parsing!", 0, parser.getParseErrorHandler().getErrorCount());
return ast;
}
use of org.hibernate.hql.internal.ast.HqlParser in project querydsl by querydsl.
the class QueryHelper method parse.
public void parse() throws RecognitionException, TokenStreamException {
String input = toString();
logger.fine("input: " + input.replace('\n', ' '));
HqlParser parser = HqlParser.getInstance(input);
parser.setFilter(false);
parser.statement();
AST ast = parser.getAST();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
parser.showAst(ast, new PrintStream(baos));
assertEquals("At least one error occurred during parsing " + input, 0, parser.getParseErrorHandler().getErrorCount());
}
Aggregations