Refine search
@Override public void exitUnaryOpExpr(ExprParser.UnaryOpExprContext ctx) { int opCode = ((TerminalNode) ctx.getChild(0)).getSymbol().getType(); switch (opCode) { case ExprParser.MINUS: nodes.put(ctx, new UnaryMinusExpr((Expr) nodes.get(ctx.getChild(1)))); break; case ExprParser.NOT: nodes.put(ctx, new UnaryNotExpr((Expr) nodes.get(ctx.getChild(1)))); break; default: throw new RuntimeException("Unrecognized unary operator " + ctx.getChild(0).getText()); } }
private void nameDeclaration(DeclarationRuleContext ctx) { ParseTree t = findChildrenByType(ctx.getChild(3).getChild(0), ClassNameExpressionContext.class); if (t != null) { String ttype = t.getText().trim(); AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getChild(1).getText()); registry.addCandidate(c); if (GroovyCompletionTypes.debug) logger.info("define variable of type " + ctx.getChild(1).getText() + " " + ttype); if (ttype != null) classUtils.defineVariable(ctx.getChild(1).getText(), ttype); } }
/** * Gets token type of ParseTree node from JavadocTokenTypes class. * @param node ParseTree node. * @return token type from JavadocTokenTypes */ private static int getTokenType(ParseTree node) { final int tokenType; if (node.getChildCount() == 0) { tokenType = ((TerminalNode) node).getSymbol().getType(); } else { final String className = getNodeClassNameWithoutContext(node); final String typeName = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, className); tokenType = JavadocUtil.getTokenId(typeName); } return tokenType; }
/** * Gets last child of a parse tree node. * * @param ctx A node * @return Last child of a node, or null if node has no children */ public static ParseTree getLastChild(ParseTree ctx) { if (ctx.getChildCount() == 0) { return null; } return ctx.getChild(ctx.getChildCount() - 1); }
/** * Gets next sibling of ParseTree node. * @param node ParseTree node * @return next sibling of ParseTree node. */ private static ParseTree getNextSibling(ParseTree node) { ParseTree nextSibling = null; if (node.getParent() != null) { final ParseTree parent = node.getParent(); int index = 0; while (true) { final ParseTree currentNode = parent.getChild(index); if (currentNode.equals(node)) { nextSibling = parent.getChild(index + 1); break; } index++; } } return nextSibling; }
/** * Returns node's index with in its parent's child array. * * @param node A child node * @return Node's index or -1 if node is null or doesn't have a parent */ public static int getNodeIndex(ParseTree node) { if (node == null || node.getParent() == null) { return -1; } ParseTree parent = node.getParent(); for (int i = 0; i < parent.getChildCount(); i++) { if (parent.getChild(i) == node) { return i; } } return -1; }
private ExpressionSegment extractFunctionExpressionSegment(final ParserRuleContext functionNode) { return new FunctionExpressionSegment(functionNode.getChild(0).getText(), functionNode.getStart().getStartIndex(), ((TerminalNode) functionNode.getChild(1)).getSymbol().getStartIndex(), functionNode.getStop().getStopIndex(), -1); }
CompilationUnitContext cuc = (CompilationUnitContext) arg0.getParent(); List<ParseTree> children = cuc.children; int tokenIndex = arg0.getSymbol().getTokenIndex(); if (tokenIndex - 2 >= 0 && tokenIndex + 1 <= children.size()) { ParseTree variablePT = children.get(tokenIndex - 2); ParseTree typePT = children.get(tokenIndex + 1); String type = typePT.getText(); String variable = variablePT.getText(); AutocompleteCandidate c1 = new AutocompleteCandidate(JavaCompletionTypes.NAME, variable); registry.addCandidate(c1); ParseTree chld = arg0.getParent().getChild(arg0.getParent().getChildCount() - 1); if (!chld.equals(arg0)) return; addQuery(classUtils.expandExpression(arg0.getParent().getText(), registry, classUtils.DO_NON_STATIC), cursor); } else if (arg0.getParent() instanceof TypeDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof CompilationUnitContext) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText()); addQuery(c, cursor); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext && arg0.getParent().getParent().getParent() != null && arg0.getParent().getParent().getParent() instanceof ClassBodyContext && arg0.getParent().getParent().getParent().getText().trim().startsWith("<missing '{'>")) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.CLASSLEVEL, arg0.getText()); addQuery(c, cursor); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null &&
private SelectItemSegment extractFunctionSelectItemSegment(final ParserRuleContext expressionNode, final ParserRuleContext functionNode) { String functionName = functionNode.getChild(0).getText(); Optional<AggregationType> aggregationType = findAggregationType(functionName); AliasAvailable result = aggregationType.isPresent() ? extractAggregationSelectItemSegment(aggregationType.get(), functionNode) : new ExpressionSelectItemSegment(functionNode.getText(), functionNode.getStart().getStartIndex(), functionNode.getStop().getStopIndex()); Optional<ParserRuleContext> aliasNode = ExtractorUtils.findFirstChildNode(expressionNode, RuleName.ALIAS); if (aliasNode.isPresent()) { result.setAlias(aliasNode.get().getText()); } return (SelectItemSegment) result; }
@Override public AstNode visitDirective_call(Directive_callContext ctx) { Token token = ((TerminalNode) ctx.getChild(0)).getSymbol(); Position position = new Position(token.getLine(), token.getCharPositionInLine() + 6); String name = ctx.getChild(0).getText(); name = StringUtils.substringBetween(name, " ", "(").trim(); AstExpressionList expressionList = accept(ctx.expression_list()); return new AstDirectiveCall(name, expressionList, position); }
ParseTree mismatchedNode = null; if ( t1.getSymbol().getType() == t2.getSymbol().getType() ) { if ( t2.getSymbol() instanceof TokenTagToken ) { // x and <ID> TokenTagToken tokenTagToken = (TokenTagToken)t2.getSymbol(); if ( ruleTagToken!=null ) { ParseTreeMatch m = null; if ( r1.getRuleContext().getRuleIndex() == r2.getRuleContext().getRuleIndex() ) { if ( r1.getChildCount()!=r2.getChildCount() ) { if (mismatchedNode == null) { mismatchedNode = r1; int n = r1.getChildCount(); for (int i = 0; i<n; i++) { ParseTree childMatch = matchImpl(r1.getChild(i), patternTree.getChild(i), labels); if ( childMatch != null ) { return childMatch;
@Override public Collection<OrderByItemSegment> extract(final ParserRuleContext ancestorNode) { Collection<OrderByItemSegment> result = new LinkedList<>(); for (ParserRuleContext each : ExtractorUtils.getAllDescendantNodes(ancestorNode, RuleName.ORDER_BY_ITEM)) { OrderDirection orderDirection = 2 == each.getChildCount() && OrderDirection.DESC.name().equalsIgnoreCase(each.getChild(1).getText()) ? OrderDirection.DESC : OrderDirection.ASC; Optional<ParserRuleContext> indexNode = ExtractorUtils.findFirstChildNode(each, RuleName.NUMBER); if (indexNode.isPresent()) { result.add(new IndexOrderByItemSegment(NumberUtil.getExactlyNumber(indexNode.get().getText(), 10).intValue(), orderDirection, OrderDirection.ASC)); continue; } Optional<ParserRuleContext> expressionNode = ExtractorUtils.findFirstChildNode(each, RuleName.EXPR); if (expressionNode.isPresent()) { result.add(new ExpressionOrderByItemSegment(expressionNode.get().getText(), orderDirection, OrderDirection.ASC)); continue; } Optional<ParserRuleContext> columnNameNode = ExtractorUtils.findFirstChildNode(each, RuleName.COLUMN_NAME); if (columnNameNode.isPresent()) { result.add(new ColumnNameOrderByItemSegment(columnNameNode.get().getText(), ((ParserRuleContext) each.getChild(0)).getStart().getStartIndex(), orderDirection, OrderDirection.ASC)); } } return result; } }
private static Token verifyToken(final ParseTree parent, final int offset, final int expected) { final TerminalNode node = verifyTerminal(parent.getChild(offset)); final Token ret = node.getSymbol(); final int type = ret.getType(); verify(type == expected, "Item %s has type %s, expected %s", node, type, expected); return ret; }
public Object process(TemplateInterpreter interpreter, TemplateFromContext templateFromContext, TinyTemplateParser.Expr_field_accessContext parseTree, TemplateContext pageContext, TemplateContext context, TemplateEngineDefault engine, OutputStream outputStream, String fileName) throws Exception { Object a = interpreter.interpretTree(engine, templateFromContext, parseTree.expression(), pageContext, context, outputStream, fileName); String fieldName = parseTree.IDENTIFIER().getSymbol().getText(); try { if (parseTree.getChild(1).getText().startsWith("?")) { return TemplateUtil.sp(a, fieldName); } else { return TemplateUtil.getAttribute(a, fieldName); } } catch (Exception e) { throw new TemplateException("参数取值失败", parseTree, fileName); } }
public static void _findAllNodes(ParseTree t, int index, boolean findTokens, List<? super ParseTree> nodes) { // check this node (the root) first if ( findTokens && t instanceof TerminalNode ) { TerminalNode tnode = (TerminalNode)t; if ( tnode.getSymbol().getType()==index ) nodes.add(t); } else if ( !findTokens && t instanceof ParserRuleContext ) { ParserRuleContext ctx = (ParserRuleContext)t; if ( ctx.getRuleIndex() == index ) nodes.add(t); } // check children for (int i = 0; i < t.getChildCount(); i++){ _findAllNodes(t.getChild(i), index, findTokens, nodes); } }
ctx.getChild(0) instanceof TypeDeclarationContext && ctx.getChild(3) instanceof ExpressionContext && ctx.getChild(3).getChildCount() > 0) { if (!ctx.getChild(1).getText().contains(".")) { if (ctx.getChild(3).getChild(0) instanceof PathExpressionContext) { String typpen = ctx.getChild(3).getChild(0).getText().trim(); AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getChild(1).getText()); registry.addCandidate(c); if (GroovyCompletionTypes.debug) logger.info("define variable of type " + ctx.getChild(1).getText() + " " + typpen); if (classUtils.getVariableType(typpen) != null) { classUtils.defineVariable(ctx.getChild(1).getText(), classUtils.getVariableType(typpen)); } else if (ctx.getChild(3).getChild(0) instanceof NewInstanceRuleContext) { nameDeclaration(ctx); } else { if (GroovyCompletionTypes.debug) System.out.println(((ExpressionContext) ctx.getChild(3)).getStart().getType()); AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getChild(1).getText()); registry.addCandidate(c); if (GroovyCompletionTypes.debug) logger.info("define variable of type " + ctx.getChild(1).getText() + " " + typpen); if (typpen != null) classUtils.defineVariable(ctx.getChild(1).getText(), typpen);
@SuppressWarnings("unused") private String buildFunctionBody(ExpressionBodyContext expressionBodyContext){ StringBuffer sb=new StringBuffer(); for(ParseTree node:expressionBodyContext.children){ Interval interval=node.getSourceInterval(); int index=interval.a; List<Token> leftTokens=tokenStream.getHiddenTokensToLeft(index); if(leftTokens!=null){ Token token=leftTokens.get(0); String text=token.getText(); sb.append(text); } sb.append(node.getText()); List<Token> rightTokens=tokenStream.getHiddenTokensToRight(index); if(rightTokens!=null){ Token token=rightTokens.get(0); String text=token.getText(); sb.append(text); } } return sb.toString(); }
private String getDistinctExpression(final ParserRuleContext functionNode) { StringBuilder result = new StringBuilder(); for (int i = 3; i < functionNode.getChildCount() - 1; i++) { result.append(functionNode.getChild(i).getText()); } return result.toString(); } }
@Override public void enterFunctionCall(@NotNull PQL2Parser.FunctionCallContext ctx) { String expression = _expression.substring(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex() + 1); pushNode(new FunctionCallAstNode(ctx.getChild(0).getText(), expression)); }