本文整理汇总了Java中org.antlr.v4.runtime.tree.Tree类的典型用法代码示例。如果您正苦于以下问题:Java Tree类的具体用法?Java Tree怎么用?Java Tree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tree类属于org.antlr.v4.runtime.tree包,在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toStringTree
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
/** Print out a whole tree in LISP form. Arg nodeTextProvider is used on the
* node payloads to get the text for the nodes.
*
* @since 4.5.1
*/
public static String toStringTree(Tree t, TreeTextProvider nodeTextProvider) {
if ( t==null ) return "null";
String s = Utils.escapeWhitespace(nodeTextProvider.getText(t), false);
if ( t.getChildCount()==0 ) return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(nodeTextProvider.getText(t), false);
buf.append(s);
buf.append(' ');
for (int i = 0; i<t.getChildCount(); i++) {
if ( i>0 ) buf.append(' ');
buf.append(toStringTree(t.getChild(i), nodeTextProvider));
}
buf.append(")");
return buf.toString();
}
示例2: iterator
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
@Override
public Iterator<Tree> iterator() {
return new Iterator<Tree>() {
private int i = 0;
@Override
public boolean hasNext() {
return tree.getChildCount() > i;
}
@Override
public Tree next() {
if (!hasNext())
throw new NoSuchElementException();
return tree.getChild(i++);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
示例3: generateEdges
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
protected void generateEdges(Tree parent) {
if (!getTree().isLeaf(parent)) {
Rectangle2D.Double parentBounds = getBoundsOfNode(parent);
// System.out.println("%% parent("+getText(parent)+")="+parentBounds);
double x1 = parentBounds.getCenterX();
double y1 = parentBounds.y;
for (Tree child : getChildren(parent)) {
Rectangle2D.Double childBounds = getBoundsOfNode(child);
// System.out.println("%% child("+getText(child)+")="+childBounds);
double x2 = childBounds.getCenterX();
double y2 = childBounds.getMaxY();
doc.line(x1, y1, x2, y2);
generateEdges(child);
}
}
}
示例4: setTree
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public void setTree(Tree root) {
if ( root!=null ) {
boolean useIdentity = true; // compare node identity
this.treeLayout =
new TreeLayout<Tree>(getTreeLayoutAdaptor(root),
new TreeViewer.VariableExtentProvide(this),
new DefaultConfiguration<Tree>(gapBetweenLevels,
gapBetweenNodes),
useIdentity);
// Let the UI display this new AST.
updatePreferredSize();
}
else {
this.treeLayout = null;
repaint();
}
}
示例5: toStringTree
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
private String toStringTree(Tree tree, List<String> ruleNames) {
String s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
if(tree.getChildCount() == 0) return s;
StringBuilder buf = new StringBuilder();
buf.append("(");
s = Utils.escapeWhitespace(getNodeText(tree, ruleNames), false);
buf.append(s);
buf.append(' ');
for(int i = 0; i < tree.getChildCount(); i++)
{
if(i > 0)
buf.append(' ');
buf.append(toStringTree(tree.getChild(i), ruleNames));
}
buf.append(")");
return buf.toString();
}
示例6: dumpAST
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public static void dumpAST(PrintWriter printer, Tree ast, int ident) {
char[] identChars = new char[ident];
Arrays.fill(identChars, ' ');
if (ast == null) {
renderNode(identChars, null, printer);
return;
}
for (int i = 0; i < ast.getChildCount(); i++) {
Tree node = ast.getChild(i);
if (node == null) {
throw new NullPointerException("Null AST node");
}
renderNode(identChars, node, printer);
dumpAST(printer, node, ident + 2);
}
}
示例7: getOnTriggerSetAssignments
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
protected static List<OnTriggerSetAssignment> getOnTriggerSetAssignments(EsperEPL2GrammarParser.OnSetAssignmentListContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
if (ctx == null || ctx.onSetAssignment().isEmpty()) {
return Collections.emptyList();
}
List<EsperEPL2GrammarParser.OnSetAssignmentContext> ctxs = ctx.onSetAssignment();
List<OnTriggerSetAssignment> assignments = new ArrayList<OnTriggerSetAssignment>(ctx.onSetAssignment().size());
for (EsperEPL2GrammarParser.OnSetAssignmentContext assign : ctxs) {
ExprNode childEvalNode;
if (assign.eventProperty() != null) {
ExprNode prop = ASTExprHelper.exprCollectSubNodes(assign.eventProperty(), 0, astExprNodeMap).get(0);
ExprNode value = ASTExprHelper.exprCollectSubNodes(assign.expression(), 0, astExprNodeMap).get(0);
ExprEqualsNode equals = new ExprEqualsNodeImpl(false, false);
equals.addChildNode(prop);
equals.addChildNode(value);
childEvalNode = equals;
} else {
childEvalNode = ASTExprHelper.exprCollectSubNodes(assign, 0, astExprNodeMap).get(0);
}
assignments.add(new OnTriggerSetAssignment(childEvalNode));
}
return assignments;
}
示例8: mathGetExpr
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public static ExprNode mathGetExpr(ParseTree ctx, Map<Tree, ExprNode> astExprNodeMap, ConfigurationInformation configurationInformation) {
int count = 1;
ExprNode base = ASTExprHelper.exprCollectSubNodes(ctx.getChild(0), 0, astExprNodeMap).get(0);
while (true) {
int token = ASTUtil.getAssertTerminatedTokenType(ctx.getChild(count));
MathArithTypeEnum mathArithTypeEnum = tokenToMathEnum(token);
ExprNode right = ASTExprHelper.exprCollectSubNodes(ctx.getChild(count + 1), 0, astExprNodeMap).get(0);
ExprMathNode math = new ExprMathNode(mathArithTypeEnum,
configurationInformation.getEngineDefaults().getExpression().isIntegerDivision(),
configurationInformation.getEngineDefaults().getExpression().isDivisionByZeroReturnsNull());
math.addChildNode(base);
math.addChildNode(right);
base = math;
count += 2;
if (count >= ctx.getChildCount()) {
break;
}
}
return base;
}
示例9: walkCreateDataFlow
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public static CreateDataFlowDesc walkCreateDataFlow(EsperEPL2GrammarParser.CreateDataflowContext ctx, Map<Tree, Object> astGraphNodeMap, EngineImportService engineImportService) {
String graphName = ctx.name.getText();
List<GraphOperatorSpec> ops = new ArrayList<GraphOperatorSpec>();
List<CreateSchemaDesc> schemas = new ArrayList<CreateSchemaDesc>();
List<EsperEPL2GrammarParser.GopContext> gopctxs = ctx.gopList().gop();
for (EsperEPL2GrammarParser.GopContext gopctx : gopctxs) {
if (gopctx.createSchemaExpr() != null) {
schemas.add(ASTCreateSchemaHelper.walkCreateSchema(gopctx.createSchemaExpr()));
} else {
ops.add(parseOp(gopctx, astGraphNodeMap, engineImportService));
}
}
return new CreateDataFlowDesc(graphName, ops, schemas);
}
示例10: getExprNodesLibFunc
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public static List<ExprNode> getExprNodesLibFunc(EsperEPL2GrammarParser.LibFunctionArgsContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
if (ctx == null) {
return Collections.emptyList();
}
List<EsperEPL2GrammarParser.LibFunctionArgItemContext> args = ctx.libFunctionArgItem();
if (args == null || args.isEmpty()) {
return Collections.emptyList();
}
List<ExprNode> parameters = new ArrayList<ExprNode>(args.size());
for (EsperEPL2GrammarParser.LibFunctionArgItemContext arg : args) {
if (arg.expressionLambdaDecl() != null) {
List<String> lambdaparams = getLambdaGoesParams(arg.expressionLambdaDecl());
ExprLambdaGoesNode goes = new ExprLambdaGoesNode(lambdaparams);
ExprNode lambdaExpr = ASTExprHelper.exprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap).get(0);
goes.addChildNode(lambdaExpr);
parameters.add(goes);
} else {
ExprNode parameter = ASTExprHelper.exprCollectSubNodes(arg.expressionWithNamed(), 0, astExprNodeMap).get(0);
parameters.add(parameter);
}
}
return parameters;
}
示例11: walk
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public static CreateIndexDesc walk(EsperEPL2GrammarParser.CreateIndexExprContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
String indexName = ctx.n.getText();
String windowName = ctx.w.getText();
boolean unique = false;
if (ctx.u != null) {
String ident = ctx.u.getText();
if (ident.toLowerCase(Locale.ENGLISH).trim().equals("unique")) {
unique = true;
} else {
throw ASTWalkException.from("Invalid keyword '" + ident + "' in create-index encountered, expected 'unique'");
}
}
List<CreateIndexItem> columns = new ArrayList<>();
List<EsperEPL2GrammarParser.CreateIndexColumnContext> cols = ctx.createIndexColumnList().createIndexColumn();
for (EsperEPL2GrammarParser.CreateIndexColumnContext col : cols) {
CreateIndexItem item = walk(col, astExprNodeMap);
columns.add(item);
}
return new CreateIndexDesc(unique, indexName, windowName, columns);
}
示例12: walkOptionalRepeat
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public static RowRegexExprRepeatDesc walkOptionalRepeat(EsperEPL2GrammarParser.MatchRecogPatternRepeatContext ctx, Map<Tree, ExprNode> astExprNodeMap) {
if (ctx == null) {
return null;
}
ExprNode e1 = ctx.e1 == null ? null : ASTExprHelper.exprCollectSubNodes(ctx.e1, 0, astExprNodeMap).get(0);
ExprNode e2 = ctx.e2 == null ? null : ASTExprHelper.exprCollectSubNodes(ctx.e2, 0, astExprNodeMap).get(0);
if (ctx.comma == null && ctx.e1 != null) {
return new RowRegexExprRepeatDesc(null, null, e1);
}
if (e1 == null && e2 == null) {
throw ASTWalkException.from("Invalid match-recognize quantifier '" + ctx.getText() + "', expecting an expression");
}
return new RowRegexExprRepeatDesc(e1, e2, null);
}
示例13: testGetPropertyName
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
public void testGetPropertyName() throws Exception {
final String PROPERTY = "a('aa').b[1].c";
// Should parse and result in the exact same property name
Pair<Tree, CommonTokenStream> parsed = SupportParserHelper.parseEventProperty(PROPERTY);
Tree propertyNameExprNode = parsed.getFirst().getChild(0);
ASTUtil.dumpAST(propertyNameExprNode);
String propertyName = ((RuleNode) propertyNameExprNode).getText();
assertEquals(PROPERTY, propertyName);
// Try AST with tokens separated, same property name
parsed = SupportParserHelper.parseEventProperty("a( 'aa' ). b [ 1 ] . c");
propertyNameExprNode = parsed.getFirst().getChild(0);
propertyName = ((RuleNode) propertyNameExprNode).getText();
assertEquals(PROPERTY, propertyName);
}
示例14: getCurrentEditorElement
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
/** From editor's cursor, find associated parse tree node so we can highlight
* in structure view. It wants the parse tree node not a
* StructureViewTreeElement. It will try to find a path from root to
* that node and highlight it.
*/
@Nullable
public Object getCurrentEditorElement() {
if (editor==null) return null;
final int offset = editor.getCaretModel().getOffset();
if ( parseTree==null ) return null;
Tree selectedNode = Trees.findNodeSuchThat(parseTree, new Predicate<Tree>() {
@Override
public boolean test(Tree node) {
if ( !(node instanceof TerminalNode) ) return false;
Token t = ((TerminalNode) node).getSymbol();
return offset>=t.getStartIndex() && offset<=t.getStopIndex();
}
});
if ( selectedNode==null ) return null;
// now walk up looking for template def node
ParseTree p = (ParseTree)selectedNode;
while ( p!=null && !(p instanceof STGParser.TemplateContext) ) {
p = p.getParent();
}
if ( p!=null ) {
return ((STGParser.TemplateContext)p).ID(0);
}
return null;
}
示例15: toStringTree
import org.antlr.v4.runtime.tree.Tree; //导入依赖的package包/类
private String toStringTree(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
if (t.getChildCount() == 0) {
return Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
}
StringBuilder buf = new StringBuilder();
buf.append(" ( ");
String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), true);
buf.append(s);
buf.append(' ');
for (int i = 0; i < t.getChildCount(); i++) {
if (i > 0) {
buf.append(' ');
}
buf.append(toStringTree(t.getChild(i), ruleNames));
}
buf.append(" ) ");
return buf.toString();
}