Java Code Examples for antlr.collections.AST

The following examples show how to use antlr.collections.AST. These examples are extracted from open source projects. 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
public final void attrScope(AST _t) throws RecognitionException {
	
	GrammarAST attrScope_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		AST __t8 = _t;
		GrammarAST tmp12_AST_in = (GrammarAST)_t;
		match(_t,SCOPE);
		_t = _t.getFirstChild();
		GrammarAST tmp13_AST_in = (GrammarAST)_t;
		match(_t,ID);
		_t = _t.getNextSibling();
		GrammarAST tmp14_AST_in = (GrammarAST)_t;
		match(_t,ACTION);
		_t = _t.getNextSibling();
		_t = __t8;
		_t = _t.getNextSibling();
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 2
Source Project: cxf   Source File: StructVisitor.java    License: Apache License 2.0 6 votes vote down vote up
private XmlSchemaElement createXmlSchemaElement(AST memberNode,
                                                XmlSchemaType schemaType,
                                                Scope fqName) {
    // xmlschema:member
    XmlSchemaElement member = new XmlSchemaElement(schema, false);
    String memberName = memberNode.toString();
    member.setName(memberName);
    member.setSchemaType(schemaType);
    if (schemaType != null) {
        member.setSchemaTypeName(schemaType.getQName());
        if (schemaType.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
            member.setNillable(true);
        }
    } else {
        wsdlVisitor.getDeferredActions().
            add(fqName, new StructDeferredAction(member));
    }
    return member;
}
 
Example 3
Source Project: cxf   Source File: ConstrTypeSpecVisitor.java    License: Apache License 2.0 6 votes vote down vote up
public void visit(AST node) {
    // <constr_type_spec> ::= <struct_type>
    //                      | <union_type>
    //                      | <enum_type>

    Visitor visitor = null;

    if (StructVisitor.accept(node)) {
        visitor = new StructVisitor(getScope(), definition, schema, wsdlVisitor);
    }

    if (UnionVisitor.accept(node)) {
        visitor = new UnionVisitor(getScope(), definition, schema, wsdlVisitor);
    }

    if (EnumVisitor.accept(node)) {
        visitor = new EnumVisitor(getScope(), definition, schema, wsdlVisitor);
    }

    if (visitor != null) {
        visitor.visit(node);

        setSchemaType(visitor.getSchemaType());
        setCorbaType(visitor.getCorbaType());
    }
}
 
Example 4
public final void attrScope(AST _t) throws RecognitionException {
	
	GrammarAST attrScope_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		AST __t17 = _t;
		GrammarAST tmp13_AST_in = (GrammarAST)_t;
		match(_t,SCOPE);
		_t = _t.getFirstChild();
		GrammarAST tmp14_AST_in = (GrammarAST)_t;
		match(_t,ID);
		_t = _t.getNextSibling();
		GrammarAST tmp15_AST_in = (GrammarAST)_t;
		match(_t,ACTION);
		_t = _t.getNextSibling();
		_t = __t17;
		_t = _t.getNextSibling();
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 5
Source Project: lams   Source File: QueryNode.java    License: GNU General Public License v2.0 6 votes vote down vote up
public final OrderByClause getOrderByClause() {
	if ( orderByClause == null ) {
		orderByClause = locateOrderByClause();

		// if there is no order by, make one
		if ( orderByClause == null ) {
			LOG.debug( "getOrderByClause() : Creating a new ORDER BY clause" );
			orderByClause = (OrderByClause) getWalker().getASTFactory().create( SqlTokenTypes.ORDER, "ORDER" );

			// Find the WHERE; if there is no WHERE, find the FROM...
			AST prevSibling = ASTUtil.findTypeInChildren( this, SqlTokenTypes.WHERE );
			if ( prevSibling == null ) {
				prevSibling = ASTUtil.findTypeInChildren( this, SqlTokenTypes.FROM );
			}

			// Now, inject the newly built ORDER BY into the tree
			orderByClause.setNextSibling( prevSibling.getNextSibling() );
			prevSibling.setNextSibling( orderByClause );
		}
	}
	return orderByClause;
}
 
Example 6
Source Project: lams   Source File: HqlSqlWalker.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void validateMapPropertyExpression(AST node) throws SemanticException {
	try {
		FromReferenceNode fromReferenceNode = (FromReferenceNode) node;
		QueryableCollection collectionPersister = fromReferenceNode.getFromElement().getQueryableCollection();
		if ( !Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
			throw new SemanticException( "node did not reference a map" );
		}
	}
	catch (SemanticException se) {
		throw se;
	}
	catch (Throwable t) {
		throw new SemanticException( "node did not reference a map" );
	}
}
 
Example 7
Source Project: lams   Source File: HqlSqlWalker.java    License: GNU General Public License v2.0 6 votes vote down vote up
private EntityJoinFromElement createEntityJoin(
		EntityPersister entityPersister,
		AST aliasNode,
		int joinType,
		AST propertyFetch,
		AST with) throws SemanticException {
	final String alias = aliasNode == null ? null : aliasNode.getText();
	LOG.debugf( "Creating entity-join FromElement [%s -> %s]", alias, entityPersister.getEntityName() );
	EntityJoinFromElement join = new EntityJoinFromElement(
			this,
			getCurrentFromClause(),
			entityPersister,
			JoinProcessor.toHibernateJoinType( joinType ),
			propertyFetch != null,
			alias
	);

	if ( with != null ) {
		handleWithFragment( join, with );
	}

	return join;
}
 
Example 8
Source Project: lams   Source File: QueryTranslatorImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void generate(AST sqlAst) throws QueryException, RecognitionException {
	if ( sql == null ) {
		final SqlGenerator gen = new SqlGenerator( factory );
		gen.statement( sqlAst );
		sql = gen.getSQL();
		if ( LOG.isDebugEnabled() ) {
			LOG.debugf( "HQL: %s", hql );
			LOG.debugf( "SQL: %s", sql );
		}
		gen.getParseErrorHandler().throwQueryException();
		if ( collectedParameterSpecifications == null ) {
			collectedParameterSpecifications = gen.getCollectedParameters();
		}
		else {
			collectedParameterSpecifications.addAll( gen.getCollectedParameters() );
		}
	}
}
 
Example 9
Source Project: lams   Source File: QueryTranslatorImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
private HqlParser parse(boolean filter) throws TokenStreamException {
	// Parse the query string into an HQL AST.
	final HqlParser parser = HqlParser.getInstance( hql );
	parser.setFilter( filter );

	LOG.debugf( "parse() - HQL: %s", hql );
	try {
		parser.statement();
	}
	catch (RecognitionException e) {
		throw new HibernateException( "Unexpected error parsing HQL", e );
	}

	final AST hqlAst = parser.getAST();
	parser.getParseErrorHandler().throwQueryException();

	final NodeTraverser walker = new NodeTraverser( new JavaConstantConverter( factory ) );
	walker.traverseDepthFirst( hqlAst );

	showHqlAst( hqlAst );

	return parser;
}
 
Example 10
public AST nextNode() {
	current = next;
	if ( next != null ) {
		AST nextSibling = next.getNextSibling();
		if ( nextSibling == null ) {
			next = pop();
		}
		else {
			next = nextSibling;
			down();
		}
	}
	return current;
}
 
Example 11
Source Project: lams   Source File: OrderByFragmentParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AST quotedIdentifier(AST ident) {
	/*
	 * Semantic action used during recognition of quoted identifiers (quoted column names)
	 */
	final String columnName = context.getDialect().quote( '`' + ident.getText() + '`' );
	columnReferences.add( columnName );
	final String marker = '{' + columnName + '}';
	return getASTFactory().create( OrderByTemplateTokenTypes.IDENT, marker );
}
 
Example 12
Source Project: lams   Source File: OrderByFragmentParser.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AST quotedString(AST ident) {
	/*
	 * Semantic action used during recognition of quoted strings (string literals)
	 */
	return getASTFactory().create( OrderByTemplateTokenTypes.IDENT, context.getDialect().quote( ident.getText() ) );
}
 
Example 13
Source Project: cxf   Source File: TemplateTypeSpecVisitor.java    License: Apache License 2.0 5 votes vote down vote up
public void visit(AST node) {
    // <template_type_spec> ::= <sequence_type>
    //                        | <string_type>
    //                        | <wide_string_type>
    //                        | <fixed_pt_type>


    Visitor visitor = null;

    if (SequenceVisitor.accept(node)) {
        // <sequence_type>
        visitor = new SequenceVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
    } else if (StringVisitor.accept(node)) {
        // <string_type>
        // <wstring_type>
        visitor = new StringVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
    } else if (FixedVisitor.accept(node)) {
        // <fixed_pt_type>
        visitor = new FixedVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
    }

    if (visitor != null) {
        visitor.visit(node);

        setSchemaType(visitor.getSchemaType());
        setCorbaType(visitor.getCorbaType());
        setFullyQualifiedName(visitor.getFullyQualifiedName());
    }
}
 
Example 14
public int getLine() {
int line=0;
      if ( token!=null ) {
          line = token.getLine();
      }
if ( line==0 ) {
	AST child = getFirstChild();
	if ( child!=null ) {
		line = child.getLine();
	}
}
      return line;
  }
 
Example 15
public final void attrScope(AST _t) throws RecognitionException {
	
	GrammarAST attrScope_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	GrammarAST name = null;
	GrammarAST attrs = null;
	
	try {      // for error handling
		AST __t8 = _t;
		GrammarAST tmp5_AST_in = (GrammarAST)_t;
		match(_t,SCOPE);
		_t = _t.getFirstChild();
		name = (GrammarAST)_t;
		match(_t,ID);
		_t = _t.getNextSibling();
		attrs = (GrammarAST)_t;
		match(_t,ACTION);
		_t = _t.getNextSibling();
		_t = __t8;
		_t = _t.getNextSibling();
		if ( inputState.guessing==0 ) {
			
					AttributeScope scope = grammar.defineGlobalScope(name.getText(),attrs.token);
					scope.isDynamicGlobalScope = true;
					scope.addAttributes(attrs.getText(), ';');
					
		}
	}
	catch (RecognitionException ex) {
		if (inputState.guessing==0) {
			reportError(ex);
			if (_t!=null) {_t = _t.getNextSibling();}
		} else {
		  throw ex;
		}
	}
	_retTree = _t;
}
 
Example 16
public void processNumeric(AST literal) {
	if ( literal.getType() == NUM_INT || literal.getType() == NUM_LONG ) {
		literal.setText( determineIntegerRepresentation( literal.getText(), literal.getType() ) );
	}
	else if ( literal.getType() == NUM_FLOAT || literal.getType() == NUM_DOUBLE ) {
		literal.setText( determineDecimalRepresentation( literal.getText(), literal.getType() ) );
	}
	else {
		log.warn( "Unexpected literal token type [" + literal.getType() + "] passed for numeric processing" );
	}
}
 
Example 17
Source Project: cxf   Source File: TypesUtils.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns node corresponding to the name of the CORBA primitive type node.
 *
 * @param node
 * @return
 */
public static AST getCorbaTypeNameNode(AST node) {
    AST currentNode = node;
    if (currentNode.getType() == IDLTokenTypes.LITERAL_unsigned) {
        currentNode = currentNode.getNextSibling();
    }
    if (currentNode.getType() == IDLTokenTypes.LITERAL_long
        && (currentNode.getNextSibling() != null)
        && (currentNode.getNextSibling().getType() == IDLTokenTypes.LITERAL_long)) {
        currentNode = currentNode.getNextSibling();
    }
    return currentNode.getNextSibling();
}
 
Example 18
Source Project: lams   Source File: HqlSqlWalker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void lookupAlias(AST aliasRef)
		throws SemanticException {
	FromElement alias = currentFromClause.getFromElement( aliasRef.getText() );
	FromReferenceNode aliasRefNode = (FromReferenceNode) aliasRef;
	aliasRefNode.setFromElement( alias );
}
 
Example 19
Source Project: lams   Source File: DotNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 );
	}
}
 
Example 20
Source Project: lams   Source File: FromElementFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
private FromElement createFromElement(EntityPersister entityPersister) {
	Joinable joinable = (Joinable) entityPersister;
	String text = joinable.getTableName();
	AST ast = createFromElement( text );
	FromElement element = (FromElement) ast;
	return element;
}
 
Example 21
public Visibility visibility(AST modifiers) {
  if (contains(modifiers, "private"))
    return Visibility.PRIVATE;
  if (contains(modifiers, "protected"))
    return Visibility.PROTECTED;
  if (contains(modifiers, "public"))
    return Visibility.PUBLIC;
  return Visibility.PACKAGE;
}
 
Example 22
Source Project: cxf   Source File: StructVisitor.java    License: Apache License 2.0 5 votes vote down vote up
private boolean addRecursiveScopedName(AST identifierNode) {
    String structName = identifierNode.toString();
    Scope structScope = new Scope(getScope(), structName);

    ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
    if (scopedNames.getScope(structScope) == null) {
        scopedNames.add(structScope);
        return true;
    }
    return false;
}
 
Example 23
Source Project: cxf   Source File: ScopedNameVisitor.java    License: Apache License 2.0 5 votes vote down vote up
protected static boolean findSchemaType(Scope scope,
                                        Definition defn,
                                        XmlSchema schemaRef,
                                        AST node,
                                        WSDLASTVisitor wsdlVisitor,
                                        VisitorTypeHolder holder) {
    return findSchemaType(scope, defn, schemaRef, node, wsdlVisitor, holder, false);
}
 
Example 24
public void visit(AST node) {
	// todo : currently expects that the individual with expressions apply to the same sql table join.
	//      This may not be the case for joined-subclass where the property values
	//      might be coming from different tables in the joined hierarchy.  At some
	//      point we should expand this to support that capability.  However, that has
	//      some difficulties:
	//          1) the biggest is how to handle ORs when the individual comparisons are
	//              linked to different sql joins.
	//          2) here we would need to track each comparison individually, along with
	//              the join alias to which it applies and then pass that information
	//              back to the FromElement so it can pass it along to the JoinSequence

	if ( node instanceof DotNode ) {
		DotNode dotNode = ( DotNode ) node;
		FromElement fromElement = dotNode.getFromElement();
		if ( referencedFromElement != null ) {
			if ( fromElement != referencedFromElement ) {
				throw new HibernateException( "with-clause referenced two different from-clause elements" );
			}
		}
		else {
			referencedFromElement = fromElement;
			joinAlias = extractAppliedAlias( dotNode );
			// todo : temporary
			//      needed because currently persister is the one that
			//      creates and renders the join fragments for inheritence
			//      hierarchies...
			if ( !joinAlias.equals( referencedFromElement.getTableAlias() ) ) {
				throw new InvalidWithClauseException( "with clause can only reference columns in the driving table" );
			}
		}
	}
}
 
Example 25
Source Project: lams   Source File: ASTParentsFirstIterator.java    License: GNU General Public License v2.0 5 votes vote down vote up
private AST pop() {
	if ( parents.size() == 0 ) {
		return null;
	}
	else {
		return parents.removeFirst();
	}
}
 
Example 26
public final void tokensSpec(AST _t) throws RecognitionException {
	
	GrammarAST tokensSpec_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		AST __t36 = _t;
		GrammarAST tmp12_AST_in = (GrammarAST)_t;
		match(_t,TOKENS);
		_t = _t.getFirstChild();
		{
		int _cnt38=0;
		_loop38:
		do {
			if (_t==null) _t=ASTNULL;
			if ((_t.getType()==ASSIGN||_t.getType()==TOKEN_REF)) {
				tokenSpec(_t);
				_t = _retTree;
			}
			else {
				if ( _cnt38>=1 ) { break _loop38; } else {throw new NoViableAltException(_t);}
			}
			
			_cnt38++;
		} while (true);
		}
		_t = __t36;
		_t = _t.getNextSibling();
	}
	catch (RecognitionException ex) {
		reportError(ex);
		if (_t!=null) {_t = _t.getNextSibling();}
	}
	_retTree = _t;
}
 
Example 27
public final void finallyClause(AST _t) throws RecognitionException {
	
	GrammarAST finallyClause_AST_in = (_t == ASTNULL) ? null : (GrammarAST)_t;
	
	try {      // for error handling
		AST __t93 = _t;
		GrammarAST tmp56_AST_in = (GrammarAST)_t;
		match(_t,LITERAL_finally);
		_t = _t.getFirstChild();
		GrammarAST tmp57_AST_in = (GrammarAST)_t;
		match(_t,ACTION);
		_t = _t.getNextSibling();
		_t = __t93;
		_t = _t.getNextSibling();
		if ( inputState.guessing==0 ) {
			trackInlineAction(tmp57_AST_in);
		}
	}
	catch (RecognitionException ex) {
		if (inputState.guessing==0) {
			reportError(ex);
			if (_t!=null) {_t = _t.getNextSibling();}
		} else {
		  throw ex;
		}
	}
	_retTree = _t;
}
 
Example 28
Source Project: lams   Source File: ASTUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 29
private void initializeColumns() {
	AST propertySpec = getFirstChild();
	List types = new ArrayList();
	visitPropertySpecNodes( propertySpec.getFirstChild(), types );
	this.types = ArrayHelper.toTypeArray( types );
	columnSpec = columnSpec.substring( 0, columnSpec.length() - 2 );
}
 
Example 30
Source Project: proparse   Source File: NodeFactory.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/** Used for synthetic node creation by the Antlr generated parser. */
@Override
public AST create(int type) {
	ProToken token = new ProToken(filenameList, type, "");
	switch(type) {
		case NodeTypes.Field_ref:
			return new FieldRefNode(token);
		case NodeTypes.Program_root:
			return new ProgramRootNode(token);
		default:
			return new JPNode(token);
	}
}