Search in sources :

Example 1 with ASTFactory

use of antlr.ASTFactory in project hibernate-orm by hibernate.

the class HqlSqlWalker method prepareFromClauseInputTree.

@Override
protected void prepareFromClauseInputTree(AST fromClauseInput) {
    if (!isSubQuery()) {
        if (isFilter()) {
            // Handle collection-filter compilation.
            // IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
            QueryableCollection persister = sessionFactoryHelper.getCollectionPersister(collectionFilterRole);
            Type collectionElementType = persister.getElementType();
            if (!collectionElementType.isEntityType()) {
                throw new QueryException("collection of values in filter: this");
            }
            String collectionElementEntityName = persister.getElementPersister().getEntityName();
            ASTFactory inputAstFactory = hqlParser.getASTFactory();
            AST fromElement = inputAstFactory.create(HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName);
            ASTUtil.createSibling(inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement);
            fromClauseInput.addChild(fromElement);
            // Show the modified AST.
            LOG.debug("prepareFromClauseInputTree() : Filter - Added 'this' as a from element...");
            queryTranslatorImpl.showHqlAst(hqlParser.getAST());
            // Create a parameter specification for the collection filter...
            Type collectionFilterKeyType = sessionFactoryHelper.requireQueryableCollection(collectionFilterRole).getKeyType();
            ParameterNode collectionFilterKeyParameter = (ParameterNode) astFactory.create(PARAM, "?");
            CollectionFilterKeyParameterSpecification collectionFilterKeyParameterSpec = new CollectionFilterKeyParameterSpecification(collectionFilterRole, collectionFilterKeyType, positionalParameterCount++);
            collectionFilterKeyParameter.setHqlParameterSpecification(collectionFilterKeyParameterSpec);
            parameters.add(collectionFilterKeyParameterSpec);
        }
    }
}
Also used : UserVersionType(org.hibernate.usertype.UserVersionType) JoinType(org.hibernate.sql.JoinType) CompositeType(org.hibernate.type.CompositeType) DbTimestampType(org.hibernate.type.DbTimestampType) VersionType(org.hibernate.type.VersionType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) QueryException(org.hibernate.QueryException) AST(antlr.collections.AST) ASTFactory(antlr.ASTFactory) ParameterNode(org.hibernate.hql.internal.ast.tree.ParameterNode) CollectionFilterKeyParameterSpecification(org.hibernate.param.CollectionFilterKeyParameterSpecification) QueryableCollection(org.hibernate.persister.collection.QueryableCollection)

Example 2 with ASTFactory

use of antlr.ASTFactory in project hibernate-orm by hibernate.

the class FromElementFactory method evaluateFromElementPath.

private FromElement evaluateFromElementPath(String path, String classAlias) throws SemanticException {
    ASTFactory factory = fromClause.getASTFactory();
    FromReferenceNode pathNode = (FromReferenceNode) PathHelper.parsePath(path, factory);
    pathNode.recursiveResolve(// This is the root level node.
    FromReferenceNode.ROOT_LEVEL, // Generate an explicit from clause at the root.
    false, classAlias, null);
    if (pathNode.getImpliedJoin() != null) {
        return pathNode.getImpliedJoin();
    }
    return pathNode.getFromElement();
}
Also used : ASTFactory(antlr.ASTFactory)

Example 3 with ASTFactory

use of antlr.ASTFactory in project hibernate-orm by hibernate.

the class ColumnHelper method generateScalarColumns.

/**
	 * Generates the scalar column AST nodes for a given array of SQL columns
	 */
public static void generateScalarColumns(HqlSqlWalkerNode node, String[] sqlColumns, int i) {
    if (sqlColumns.length == 1) {
        generateSingleScalarColumn(node, i);
    } else {
        ASTFactory factory = node.getASTFactory();
        AST n = node;
        // Use the DOT node to emit the first column name.
        n.setText(sqlColumns[0]);
        // Create the column names, folled by the column aliases.
        for (int j = 0; j < sqlColumns.length; j++) {
            if (j > 0) {
                n = ASTUtil.createSibling(factory, SqlTokenTypes.SQL_TOKEN, sqlColumns[j], n);
            }
            n = ASTUtil.createSibling(factory, SqlTokenTypes.SELECT_COLUMNS, " as " + NameGenerator.scalarName(i, j), n);
        }
    }
}
Also used : AST(antlr.collections.AST) ASTFactory(antlr.ASTFactory)

Example 4 with ASTFactory

use of antlr.ASTFactory in project checkstyle by checkstyle.

the class ParseTreeTablePresentation method createArtificialTreeRoot.

/**
     * Creates artificial tree root.
     * @return artificial tree root.
     */
private static DetailAST createArtificialTreeRoot() {
    final ASTFactory factory = new ASTFactory();
    factory.setASTNodeClass(DetailAST.class.getName());
    return (DetailAST) factory.create(TokenTypes.EOF, "ROOT");
}
Also used : ASTFactory(antlr.ASTFactory) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST)

Example 5 with ASTFactory

use of antlr.ASTFactory in project groovy-core by groovy.

the class Main method doTreeAction.

public static void doTreeAction(String f, AST t, String[] tokenNames) {
    if (t == null)
        return;
    if (showTree) {
        CommonAST.setVerboseStringConversion(true, tokenNames);
        ASTFactory factory = new ASTFactory();
        AST r = factory.create(0, "AST ROOT");
        r.setFirstChild(t);
        final ASTFrame frame = new ASTFrame("Groovy AST", r);
        frame.setVisible(true);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                // hide the Frame
                frame.setVisible(false);
                frame.dispose();
                System.exit(0);
            }
        });
        if (verbose)
            System.out.println(t.toStringList());
    }
/*if ( xml ) {
            ((CommonAST)t).setVerboseStringConversion(true, tokenNames);
            ASTFactory factory = new ASTFactory();
            AST r = factory.create(0,"AST ROOT");
            r.setFirstChild(t);
            XStream xstream = new XStream();
            xstream.alias("ast", CommonAST.class);
            try {
                xstream.toXML(r,new FileWriter(f + ".xml"));
                System.out.println("Written AST to " + f + ".xml");
            } catch (Exception e) {
                System.out.println("couldn't write to " + f + ".xml");
                e.printStackTrace();
            }
            //if (verbose)  System.out.println(t.toStringList());
        }*/
/*@todo
        GroovyTreeParser tparse = new GroovyTreeParser();
        try {
            tparse.compilationUnit(t);
            if (verbose)  System.out.println("successful walk of result AST for "+f);
        }
        catch (RecognitionException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    @todo*/
}
Also used : AST(antlr.collections.AST) CommonAST(antlr.CommonAST) ASTFrame(antlr.debug.misc.ASTFrame) ASTFactory(antlr.ASTFactory) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

ASTFactory (antlr.ASTFactory)7 AST (antlr.collections.AST)4 CommonAST (antlr.CommonAST)2 ASTFrame (antlr.debug.misc.ASTFrame)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)1 QueryException (org.hibernate.QueryException)1 ParameterNode (org.hibernate.hql.internal.ast.tree.ParameterNode)1 CollectionFilterKeyParameterSpecification (org.hibernate.param.CollectionFilterKeyParameterSpecification)1 QueryableCollection (org.hibernate.persister.collection.QueryableCollection)1 JoinType (org.hibernate.sql.JoinType)1 AssociationType (org.hibernate.type.AssociationType)1 CompositeType (org.hibernate.type.CompositeType)1 DbTimestampType (org.hibernate.type.DbTimestampType)1 Type (org.hibernate.type.Type)1 VersionType (org.hibernate.type.VersionType)1 UserVersionType (org.hibernate.usertype.UserVersionType)1