private static boolean isDotNode(AST n) { return n != null && n.getType() == SqlTokenTypes.DOT; }
public void processNumeric(AST literal) { if ( literal.getType() == NUM_INT || literal.getType() == NUM_LONG || literal.getType() == NUM_BIG_INTEGER ) { literal.setText( determineIntegerRepresentation( literal.getText(), literal.getType() ) ); } else if ( literal.getType() == NUM_FLOAT || literal.getType() == NUM_DOUBLE || literal.getType() == NUM_BIG_DECIMAL ) { literal.setText( determineDecimalRepresentation( literal.getText(), literal.getType() ) ); } else { LOG.unexpectedLiteralTokenType( literal.getType() ); } }
@Override protected boolean isOrderExpressionResultVariableRef(AST orderExpressionNode) throws SemanticException { // ORDER BY is not supported in a subquery // TODO: should an exception be thrown if an ORDER BY is in a subquery? if ( !isSubQuery() && orderExpressionNode.getType() == IDENT && selectExpressionsByResultVariable.containsKey( orderExpressionNode.getText() ) ) { return true; } return false; }
@Override public void visitToken(DetailAST ast) { // no need to check for nulls here, == and != always have two children final AST firstChild = ast.getFirstChild(); final AST secondChild = firstChild.getNextSibling(); if (firstChild.getType() == TokenTypes.STRING_LITERAL || secondChild.getType() == TokenTypes.STRING_LITERAL) { log(ast, MSG_KEY, ast.getText()); } }
/** * Locate the specified <tt>collation specification</tt>, if one. * * @return The <tt>collation specification</tt>, or null if none was specified. */ public CollationSpecification getCollation() { AST possible = getSortKey().getNextSibling(); return possible != null && OrderByTemplateTokenTypes.COLLATE == possible.getType() ? ( CollationSpecification ) possible : null; }
private String buildTraceNodeName(AST tree) { return tree == null ? "???" : tree.getText() + " [" + TokenPrinters.SQL_TOKEN_PRINTER.getTokenTypeName( tree.getType() ) + "]"; }
private String buildTraceNodeName(AST tree) { return tree == null ? "???" : tree.getText() + " [" + TokenPrinters.ORDERBY_FRAGMENT_PRINTER.getTokenTypeName( tree.getType() ) + "]"; }
private String buildTraceNodeName(AST tree) { return tree == null ? "???" : tree.getText() + " [" + TokenPrinters.SQL_TOKEN_PRINTER.getTokenTypeName( tree.getType() ) + "]"; }
/** * Returns the number of direct child tokens that have the specified type. * @param type the token type to match * @return the number of matching token */ public int getChildCount(int type) { int count = 0; for (AST ast = getFirstChild(); ast != null; ast = ast.getNextSibling()) { if (ast.getType() == type) { count++; } } return count; }
public boolean isDistinct() { return getFirstChild() != null && getFirstChild().getType() == SqlTokenTypes.DISTINCT; }
/** * Finds the first node of the specified type in the chain of children. * * @param parent The parent * @param type The type to find. * * @return The first node of the specified type, or null if not found. */ public static AST findTypeInChildren(AST parent, int type) { AST n = parent.getFirstChild(); while ( n != null && n.getType() != type ) { n = n.getNextSibling(); } return n; }
@Override public void visit(AST node) { if ( dotRoot != null ) { // we are already processing a dot-structure if ( ASTUtil.isSubtreeChild( dotRoot, node ) ) { return; } // we are now at a new tree level dotRoot = null; } if ( node.getType() == HqlTokenTypes.DOT ) { dotRoot = node; handleDotStructure( dotRoot ); } } private void handleDotStructure(AST dotStructureRoot) {
private EntityPersister resolveEntityJoinReferencedPersister(AST path) { if ( path.getType() == IDENT ) { final IdentNode pathIdentNode = (IdentNode) path; String name = path.getText(); if ( name == null ) { name = pathIdentNode.getOriginalText(); } return sessionFactoryHelper.findEntityPersisterByName( name ); } else if ( path.getType() == DOT ) { final String pathText = ASTUtil.getPathText( path ); return sessionFactoryHelper.findEntityPersisterByName( pathText ); } return null; }
/** * Is same name of method. * @param ast method AST * @return true if method name is the same */ private boolean isSameNameMethod(DetailAST ast) { AST sibling = ast.getNextSibling(); // ignore type parameters if (sibling != null && sibling.getType() == TokenTypes.TYPE_ARGUMENTS) { sibling = sibling.getNextSibling(); } return sibling == null || !getMethodName().equals(sibling.getText()); }
private void setImpliedJoin(FromElement elem) { this.impliedJoin = elem; if ( getFirstChild().getType() == SqlTokenTypes.DOT ) { DotNode dotLhs = (DotNode) getFirstChild(); if ( dotLhs.getImpliedJoin() != null ) { this.impliedJoin = dotLhs.getImpliedJoin(); } } }
@Test public void testChild() { final Object child = new ParseTreeTablePresentation(null).getChild(tree, 1); Assert.assertTrue("Invalid child type", child instanceof DetailAST); Assert.assertEquals("Invalid child token type", TokenTypes.BLOCK_COMMENT_BEGIN, ((AST) child).getType()); }
@Test public void testChildInJavaAndJavadocMode() { final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null); parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS); final Object child = parseTree.getChild(tree, 1); Assert.assertTrue("Invalid child type", child instanceof DetailAST); Assert.assertEquals("Invalid child token type", TokenTypes.BLOCK_COMMENT_BEGIN, ((AST) child).getType()); }
@Test public void testCreate() throws Exception { AST n = ASTUtil.create( factory, 1, "one"); assertNull( n.getFirstChild() ); assertEquals( "one", n.getText() ); assertEquals( 1, n.getType() ); }