本文整理匯總了Java中org.antlr.v4.runtime.RuleContext.getChildCount方法的典型用法代碼示例。如果您正苦於以下問題:Java RuleContext.getChildCount方法的具體用法?Java RuleContext.getChildCount怎麽用?Java RuleContext.getChildCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.antlr.v4.runtime.RuleContext
的用法示例。
在下文中一共展示了RuleContext.getChildCount方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChildContextText
import org.antlr.v4.runtime.RuleContext; //導入方法依賴的package包/類
/**
* Searches the children of the given context for a context of the given clazz
* type and returns its Text Value. If there are multiple relevant child nodes,
* we will return the text value for one of them at random.
*/
public String getChildContextText(RuleContext ctx) {
if (ctx == null) {
return "";
}
if (ctx instanceof TypeNameContext) {
return ctx.getText();
}
String s = "";
for (int i = 0; i < ctx.getChildCount(); i++) {
if (!(ctx.getChild(i) instanceof TerminalNodeImpl)) {
try {
String t = getChildContextText((RuleContext) ctx.getChild(i));
if (!t.isEmpty()) {
s += t + ",";
}
} catch (Exception e) {
// do nothing
}
}
}
return s.replaceAll(",$", "");
}
示例2: findLeftSibling
import org.antlr.v4.runtime.RuleContext; //導入方法依賴的package包/類
private ParseTree findLeftSibling(RuleContext ctx) {
RuleContext p = ctx.getParent();
if(p!=null) {
for(int i=0; i<p.getChildCount(); i++) {
if(p.getChild(i).equals(ctx)) {
if(i>0)
return p.getChild(i-1);
break;
}
}
}
return null;
}
示例3: searchTokenFromHead
import org.antlr.v4.runtime.RuleContext; //導入方法依賴的package包/類
private Token searchTokenFromHead(RuleContext ctx, SilverstripeTokenId token) {
for(int i=0; i<ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if(child instanceof TerminalNode && ((TerminalNode)child).getSymbol().getType() == token.getId()) {
return ((TerminalNode)child).getSymbol();
}
}
throw new IllegalArgumentException("Illegal arguments");
}
示例4: searchTokenFromTail
import org.antlr.v4.runtime.RuleContext; //導入方法依賴的package包/類
private Token searchTokenFromTail(RuleContext ctx, SilverstripeTokenId token) {
for(int i=ctx.getChildCount()-1; i>=0; i--) {
ParseTree child = ctx.getChild(i);
if(child instanceof TerminalNode && ((TerminalNode)child).getSymbol().getType() == token.getId()) {
return ((TerminalNode)child).getSymbol();
}
}
throw new IllegalArgumentException("Illegal arguments");
}