Java Code Examples for antlr.collections.AST#setType()

The following examples show how to use antlr.collections.AST#setType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FromElementFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private AST createFromElement(String text) {
	AST ast = ASTUtil.create(
			fromClause.getASTFactory(),
			implied ? IMPLIED_FROM : FROM_FRAGMENT, // This causes the factory to instantiate the desired class.
			text
	);
	// Reset the node type, because the rest of the system is expecting FROM_FRAGMENT, all we wanted was
	// for the factory to create the right sub-class.  This might get reset again later on anyway to make the
	// SQL generation simpler.
	ast.setType( FROM_FRAGMENT );
	return ast;
}
 
Example 2
Source File: MethodNode.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void initializeMethodNode(AST name, boolean inSelect) {
	name.setType( SqlTokenTypes.METHOD_NAME );
	String text = name.getText();
	// Use the lower case function name.
	methodName = text.toLowerCase(Locale.ROOT);
	// Remember whether we're in a SELECT clause or not.
	this.inSelect = inSelect;
}
 
Example 3
Source File: QueryTranslatorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void handleDotStructure(AST dotStructureRoot) {
	final String expression = ASTUtil.getPathText( dotStructureRoot );
	final Object constant = ReflectHelper.getConstantValue( expression, factory );
	if ( constant != null ) {
		dotStructureRoot.setFirstChild( null );
		dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT );
		dotStructureRoot.setText( expression );
	}
}
 
Example 4
Source File: FromElementFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private AST createFromElement(String text) {
	AST ast = ASTUtil.create( fromClause.getASTFactory(),
			implied ? IMPLIED_FROM : FROM_FRAGMENT, // This causes the factory to instantiate the desired class.
			text );
	// Reset the node type, because the rest of the system is expecting FROM_FRAGMENT, all we wanted was
	// for the factory to create the right sub-class.  This might get reset again later on anyway to make the
	// SQL generation simpler.
	ast.setType( FROM_FRAGMENT );
	return ast;
}
 
Example 5
Source File: QueryTranslatorImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void handleDotStructure(AST dotStructureRoot) {
	String expression = ASTUtil.getPathText( dotStructureRoot );
	Object constant = ReflectHelper.getConstantValue( expression );
	if ( constant != null ) {
		dotStructureRoot.setFirstChild( null );
		dotStructureRoot.setType( HqlTokenTypes.JAVA_CONSTANT );
		dotStructureRoot.setText( expression );
	}
}
 
Example 6
Source File: MethodNode.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void initializeMethodNode(AST name, boolean inSelect) {
	name.setType( SqlTokenTypes.METHOD_NAME );
	String text = name.getText();
	methodName = text.toLowerCase();	// Use the lower case function name.
	this.inSelect = inSelect;			// Remember whether we're in a SELECT clause or not.
}
 
Example 7
Source File: HqlParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
	 * Returns an equivalent tree for (NOT (a relop b) ), for example:<pre>
	 * (NOT (GT a b) ) => (LE a b)
	 * </pre>
	 *
	 * @param x The sub tree to transform, the parent is assumed to be NOT.
	 * @return AST - The equivalent sub-tree.
	 */
	public AST negateNode(AST x) {
		//TODO: switch statements are always evil! We already had bugs because 
		//      of forgotten token types. Use polymorphism for this!
		switch ( x.getType() ) {
			case OR:
				x.setType(AND);
				x.setText("{and}");
				negateNode( x.getFirstChild() );
				negateNode( x.getFirstChild().getNextSibling() );
				return x;
			case AND:
				x.setType(OR);
				x.setText("{or}");
				negateNode( x.getFirstChild() );
				negateNode( x.getFirstChild().getNextSibling() );
				return x;
			case EQ:
				x.setType( NE );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (EQ a b) ) => (NE a b)
			case NE:
				x.setType( EQ );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (NE a b) ) => (EQ a b)
			case GT:
				x.setType( LE );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (GT a b) ) => (LE a b)
			case LT:
				x.setType( GE );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (LT a b) ) => (GE a b)
			case GE:
				x.setType( LT );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (GE a b) ) => (LT a b)
			case LE:
				x.setType( GT );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (LE a b) ) => (GT a b)
			case LIKE:
				x.setType( NOT_LIKE );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (LIKE a b) ) => (NOT_LIKE a b)
			case NOT_LIKE:
				x.setType( LIKE );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (NOT_LIKE a b) ) => (LIKE a b)
			case IN:
				x.setType( NOT_IN );
				x.setText( "{not}" + x.getText() );
				return x;
			case NOT_IN:
				x.setType( IN );
				x.setText( "{not}" + x.getText() );
				return x;
			case IS_NULL:
				x.setType( IS_NOT_NULL );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (IS_NULL a b) ) => (IS_NOT_NULL a b)
			case IS_NOT_NULL:
				x.setType( IS_NULL );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (IS_NOT_NULL a b) ) => (IS_NULL a b)
			case BETWEEN:
				x.setType( NOT_BETWEEN );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (BETWEEN a b) ) => (NOT_BETWEEN a b)
			case NOT_BETWEEN:
				x.setType( BETWEEN );
				x.setText( "{not}" + x.getText() );
				return x;	// (NOT (NOT_BETWEEN a b) ) => (BETWEEN a b)
/* This can never happen because this rule will always eliminate the child NOT.
			case NOT:
				return x.getFirstChild();			// (NOT (NOT x) ) => (x)
*/
			default:
				return super.negateNode( x );		// Just add a 'not' parent.
		}
	}