/** * Returns the last sibling of 'a'. * * @param a The sibling. * * @return The last sibling of 'a'. */ private static AST getLastSibling(AST a) { AST last = null; while ( a != null ) { last = a; a = a.getNextSibling(); } return last; }
public static void appendSibling(AST n, AST s) { while ( n.getNextSibling() != null ) { n = n.getNextSibling(); } n.setNextSibling( s ); }
public Node getHighOperand() { return (Node) getFirstChild().getNextSibling().getNextSibling(); }
/** * Retrieves the right-hand operand of the operator. * * @return The right-hand operand */ public Node getRightHandOperand() { return (Node) getFirstChild().getNextSibling(); }
@Override protected AST getFirstSelectExpression() { // Collect the select expressions, skip the first child because it is the class name. return getFirstChild().getNextSibling(); }
/** * Retrieves the right-hand operand of the operator. * * @return The right-hand operand */ @Override public Node getRightHandOperand() { return (Node) getFirstChild().getNextSibling(); }
protected void separator(AST n, String sep) { if (n.getNextSibling() != null) out(sep); }
public final void sortKey(AST _t) throws RecognitionException { AST sortKey_AST_in = (_t == ASTNULL) ? null : (AST)_t; try { // for error handling AST tmp4_AST_in = (AST)_t; match(_t,IDENT); _t = _t.getNextSibling(); } catch (RecognitionException ex) { reportError(ex); if (_t!=null) {_t = _t.getNextSibling();} } _retTree = _t; }
public Node getLowOperand() { return (Node) getFirstChild().getNextSibling(); }
private String toPathText(AST node) { final String text = node.getText(); if ( text.equals( "." ) && node.getFirstChild() != null && node.getFirstChild().getNextSibling() != null && node.getFirstChild().getNextSibling().getNextSibling() == null ) { return toPathText( node.getFirstChild() ) + '.' + toPathText( node.getFirstChild().getNextSibling() ); } return text; }
private static void getPathText(StringBuilder buf, AST n) { AST firstChild = n.getFirstChild(); // If the node has a first child, recurse into the first child. if ( firstChild != null ) { getPathText( buf, firstChild ); } // Append the text of the current node. buf.append( n.getText() ); // If there is a second child (RHS), recurse into that child. if ( firstChild != null && firstChild.getNextSibling() != null ) { getPathText( buf, firstChild.getNextSibling() ); } }
public Type getFirstArgumentType() { AST argument = getFirstChild(); while ( argument != null ) { if ( argument instanceof SqlNode ) { final Type type = ( (SqlNode) argument ).getDataType(); if ( type != null ) { return type; } argument = argument.getNextSibling(); } } return null; }
/** * 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 static boolean hasExactlyOneChild(AST n) { return n != null && n.getFirstChild() != null && n.getFirstChild().getNextSibling() == null; }
@Override public Type getFirstArgumentType() { AST argument = getFirstChild(); while ( argument != null ) { if ( argument instanceof SqlNode ) { final Type type = ( (SqlNode) argument ).getDataType(); if ( type != null ) { return type; } argument = argument.getNextSibling(); } } return null; }
@Override protected AST getFirstSelectExpression() { AST n = getFirstChild(); // Skip 'DISTINCT' and 'ALL', so we return the first expression node. while ( n != null && ( n.getType() == SqlTokenTypes.DISTINCT || n.getType() == SqlTokenTypes.ALL ) ) { n = n.getNextSibling(); } return n; }
public Type findFunctionReturnType(String functionName, SQLFunction sqlFunction, AST firstArgument) { // determine the type of the first argument... Type argumentType = null; if ( firstArgument != null ) { if ( "cast".equals( functionName ) ) { argumentType = sfi.getTypeResolver().heuristicType( firstArgument.getNextSibling().getText() ); } else if ( SqlNode.class.isInstance( firstArgument ) ) { argumentType = ( (SqlNode) firstArgument ).getDataType(); } } return sqlFunction.getReturnType( argumentType, sfi ); }
/** * 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()); }
@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()); } }
private void setPropertyNameAndPath(AST parent) { if ( isDotNode( parent ) ) { DotNode dotNode = (DotNode) parent; AST lhs = dotNode.getFirstChild(); AST rhs = lhs.getNextSibling(); propertyName = rhs.getText(); propertyPath = propertyPath + "." + propertyName; // Append the new property name onto the unresolved path. dotNode.propertyPath = propertyPath; LOG.debugf( "Unresolved property path is now '%s'", dotNode.propertyPath ); } else { LOG.debugf( "Terminal getPropertyPath = [%s]", propertyPath ); } }