/** * Renders string from a parse tree result. * * @param tree * {@link ParserRuleContext} to render * @return String representation of tree. */ public String toStringTree(ParserRuleContext tree) { return tree.toStringTree(this.parser); }
@Override public void enterEveryRule(ParserRuleContext ctx) { if (log.isTraceEnabled()) { log.trace("{} entered with {}", ctx.getClass().getName(), ctx.toStringTree()); } }
@Override public void exitEveryRule(ParserRuleContext ctx) { if (log.isTraceEnabled()) { log.trace("{} exited with {}", ctx.getClass().getName(), ctx.toStringTree()); } }
@Override public void enterEveryRule(ParserRuleContext ctx) { if (log.isTraceEnabled()) { log.trace("{} entered with {}", ctx.getClass().getName(), ctx.toStringTree()); } }
@Override public void exitEveryRule(ParserRuleContext ctx) { if (log.isTraceEnabled()) { log.trace("{} exited with {}", ctx.getClass().getName(), ctx.toStringTree()); } }
private Expression createExpression(RuleInvoker ruleInvoker, String expression, boolean allowCaseWhen, boolean allowQuantifiedPredicates, boolean allowTreatJoinExtension, MacroConfiguration macroConfiguration, Set<String> usedMacros) { if (expression == null) { throw new NullPointerException("expression"); } if (expression.isEmpty()) { throw new IllegalArgumentException("expression"); } JPQLSelectExpressionLexer l = new JPQLSelectExpressionLexer(new ANTLRInputStream(expression)); configureLexer(l); CommonTokenStream tokens = new CommonTokenStream(l); JPQLSelectExpressionParser p = new JPQLSelectExpressionParser(tokens, allowCaseWhen, allowQuantifiedPredicates, allowTreatJoinExtension); configureParser(p); ParserRuleContext ctx; try { ctx = ruleInvoker.invokeRule(p); } catch (SyntaxErrorException ex) { throw new SyntaxErrorException("Could not parse expression '" + expression + "', " + ex.getMessage(), ex); } if (LOG.isLoggable(Level.FINEST)) { LOG.finest(ctx.toStringTree()); } JPQLSelectExpressionVisitorImpl visitor = new JPQLSelectExpressionVisitorImpl(aggregateFunctions, enumTypes, entityTypes, minEnumSegmentCount, minEntitySegmentCount, macroConfiguration == null ? Collections.EMPTY_MAP : macroConfiguration.macros, usedMacros); Expression parsedExpression = visitor.visit(ctx); if (optimize) { parsedExpression = parsedExpression.accept(optimizer); } return parsedExpression; }
private Expression createExpression(RuleInvoker ruleInvoker, String expression, boolean allowCaseWhen, boolean allowQuantifiedPredicates, boolean allowTreatJoinExtension, MacroConfiguration macroConfiguration, Set<String> usedMacros) { if (expression == null) { throw new NullPointerException("expression"); } if (expression.isEmpty()) { throw new IllegalArgumentException("expression"); } JPQLSelectExpressionLexer l = new JPQLSelectExpressionLexer(new ANTLRInputStream(expression)); configureLexer(l); CommonTokenStream tokens = new CommonTokenStream(l); JPQLSelectExpressionParser p = new JPQLSelectExpressionParser(tokens, allowCaseWhen, allowQuantifiedPredicates, allowTreatJoinExtension); configureParser(p); ParserRuleContext ctx; try { ctx = ruleInvoker.invokeRule(p); } catch (SyntaxErrorException ex) { throw new SyntaxErrorException("Could not parse expression '" + expression + "', " + ex.getMessage(), ex); } if (LOG.isLoggable(Level.FINEST)) { LOG.finest(ctx.toStringTree()); } JPQLSelectExpressionVisitorImpl visitor = new JPQLSelectExpressionVisitorImpl(aggregateFunctions, enumTypes, entityTypes, minEnumSegmentCount, minEntitySegmentCount, macroConfiguration == null ? Collections.EMPTY_MAP : macroConfiguration.macros, usedMacros); Expression parsedExpression = visitor.visit(ctx); if (optimize) { parsedExpression = parsedExpression.accept(optimizer); } return parsedExpression; }
System.out.println(tree.toStringTree(parser));
System.out.println(tree.toStringTree(parser));
System.out.println(tree.toStringTree(parser));
System.out.println(tree.toStringTree(parser));
System.out.println(tree.toStringTree(parser));