List of usage examples for org.antlr.v4.runtime.tree ParseTree accept
<T> T accept(ParseTreeVisitor<? extends T> visitor);
From source file:android.databinding.tool.ExpressionVisitor.java
License:Apache License
@Override public Expr visitMethodInvocation(@NotNull BindingExpressionParser.MethodInvocationContext ctx) { try {/* w w w.j a v a 2 s . co m*/ onEnter(ctx); List<Expr> args = new ArrayList<Expr>(); if (ctx.args != null) { for (ParseTree item : ctx.args.children) { if (ObjectUtils.equals(item.getText(), ",")) { continue; } args.add(item.accept(this)); } } return mModel.methodCall(ctx.target.accept(this), ctx.Identifier().getText(), args); } finally { onExit(ctx); } }
From source file:android.databinding.tool.ExpressionVisitor.java
License:Apache License
@Override public Expr visitResources(@NotNull BindingExpressionParser.ResourcesContext ctx) { try {/*from w ww . j ava 2s . c o m*/ onEnter(ctx); final List<Expr> args = new ArrayList<Expr>(); if (ctx.resourceParameters() != null) { for (ParseTree item : ctx.resourceParameters().expressionList().children) { if (ObjectUtils.equals(item.getText(), ",")) { continue; } args.add(item.accept(this)); } } final String resourceReference = ctx.ResourceReference().getText(); final int colonIndex = resourceReference.indexOf(':'); final int slashIndex = resourceReference.indexOf('/'); final String packageName = colonIndex < 0 ? null : resourceReference.substring(1, colonIndex).trim(); final int startIndex = Math.max(1, colonIndex + 1); final String resourceType = resourceReference.substring(startIndex, slashIndex).trim(); final String resourceName = resourceReference.substring(slashIndex + 1).trim(); return mModel.resourceExpr(packageName, resourceType, resourceName, args); } finally { onExit(ctx); } }
From source file:codemate.Fortran.FortranTemplater.java
License:Open Source License
/** * visitChildren//w ww .ja va 2s. co m * * This method overrides the original one which will be interfered when I * make changes to the parse tree (e.g. inserting multiple nodes) by * changing the loop style. */ public Void visitChildren(RuleNode node) { Void result = defaultResult(); for (int i = 0; i < node.getChildCount(); i++) { if (!shouldVisitNextChild(node, result)) break; ParseTree c = node.getChild(i); Void childResult = c.accept(this); result = aggregateResult(result, childResult); } return result; }
From source file:com.blazebit.persistence.impl.expression.JPQLSelectExpressionVisitorImpl.java
License:Apache License
BinaryExpressionPredicate handleComparison(ParseTree left, ParseTree comparisonOperator, ParseTree right) { BinaryExpressionPredicate pred = (BinaryExpressionPredicate) comparisonOperator.accept(this); pred.setLeft(left.accept(this)); pred.setRight(right.accept(this)); return pred;//ww w.j a v a2s .c o m }
From source file:com.blazebit.persistence.impl.expression.JPQLSelectExpressionVisitorImpl.java
License:Apache License
private CompositeExpression acceptAndCompose(CompositeExpression composite, ParseTree ruleContext) { Expression expr = ruleContext.accept(this); if (expr != null) { composite.append(expr);//from www . ja va 2 s . c o m } return composite; }
From source file:com.blazebit.persistence.impl.expression.JPQLSelectExpressionVisitorImpl.java
License:Apache License
private CompositeExpression accept(ParseTree ruleContext) { Expression expr = ruleContext.accept(this); CompositeExpression composite;/*from w ww .jav a 2s .com*/ if (expr instanceof CompositeExpression) { composite = (CompositeExpression) expr; } else { composite = new CompositeExpression(new ArrayList<Expression>(Arrays.asList(expr))); } return composite; }
From source file:com.blazebit.persistence.parser.expression.JPQLSelectExpressionVisitorImpl.java
License:Apache License
BinaryExpressionPredicate handleQuantifiedComparison(ParseTree left, ParseTree comparisonOperator, ParseTree right, PredicateQuantifier quantifier) { QuantifiableBinaryExpressionPredicate pred = (QuantifiableBinaryExpressionPredicate) comparisonOperator .accept(this); pred.setLeft(left.accept(this)); pred.setRight(right.accept(this)); pred.setQuantifier(quantifier);/*w ww . j a v a 2 s .co m*/ return pred; }
From source file:com.boothen.jsonedit.outline.JsonLabelProvider.java
License:Open Source License
@Override public Image getImage(Object element) { if (element instanceof ParseTree) { ParseTree context = (ParseTree) element; return context.accept(contextImageVisitor); }//w w w .j a v a 2s . co m return null; }
From source file:com.boothen.jsonedit.quickoutline.QuickOutlinePopup.java
License:Open Source License
@Override public void setInput(Object input) { ParseTree parseTree = (ParseTree) input; treeViewer.setInput(new Container<ParseTree>(parseTree)); filterText.setText(""); // In theory, it should be possible to derive the parent, // but this is not trivial and needs to be reliable contentProvider.refreshParents(parseTree); final ISelection selection = sourceViewer.getSelectionProvider().getSelection(); // try to find the element that contains the text cursor in sourceViewer and pre-select it if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; int start = textSelection.getOffset(); int length = textSelection.getLength(); PositionVisitor positionVisitor = new PositionVisitor(); Map<ParseTree, Position> positions = parseTree.accept(positionVisitor); ParseTree element = parseTree.accept(new JsonContextTokenFinder(start, start + length, positions)); // similar code exists in JsonContentOutlinePage while (element != null && !contentProvider.isKnown(element)) { element = element.getParent(); }//from ww w . j a va 2s .com if (element != null) { treeViewer.reveal(element); treeViewer.setSelection(new TreeSelection(new TreePath(new Object[] { element }))); } } treeViewer.expandAll(); }
From source file:com.github.gfx.android.orma.migration.sqliteparser.SQLiteCreateTableStatementCollector.java
License:Apache License
static String combineParseTree(ParseTree node) { return node.accept(new AbstractParseTreeVisitor<StringBuilder>() { final StringBuilder sb = new StringBuilder(); @Override//from w w w .ja v a 2s. c o m protected StringBuilder defaultResult() { return sb; } @Override public StringBuilder visitTerminal(TerminalNode node) { if (sb.length() != 0) { sb.append(' '); } sb.append(node.getText()); return sb; } }).toString(); }