本文整理汇总了Java中antlr.collections.AST.addChild方法的典型用法代码示例。如果您正苦于以下问题:Java AST.addChild方法的具体用法?Java AST.addChild怎么用?Java AST.addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类antlr.collections.AST
的用法示例。
在下文中一共展示了AST.addChild方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSortSpecification
import antlr.collections.AST; //导入方法依赖的package包/类
private SortSpecification createSortSpecification(
AST ident,
CollationSpecification collationSpecification,
OrderingSpecification orderingSpecification) {
AST sortSpecification = getASTFactory().create( SORT_SPEC, "{{sort specification}}" );
AST sortKey = getASTFactory().create( SORT_KEY, "{{sort key}}" );
AST newIdent = getASTFactory().create( ident.getType(), ident.getText() );
sortKey.setFirstChild( newIdent );
sortSpecification.setFirstChild( sortKey );
if ( collationSpecification != null ) {
sortSpecification.addChild( collationSpecification );
}
if ( orderingSpecification != null ) {
sortSpecification.addChild( orderingSpecification );
}
return ( SortSpecification ) sortSpecification;
}
示例2: resolveIdent
import antlr.collections.AST; //导入方法依赖的package包/类
@Override
protected AST resolveIdent(AST ident) {
/*
* Semantic action used during recognition of an identifier. This identifier might be a column name, it might
* be a property name.
*/
String text = ident.getText();
SqlValueReference[] sqlValueReferences;
try {
sqlValueReferences = context.getColumnMapper().map( text );
}
catch( Throwable t ) {
sqlValueReferences = null;
}
if ( sqlValueReferences == null || sqlValueReferences.length == 0 ) {
return getASTFactory().create( OrderByTemplateTokenTypes.IDENT, makeColumnReference( text ) );
}
else if ( sqlValueReferences.length == 1 ) {
return processSqlValueReference( sqlValueReferences[0] );
}
else {
final AST root = getASTFactory().create( OrderByTemplateTokenTypes.IDENT_LIST, "{ident list}" );
for ( SqlValueReference sqlValueReference : sqlValueReferences ) {
root.addChild( processSqlValueReference( sqlValueReference ) );
}
return root;
}
}
示例3: generateSyntheticDotNodeForNonQualifiedPropertyRef
import antlr.collections.AST; //导入方法依赖的package包/类
private AST generateSyntheticDotNodeForNonQualifiedPropertyRef(AST property, FromElement fromElement) {
AST dot = getASTFactory().create( DOT, "{non-qualified-property-ref}" );
// TODO : better way?!?
( (DotNode) dot ).setPropertyPath( ( (FromReferenceNode) property ).getPath() );
IdentNode syntheticAlias = (IdentNode) getASTFactory().create( IDENT, "{synthetic-alias}" );
syntheticAlias.setFromElement( fromElement );
syntheticAlias.setResolved();
dot.setFirstChild( syntheticAlias );
dot.addChild( property );
return dot;
}
示例4: processMemberOf
import antlr.collections.AST; //导入方法依赖的package包/类
@Override
public void processMemberOf(Token n, AST p, ASTPair currentAST) {
// convert MEMBER OF to the equivalent IN ELEMENTS structure...
AST inNode = n == null ? astFactory.create( IN, "in" ) : astFactory.create( NOT_IN, "not in" );
astFactory.makeASTRoot( currentAST, inNode );
AST inListNode = astFactory.create( IN_LIST, "inList" );
inNode.addChild( inListNode );
AST elementsNode = astFactory.create( ELEMENTS, "elements" );
inListNode.addChild( elementsNode );
elementsNode.addChild( p );
}
示例5: makeASTRoot
import antlr.collections.AST; //导入方法依赖的package包/类
/** Make an AST the root of current AST */
public void makeASTRoot(ASTPair currentAST, AST root) {
if (root != null) {
// Add the current root as a child of new root
root.addChild(currentAST.root);
// The new current child is the last sibling of the old root
currentAST.child = currentAST.root;
currentAST.advanceChildToEnd();
// Set the new root
currentAST.root = root;
}
}
示例6: addDiscriminatorWhereFragment
import antlr.collections.AST; //导入方法依赖的package包/类
public void addDiscriminatorWhereFragment(
RestrictableStatement statement,
Queryable persister,
Map enabledFilters,
String alias) {
String whereFragment = persister.filterFragment( alias, enabledFilters ).trim();
if ( "".equals( whereFragment ) ) {
return;
}
if ( whereFragment.startsWith( "and" ) ) {
whereFragment = whereFragment.substring( 4 );
}
// Need to parse off the column qualifiers; this is assuming (which is true as of now)
// that this is only used from update and delete HQL statement parsing
whereFragment = StringHelper.replace(
whereFragment,
persister.generateFilterConditionAlias( alias ) + ".",
""
);
// Note: this simply constructs a "raw" SQL_TOKEN representing the
// where fragment and injects this into the tree. This "works";
// however it is probably not the best long-term solution.
//
// At some point we probably want to apply an additional grammar to
// properly tokenize this where fragment into constituent parts
// focused on the operators embedded within the fragment.
SqlFragment discrimNode = (SqlFragment) create( SQL_TOKEN, whereFragment );
JoinProcessor.processDynamicFilterParameters(
whereFragment,
discrimNode,
hqlSqlWalker
);
if ( statement.getWhereClause().getNumberOfChildren() == 0 ) {
statement.getWhereClause().setFirstChild( discrimNode );
}
else {
AST and = create( AND, "{and}" );
AST currentFirstChild = statement.getWhereClause().getFirstChild();
and.setFirstChild( discrimNode );
and.addChild( currentFirstChild );
statement.getWhereClause().setFirstChild( and );
}
}
示例7: prepareFromClauseInputTree
import antlr.collections.AST; //导入方法依赖的package包/类
@Override
protected void prepareFromClauseInputTree(AST fromClauseInput) {
if ( !isSubQuery() ) {
// // inject param specifications to account for dynamic filter param values
// if ( ! getEnabledFilters().isEmpty() ) {
// Iterator filterItr = getEnabledFilters().values().iterator();
// while ( filterItr.hasNext() ) {
// FilterImpl filter = ( FilterImpl ) filterItr.next();
// if ( ! filter.getFilterDefinition().getParameterNames().isEmpty() ) {
// Iterator paramItr = filter.getFilterDefinition().getParameterNames().iterator();
// while ( paramItr.hasNext() ) {
// String parameterName = ( String ) paramItr.next();
// // currently param filters *only* work with single-column parameter types;
// // if that limitation is ever lifted, this logic will need to change to account for that
// ParameterNode collectionFilterKeyParameter = ( ParameterNode ) astFactory.create( PARAM, "?" );
// DynamicFilterParameterSpecification paramSpec = new DynamicFilterParameterSpecification(
// filter.getName(),
// parameterName,
// filter.getFilterDefinition().getParameterType( parameterName ),
// positionalParameterCount++
// );
// collectionFilterKeyParameter.setHqlParameterSpecification( paramSpec );
// parameters.add( paramSpec );
// }
// }
// }
// }
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 );
}
}
}
示例8: prepareVersioned
import antlr.collections.AST; //导入方法依赖的package包/类
@Override
protected void prepareVersioned(AST updateNode, AST versioned) throws SemanticException {
UpdateStatement updateStatement = (UpdateStatement) updateNode;
FromClause fromClause = updateStatement.getFromClause();
if ( versioned != null ) {
// Make sure that the persister is versioned
Queryable persister = fromClause.getFromElement().getQueryable();
if ( !persister.isVersioned() ) {
throw new SemanticException( "increment option specified for update of non-versioned entity" );
}
VersionType versionType = persister.getVersionType();
if ( versionType instanceof UserVersionType ) {
throw new SemanticException( "user-defined version types not supported for increment option" );
}
AST eq = getASTFactory().create( HqlSqlTokenTypes.EQ, "=" );
AST versionPropertyNode = generateVersionPropertyNode( persister );
eq.setFirstChild( versionPropertyNode );
AST versionIncrementNode = null;
if ( isTimestampBasedVersion( versionType ) ) {
versionIncrementNode = getASTFactory().create( HqlSqlTokenTypes.PARAM, "?" );
ParameterSpecification paramSpec = new VersionTypeSeedParameterSpecification( versionType );
( (ParameterNode) versionIncrementNode ).setHqlParameterSpecification( paramSpec );
parameters.add( 0, paramSpec );
}
else {
// Not possible to simply re-use the versionPropertyNode here as it causes
// OOM errors due to circularity :(
versionIncrementNode = getASTFactory().create( HqlSqlTokenTypes.PLUS, "+" );
versionIncrementNode.setFirstChild( generateVersionPropertyNode( persister ) );
versionIncrementNode.addChild( getASTFactory().create( HqlSqlTokenTypes.IDENT, "1" ) );
}
eq.addChild( versionIncrementNode );
evaluateAssignment( eq, persister, 0 );
AST setClause = updateStatement.getSetClause();
AST currentFirstSetElement = setClause.getFirstChild();
setClause.setFirstChild( eq );
eq.setNextSibling( currentFirstSetElement );
}
}