public void renderHandWrittenRuntime(String name) throws IOException { AstRoot ast = parseRuntime(name); ast.visit(new StringConstantElimination()); AstWriter astWriter = new AstWriter(writer); astWriter.hoist(ast); astWriter.print(ast); }
/** * Visits the AST nodes, then the comment nodes. * This method is equivalent to calling {@link #visit}, then * {@link #visitComments}. The return value * is ignored while visiting comment nodes. * @param visitor the callback object. */ public void visitAll(NodeVisitor visitor) { visit(visitor); visitComments(visitor); }
/** * Debugging function to check that the parser has set the parent * link for every node in the tree. * @throws IllegalStateException if a parent link is missing */ public void checkParentLinks() { this.visit(new NodeVisitor() { public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } }); } }
/** * Visits the AST nodes, then the comment nodes. * This method is equivalent to calling {@link #visit}, then * {@link #visitComments}. The return value * is ignored while visiting comment nodes. * @param visitor the callback object. */ public void visitAll(NodeVisitor visitor) { visit(visitor); visitComments(visitor); }
/** * Debugging function to check that the parser has set the parent * link for every node in the tree. * @throws IllegalStateException if a parent link is missing */ public void checkParentLinks() { this.visit(new NodeVisitor() { public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } }); } }
/** * Visits the AST nodes, then the comment nodes. * This method is equivalent to calling {@link #visit}, then * {@link #visitComments}. The return value * is ignored while visiting comment nodes. * @param visitor the callback object. */ public void visitAll(NodeVisitor visitor) { visit(visitor); visitComments(visitor); }
/** * Debugging function to check that the parser has set the parent * link for every node in the tree. * @throws IllegalStateException if a parent link is missing */ public void checkParentLinks() { this.visit(new NodeVisitor() { public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } }); } }
/** * Visits the AST nodes, then the comment nodes. * This method is equivalent to calling {@link #visit}, then * {@link #visitComments}. The return value * is ignored while visiting comment nodes. * @param visitor the callback object. */ public void visitAll(NodeVisitor visitor) { visit(visitor); visitComments(visitor); }
/** * Debugging function to check that the parser has set the parent * link for every node in the tree. * @throws IllegalStateException if a parent link is missing */ public void checkParentLinks() { this.visit(new NodeVisitor() { public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } }); } }
JavaScriptOutlineTreeGenerator(RSyntaxTextArea textArea, AstRoot ast) { this.textArea = textArea; root = new JavaScriptTreeNode((AstNode)null); if (ast!=null) { ast.visit(this); } }
root.visit(new NodeVisitor() { public boolean visit(AstNode node) {
/** * Scan the given file for class definitions and accumulate dependencies. */ private void scan(final File source) throws IOException { log.debug("Scanning: " + source); ErrorReporter errorReporter = new LogErrorReporter(log); CompilerEnvirons env = new CompilerEnvirons(); env.setErrorReporter(errorReporter); Parser parser = new Parser(env, errorReporter); Reader reader = new BufferedReader(new FileReader(source)); try { AstRoot root = parser.parse(reader, source.getAbsolutePath(), 0); DependencyAccumulator visitor = new DependencyAccumulator(source); root.visit(visitor); // complain if no def was found in this source if (visitor.current == null) { log.warn("No class definition was found while processing: " + source); } } finally { reader.close(); } }
root.visit(new NodeVisitor() { public boolean visit(AstNode node) { if (node instanceof FunctionCall) {
@Override public void actionPerformed(ActionEvent e) { JavaScriptParser parser = getParser(textArea); if (parser==null) { return; // Shouldn't happen } AstRoot astRoot = parser.getAstRoot(); if (astRoot!=null) { int dot = textArea.getCaretPosition(); visitor.reset(dot); astRoot.visit(visitor); AstNode scope = visitor.getDeepestScope(); if (scope!=null && scope!=astRoot) { int start = scope.getAbsolutePosition(); int end = Math.min(start + scope.getLength() - 1, textArea.getDocument().getLength()); try { int startLine = textArea.getLineOfOffset(start); int endLine = end<0 ? textArea.getLineCount() : textArea.getLineOfOffset(end); textArea.setActiveLineRange(startLine, endLine); } catch (BadLocationException ble) { ble.printStackTrace(); // Never happens } } else { textArea.setActiveLineRange(-1, -1); } } }