Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/Block.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 package org.mozilla.javascript.ast;
8
9 import org.mozilla.javascript.Node;
10 import org.mozilla.javascript.Token;
11
12 /**
13 * A block statement delimited by curly braces. The node position is the
14 * position of the open-curly, and the length extends to the position of
15 * the close-curly. Node type is {@link Token#BLOCK}.
16 *
17 * <pre><i>Block</i> :
18 * <b>{</b> Statement* <b>}</b></pre>
19 */
20 public class Block extends AstNode {
21
22 {
23 this.type = Token.BLOCK;
24 }
25
26 public Block() {
27 }
28
29 public Block(int pos) {
30 super(pos);
31 }
32
33 public Block(int pos, int len) {
34 super(pos, len);
35 }
36
37 /**
38 * Alias for {@link #addChild}.
39 */
40 public void addStatement(AstNode statement) {
41 addChild(statement);
42 }
43
44 @Override
45 public String toSource(int depth) {
46 StringBuilder sb = new StringBuilder();
47 sb.append(makeIndent(depth));
48 sb.append("{\n");
49 for (Node kid : this) {
50 sb.append(((AstNode)kid).toSource(depth+1));
51 }
52 sb.append(makeIndent(depth));
53 sb.append("}\n");
54 return sb.toString();
55 }
56
57 @Override
58 public void visit(NodeVisitor v) {
59 if (v.visit(this)) {
60 for (Node kid : this) {
61 ((AstNode)kid).visit(v);
62 }
63 }
64 }
65 }