本文整理匯總了Java中org.antlr.runtime.tree.Tree.getChildCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Tree.getChildCount方法的具體用法?Java Tree.getChildCount怎麽用?Java Tree.getChildCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.runtime.tree.Tree
的用法示例。
在下文中一共展示了Tree.getChildCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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();
}
示例4: 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);
}
示例5: 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);
}
}
示例6: getInputRelation
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
/**
* We have a very crude heuristic here. If we ever make it public, would
* need to clean this up.
*
* @param input
* @return
* @throws SQLException
* @throws DataLawyerException
*/
private static Relation getInputRelation(Tree input, Counters counters,
boolean aliased) throws SQLException, DataLawyerException {
String relation_name = input.getText().toLowerCase();
if (input.getChildCount() == 0) {
String[] names = DB.getDB().separateSchemaAndName(relation_name);
Index index = new Index(names[1], names[0], counters);
if (aliased)
return new OpAlias(index, "alias_" + index.getId());
else
return index;
} else if (input.getChildCount() == 1) {
Relation base_relation = getInputRelation(input.getChild(0),
counters, false);
return new OpAlias(base_relation, relation_name);
} else {
Relation base_query = convertASTtoRelation(input, counters);
return new OpAlias(base_query, relation_name);
}
}
示例7: children
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static List<Tree> children(Tree tree) {
List<Tree> list = new ArrayList<Tree>();
for (int i = 0; i < tree.getChildCount(); i++) {
list.add(tree.getChild(i));
}
return list;
}
示例8: treeToPureString
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
public static String treeToPureString(Tree tree) {
if (tree.getChildCount() == 0) {
return quotedString(tree.toString());
}
StringBuilder sb = new StringBuilder();
for (Tree t : children(tree)) {
sb.append(treeToPureString(t));
}
return sb.toString();
}
示例9: hasSubtree
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static boolean hasSubtree(Tree tree)
{
for (Tree t : children(tree)) {
if (t.getChildCount() > 0) {
return true;
}
}
return false;
}
示例10: leafCount
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static int leafCount(Tree tree)
{
if (tree.getChildCount() == 0) {
return 1;
}
int n = 0;
for (Tree t : children(tree)) {
n += leafCount(t);
}
return n;
}
示例11: children
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private static List<Tree> children(Tree tree)
{
List<Tree> list = new ArrayList<Tree>();
for (int i = 0; i < tree.getChildCount(); i++) {
list.add(tree.getChild(i));
}
return list;
}
示例12: findFuzzy
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
static private Float findFuzzy(Tree node)
{
for (int i = 0, l = node.getChildCount(); i < l; i++)
{
CommonTree child = (CommonTree) node.getChild(i);
if (child.getType() == FTSParser.FUZZY)
{
String fuzzyString = child.getChild(0).getText();
float fuzzy = Float.parseFloat(fuzzyString);
return Float.valueOf(fuzzy);
}
}
return null;
}
示例13: getLexerAction
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
public ActionAST getLexerAction() {
Tree blk = getFirstChildWithType(ANTLRParser.BLOCK);
if ( blk.getChildCount()==1 ) {
Tree onlyAlt = blk.getChild(0);
Tree lastChild = onlyAlt.getChild(onlyAlt.getChildCount()-1);
if ( lastChild.getType()==ANTLRParser.ACTION ) {
return (ActionAST)lastChild;
}
}
return null;
}
示例14: executeShowSchema
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private void executeShowSchema(Tree statement) throws TException, InvalidRequestException
{
if (!CliMain.isConnected())
return;
printCQL3TablesWarning("show schema");
final List<KsDef> keyspaces = thriftClient.describe_keyspaces();
Collections.sort(keyspaces, new KsDefNamesComparator());
final String keyspaceName = (statement.getChildCount() == 0)
? keySpace
: CliCompiler.getKeySpace(statement, keyspaces);
Iterator<KsDef> ksIter;
if (keyspaceName != null)
ksIter = Collections2.filter(keyspaces, new Predicate<KsDef>()
{
public boolean apply(KsDef ksDef)
{
return keyspaceName.equals(ksDef.name);
}
}).iterator();
else
ksIter = keyspaces.iterator();
while (ksIter.hasNext())
showKeyspace(sessionState.out, ksIter.next());
sessionState.out.flush();
}
示例15: children
import org.antlr.runtime.tree.Tree; //導入方法依賴的package包/類
private List<Predicate<T>> children(Tree r) throws QueryParseException, IllegalArgumentException {
List<Predicate<T>> p = new ArrayList<>(r.getChildCount());
for (int i = 0; i < r.getChildCount(); i++) {
p.add(toPredicate(r.getChild(i)));
}
return p;
}