当前位置: 首页>>代码示例>>Java>>正文


Java Tree类代码示例

本文整理汇总了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();
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:22,代码来源:Trees.java

示例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();
		}
	};
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:25,代码来源:TreeLayoutAdaptor.java

示例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);
			}
		}
	}
 
开发者ID:antlr,项目名称:codebuff,代码行数:17,代码来源:TreePostScriptGenerator.java

示例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();
	}
}
 
开发者ID:antlr,项目名称:codebuff,代码行数:18,代码来源:TreeViewer.java

示例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();
}
 
开发者ID:processquerying,项目名称:PQL,代码行数:20,代码来源:AbstractPQLQuery.java

示例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);
    }
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:18,代码来源:ASTUtil.java

示例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;
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:23,代码来源:ASTExprHelper.java

示例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;
    }
 
开发者ID:espertechinc,项目名称:esper,代码行数:26,代码来源:ASTExprHelper.java

示例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);
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:17,代码来源:ASTGraphHelper.java

示例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;
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:24,代码来源:ASTLibFunctionHelper.java

示例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);
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:23,代码来源:ASTIndexHelper.java

示例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);
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:19,代码来源:ASTMatchRecognizeHelper.java

示例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);
}
 
开发者ID:espertechinc,项目名称:esper,代码行数:17,代码来源:TestASTFilterSpecHelper.java

示例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;
}
 
开发者ID:antlr,项目名称:jetbrains-plugin-st4,代码行数:30,代码来源:STGroupStructureViewModel.java

示例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();
}
 
开发者ID:antlr4ide,项目名称:antlr4ide,代码行数:19,代码来源:ParseTreeCommand.java


注:本文中的org.antlr.v4.runtime.tree.Tree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。