本文整理汇总了Java中org.antlr.runtime.tree.Tree类的典型用法代码示例。如果您正苦于以下问题:Java Tree类的具体用法?Java Tree怎么用?Java Tree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tree类属于org.antlr.runtime.tree包,在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: recursivelyFixWindowFucntion
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
public static void recursivelyFixWindowFucntion(
CommonTree srcTree) {
if (srcTree.getChildCount() == 0) { return; }
// process node
String text = srcTree.getText();
System.out.println("Currently processed node==> " + text);
if (text.equals(PARTITION_BY)) {
return;
} else if (text.equals(ORDER_BY)) {
if (srcTree.getChildCount() == 0) {
if (srcTree.getParent() != null) {
// found a matching node
srcTree.getParent().deleteChild(srcTree.getChildIndex());
srcTree.getParent().freshenParentAndChildIndexes();
}
}
return;
}
// process children
for (Tree t : children(srcTree)) {
recursivelyFixWindowFucntion((CommonTree)t);
}
}
示例2: findAggFuncRecursively
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
private static Boolean findAggFuncRecursively(
CommonTree tree,
List<String> aggregateFuncs) {
Boolean ret = false;
if (tree.getText().equals(FUNCTION_CALL)) {
// function
String funcName = tree.getChild(0).getChild(0).getText(); //FUNCTION_CALL->QNAME->xxx
if (aggregateFuncs.contains(funcName.toLowerCase())) {
return true;
}
}
for (Tree t : children(tree)) {
ret = findAggFuncRecursively((CommonTree)t, aggregateFuncs);
if (ret == true) {
return true;
}
}
return false;
}
示例3: patchTreeByTreesGroupBy
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
public static void patchTreeByTreesGroupBy(CommonTree srcTree, CommonTree targetTree)
{
//System.out.println("Text = " + srcTree.getText() + " ChildCount = " + srcTree.getChildCount() + " Type = " + srcTree.getType());
if (srcTree.getChildCount() == 0) {
return;
}
// process node
if (srcTree.getText().equals(QUERY_SPEC_NODE)) {
// patch
targetTree.setParent(srcTree);
srcTree.addChild(targetTree);
return;
}
// process children
for (Tree t : children(srcTree)) {
patchTreeByTreesGroupBy((CommonTree)t, targetTree);
}
return;
}
示例4: gatherTypes
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
private static void gatherTypes(CommonTree srcTree, Map<String, Integer> typesMap)
{
if (srcTree.getChildCount() == 0) {
return;
}
// process node
if (!typesMap.containsKey(srcTree.getText())) {
typesMap.put(srcTree.getText(), new Integer(srcTree.getType()));
}
// process children
for (Tree subTree : children(srcTree)) {
gatherTypes((CommonTree)subTree, typesMap);
}
return;
}
示例5: updateTreeByString
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
public static void updateTreeByString(CommonTree tree, String target, String goal) {
if (tree.getChildCount() == 0) {
// leaf
if (tree.getText().equals(target)) {
//modifyText(tree, goal+'.'+target);
modifyText(tree, goal);
//System.out.println("Found 1!!!");
}
return;
}
// process node
if (tree.getText().equals(target)) {
modifyText(tree, goal+'.'+target);
//System.out.println("Found 2!!!");
}
// process children
for (Tree t : children(tree)) {
updateTreeByString((CommonTree)t, target, goal);
}
return;
}
示例6: treeToString
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
private static String treeToString(Tree tree, int depth)
{
if (tree.getChildCount() == 0) {
return quotedString(tree.toString());
}
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(tree.toString());
for (Tree t : children(tree)) {
if (hasSubtree(t) && (leafCount(tree) > 2)) {
sb.append("\n");
sb.append(repeat(" ", depth));
}
else {
sb.append(" ");
}
sb.append(treeToString(t, depth + 1));
}
sb.append(")");
return sb.toString();
}
示例7: getChildren
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
/**
* Gets the children as a List
* @param tree Tree
* @return either emptyList or the children.
*/
public static List<Tree> getChildren(Tree tree)
{
if (tree!=null && tree.getChildCount() > 0)
{
List<Tree> children = new ArrayList<Tree>(tree.getChildCount());
for (int i = 0; i < tree.getChildCount(); i++) {
Tree child = tree.getChild(i);
children.add(child);
}
return children;
}
//Default
return Collections.emptyList();
}
示例8: getAltLabel
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
/** Walk ancestors of this node until we find ALT with
* alt!=null or leftRecursiveAltInfo!=null. Then grab label if any.
* If not a rule element, just returns null.
*/
public String getAltLabel() {
List<? extends Tree> ancestors = this.getAncestors();
if ( ancestors==null ) return null;
for (int i=ancestors.size()-1; i>=0; i--) {
GrammarAST p = (GrammarAST)ancestors.get(i);
if ( p.getType()== ANTLRParser.ALT ) {
AltAST a = (AltAST)p;
if ( a.altLabel!=null ) return a.altLabel.getText();
if ( a.leftRecursiveAltInfo!=null ) {
return a.leftRecursiveAltInfo.altLabel;
}
}
}
return null;
}
示例9: hasImmediateRecursiveRuleRefs
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
/**
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT RULE_REF[self] .*) (ALT .*)))
* Match (RULE RULE_REF (BLOCK (ALT .*) (ALT (ASSIGN ID RULE_REF[self]) .*) (ALT .*)))
*/
public static boolean hasImmediateRecursiveRuleRefs(GrammarAST t, String ruleName) {
if ( t==null ) return false;
GrammarAST blk = (GrammarAST)t.getFirstChildWithType(BLOCK);
if ( blk==null ) return false;
int n = blk.getChildren().size();
for (int i = 0; i < n; i++) {
GrammarAST alt = (GrammarAST)blk.getChildren().get(i);
Tree first = alt.getChild(0);
if ( first==null ) continue;
if (first.getType() == ELEMENT_OPTIONS) {
first = alt.getChild(1);
if (first == null) {
continue;
}
}
if ( first.getType()==RULE_REF && first.getText().equals(ruleName) ) return true;
Tree rref = first.getChild(1);
if ( rref!=null && rref.getType()==RULE_REF && rref.getText().equals(ruleName) ) return true;
}
return false;
}
示例10: A
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
/**
Make sure that action is last element in outer alt; here action,
a2, z, and zz are bad, but a3 is ok:
(RULE A (BLOCK (ALT {action} 'a')))
(RULE B (BLOCK (ALT (BLOCK (ALT {a2} 'x') (ALT 'y')) {a3})))
(RULE C (BLOCK (ALT 'd' {z}) (ALT 'e' {zz})))
*/
protected void checkElementIsOuterMostInSingleAlt(GrammarAST tree) {
CommonTree alt = tree.parent;
CommonTree blk = alt.parent;
boolean outerMostAlt = blk.parent.getType() == RULE;
Tree rule = tree.getAncestor(RULE);
String fileName = tree.getToken().getInputStream().getSourceName();
if ( !outerMostAlt || blk.getChildCount()>1 )
{
ErrorType e = ErrorType.LEXER_COMMAND_PLACEMENT_ISSUE;
g.tool.errMgr.grammarError(e,
fileName,
tree.getToken(),
rule.getChild(0).getText());
}
}
示例11: replaceWithCount
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
public void replaceWithCount(EntityReference entityRef) {
Tree selectedItems = tree.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEMS);
boolean isDistinct = "DISTINCT".equalsIgnoreCase(selectedItems.getChild(0).getText());
if (!(isDistinct && selectedItems.getChildCount() == 2 ||
selectedItems.getChildCount() == 1))
throw new IllegalStateException("Cannot replace with count if multiple fields selected");
SelectedItemNode selectedItemNode;
if (isDistinct)
selectedItems.deleteChild(0);
selectedItemNode = (SelectedItemNode) selectedItems.getChild(0);
AggregateExpressionNode countNode = createCountNode(entityRef, isDistinct);
selectedItemNode.deleteChild(0);
selectedItemNode.addChild(countNode);
Tree orderBy = tree.getFirstChildWithType(JPA2Lexer.T_ORDER_BY);
if (orderBy != null) {
tree.deleteChild(orderBy.getChildIndex());
}
tree.freshenParentAndChildIndexes();
}
示例12: getSelectedPathNode
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
public PathNode getSelectedPathNode() {
Tree selectedItems = tree.getFirstChildWithType(JPA2Lexer.T_SELECTED_ITEMS);
boolean isDistinct = "DISTINCT".equalsIgnoreCase(selectedItems.getChild(0).getText());
SelectedItemNode selectedItemNode;
if (isDistinct) {
if (selectedItems.getChildCount() != 2)
throw new IllegalStateException("Cannot select path node if multiple fields selected");
selectedItemNode = (SelectedItemNode) selectedItems.getChild(1);
} else {
if (selectedItems.getChildCount() != 1)
throw new IllegalStateException("Cannot select path node if multiple fields selected");
selectedItemNode = (SelectedItemNode) selectedItems.getChild(0);
}
if (!(selectedItemNode.getChild(0) instanceof PathNode)) {
throw new IllegalStateException("An entity path is assumed to be selected");
}
return (PathNode) selectedItemNode.getChild(0);
}
示例13: executeHelp
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
private void executeHelp(Tree tree)
{
if (tree.getChildCount() > 0)
{
String token = tree.getChild(0).getText();
for (CliCommandHelp ch : getHelp().commands)
{
if (token.equals(ch.name))
{
sessionState.out.println(ch.help);
break;
}
}
}
else
{
sessionState.out.println(getHelp().help);
}
}
示例14: executeConsistencyLevelStatement
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
/**
* Command: CONSISTENCYLEVEL AS (ONE | QUORUM ...)
* Tree: ^(NODE_CONSISTENCY_LEVEL AS (ONE | QUORUM ...))
* @param statement - tree representing current statement
*/
private void executeConsistencyLevelStatement(Tree statement)
{
if (!CliMain.isConnected())
return;
String userSuppliedLevel = statement.getChild(0).getText().toUpperCase();
try
{
consistencyLevel = ConsistencyLevel.valueOf(userSuppliedLevel);
}
catch (IllegalArgumentException e)
{
String elements = "ONE, TWO, THREE, QUORUM, ALL, LOCAL_QUORUM, EACH_QUORUM, ANY";
sessionState.out.println(String.format("'%s' is invalid. Available: %s", userSuppliedLevel, elements));
return;
}
sessionState.out.println(String.format("Consistency level is set to '%s'.", consistencyLevel));
}
示例15: executeAssumeStatement
import org.antlr.runtime.tree.Tree; //导入依赖的package包/类
/**
* Command: ASSUME <columnFamily> (VALIDATOR | COMPARATOR | KEYS | SUB_COMPARATOR) AS <type>
* Tree: ^(NODE_ASSUME <columnFamily> (VALIDATOR | COMPARATOR | KEYS | SUB_COMPARATOR) <type>))
* @param statement - tree representing current statement
*/
private void executeAssumeStatement(Tree statement)
{
if (!CliMain.isConnected() || !hasKeySpace())
return;
String cfName = CliCompiler.getColumnFamily(statement, currentCfDefs());
// VALIDATOR | COMPARATOR | KEYS | SUB_COMPARATOR
String assumptionElement = statement.getChild(1).getText().toUpperCase();
// Could be UTF8Type, IntegerType, LexicalUUIDType etc.
String defaultType = CliUtils.unescapeSQLString(statement.getChild(2).getText());
if (applyAssumption(cfName, assumptionElement, defaultType))
{
assumptions.addAssumption(keySpace, cfName, assumptionElement, defaultType);
sessionState.out.println(String.format("Assumption for column family '%s' added successfully.", cfName));
}
}