MCPcopy Create free account
hub / github.com/mozilla/rhino / AstNode

Class AstNode

rhino/src/main/java/org/mozilla/javascript/ast/AstNode.java:53–623  ·  view source on GitHub ↗

Base class for AST node types. The goal of the AST is to represent the physical source code, to make it useful for code-processing tools such as IDEs or pretty-printers. The parser must not rewrite the parse tree when producing this representation. The AstNode hierarchy sits atop the old

Source from the content-addressed store, hash-verified

51 * distinction in JavaScript is not as clear-cut as in Java or C++.
52 */
53public abstract class AstNode extends Node implements Comparable<AstNode> {
54
55 protected int position = -1;
56 protected int length = 1;
57 protected AstNode parent;
58 /*
59 * Holds comments that are on same line as of actual statement e.g.
60 * For a for loop
61 * 1) for(var i=0; i<10; i++) //test comment { }
62 * 2) for(var i=0; i<10; i++)
63 * //test comment
64 * //test comment 2
65 * { }
66 * For If Statement
67 * 1) if (x == 2) //test if comment
68 * a = 3 + 4; //then comment
69 * and so on
70 */
71 protected AstNode inlineComment;
72 private static final Map<Integer, String> operatorNames = new HashMap<>();
73
74 private static final int MAX_INDENT = 42;
75 private static final String[] INDENTATIONS = new String[MAX_INDENT + 1];
76
77 static {
78 operatorNames.put(Token.IN, "in");
79 operatorNames.put(Token.TYPEOF, "typeof");
80 operatorNames.put(Token.INSTANCEOF, "instanceof");
81 operatorNames.put(Token.DELPROP, "delete");
82 operatorNames.put(Token.COMMA, ",");
83 operatorNames.put(Token.COLON, ":");
84 operatorNames.put(Token.OR, "||");
85 operatorNames.put(Token.NULLISH_COALESCING, "??");
86 operatorNames.put(Token.QUESTION_DOT, "?.");
87 operatorNames.put(Token.AND, "&&");
88 operatorNames.put(Token.INC, "++");
89 operatorNames.put(Token.DEC, "--");
90 operatorNames.put(Token.BITOR, "|");
91 operatorNames.put(Token.BITXOR, "^");
92 operatorNames.put(Token.BITAND, "&");
93 operatorNames.put(Token.EQ, "==");
94 operatorNames.put(Token.NE, "!=");
95 operatorNames.put(Token.LT, "<");
96 operatorNames.put(Token.GT, ">");
97 operatorNames.put(Token.LE, "<=");
98 operatorNames.put(Token.GE, ">=");
99 operatorNames.put(Token.LSH, "<<");
100 operatorNames.put(Token.RSH, ">>");
101 operatorNames.put(Token.URSH, ">>>");
102 operatorNames.put(Token.ADD, "+");
103 operatorNames.put(Token.SUB, "-");
104 operatorNames.put(Token.MUL, "*");
105 operatorNames.put(Token.DIV, "/");
106 operatorNames.put(Token.MOD, "%");
107 operatorNames.put(Token.EXP, "**");
108 operatorNames.put(Token.NOT, "!");
109 operatorNames.put(Token.BITNOT, "~");
110 operatorNames.put(Token.POS, "+");

Callers

nothing calls this directly

Calls 3

putMethod · 0.65
toStringMethod · 0.65
appendMethod · 0.65

Tested by

no test coverage detected