@cparra/apex-reflection 0.1.0-alpha.0 → 0.1.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/__tests__/end-to-end.test.ts +256 -0
  2. package/coverage/clover.xml +12857 -0
  3. package/coverage/coverage-final.json +3 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +79 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +126 -0
  8. package/coverage/lcov-report/index.js.html +104 -0
  9. package/coverage/lcov-report/out.js.html +41126 -0
  10. package/coverage/lcov-report/prettify.css +1 -0
  11. package/coverage/lcov-report/prettify.js +2 -0
  12. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  13. package/coverage/lcov-report/sorter.js +170 -0
  14. package/coverage/lcov.info +24801 -0
  15. package/index.d.ts +118 -0
  16. package/index.js +8 -0
  17. package/index.ts +141 -0
  18. package/jest.config.js +11 -0
  19. package/out.js +13708 -0
  20. package/package.json +22 -17
  21. package/tsconfig.json +5 -3
  22. package/.idea/apexdocs-dart.iml +0 -18
  23. package/.idea/jsLibraryMappings.xml +0 -6
  24. package/.idea/libraries/Dart_Packages.xml +0 -556
  25. package/.idea/libraries/Dart_SDK.xml +0 -28
  26. package/.idea/misc.xml +0 -6
  27. package/.idea/modules.xml +0 -8
  28. package/.idea/runConfigurations/_template__of_Dart_Test.xml +0 -6
  29. package/.idea/vcs.xml +0 -6
  30. package/CHANGELOG.md +0 -3
  31. package/README.md +0 -26
  32. package/TODO.md +0 -5
  33. package/analysis_options.yaml +0 -30
  34. package/antlr4-4.9.2/CHANGELOG.md +0 -4
  35. package/antlr4-4.9.2/LICENSE +0 -52
  36. package/antlr4-4.9.2/README.md +0 -11
  37. package/antlr4-4.9.2/analysis_options.yaml +0 -1
  38. package/antlr4-4.9.2/lib/antlr4.dart +0 -21
  39. package/antlr4-4.9.2/lib/src/atn/atn.dart +0 -18
  40. package/antlr4-4.9.2/lib/src/atn/src/atn.dart +0 -170
  41. package/antlr4-4.9.2/lib/src/atn/src/atn_config.dart +0 -242
  42. package/antlr4-4.9.2/lib/src/atn/src/atn_config_set.dart +0 -283
  43. package/antlr4-4.9.2/lib/src/atn/src/atn_deserializer.dart +0 -809
  44. package/antlr4-4.9.2/lib/src/atn/src/atn_simulator.dart +0 -95
  45. package/antlr4-4.9.2/lib/src/atn/src/atn_state.dart +0 -296
  46. package/antlr4-4.9.2/lib/src/atn/src/atn_type.dart +0 -14
  47. package/antlr4-4.9.2/lib/src/atn/src/info.dart +0 -553
  48. package/antlr4-4.9.2/lib/src/atn/src/lexer_action.dart +0 -601
  49. package/antlr4-4.9.2/lib/src/atn/src/lexer_action_executor.dart +0 -167
  50. package/antlr4-4.9.2/lib/src/atn/src/lexer_atn_simulator.dart +0 -731
  51. package/antlr4-4.9.2/lib/src/atn/src/parser_atn_simulator.dart +0 -2630
  52. package/antlr4-4.9.2/lib/src/atn/src/profiling_atn_simulator.dart +0 -229
  53. package/antlr4-4.9.2/lib/src/atn/src/semantic_context.dart +0 -404
  54. package/antlr4-4.9.2/lib/src/atn/src/transition.dart +0 -305
  55. package/antlr4-4.9.2/lib/src/dfa/dfa.dart +0 -8
  56. package/antlr4-4.9.2/lib/src/dfa/src/dfa.dart +0 -138
  57. package/antlr4-4.9.2/lib/src/dfa/src/dfa_serializer.dart +0 -76
  58. package/antlr4-4.9.2/lib/src/dfa/src/dfa_state.dart +0 -151
  59. package/antlr4-4.9.2/lib/src/error/error.dart +0 -10
  60. package/antlr4-4.9.2/lib/src/error/src/diagnostic_error_listener.dart +0 -116
  61. package/antlr4-4.9.2/lib/src/error/src/error_listener.dart +0 -241
  62. package/antlr4-4.9.2/lib/src/error/src/error_strategy.dart +0 -902
  63. package/antlr4-4.9.2/lib/src/error/src/errors.dart +0 -204
  64. package/antlr4-4.9.2/lib/src/input_stream.dart +0 -335
  65. package/antlr4-4.9.2/lib/src/interval_set.dart +0 -735
  66. package/antlr4-4.9.2/lib/src/lexer.dart +0 -343
  67. package/antlr4-4.9.2/lib/src/ll1_analyzer.dart +0 -204
  68. package/antlr4-4.9.2/lib/src/misc/multi_map.dart +0 -32
  69. package/antlr4-4.9.2/lib/src/misc/pair.dart +0 -34
  70. package/antlr4-4.9.2/lib/src/parser.dart +0 -777
  71. package/antlr4-4.9.2/lib/src/parser_interpreter.dart +0 -393
  72. package/antlr4-4.9.2/lib/src/parser_rule_context.dart +0 -275
  73. package/antlr4-4.9.2/lib/src/prediction_context.dart +0 -877
  74. package/antlr4-4.9.2/lib/src/recognizer.dart +0 -182
  75. package/antlr4-4.9.2/lib/src/rule_context.dart +0 -192
  76. package/antlr4-4.9.2/lib/src/runtime_meta_data.dart +0 -188
  77. package/antlr4-4.9.2/lib/src/token.dart +0 -431
  78. package/antlr4-4.9.2/lib/src/token_factory.dart +0 -88
  79. package/antlr4-4.9.2/lib/src/token_source.dart +0 -241
  80. package/antlr4-4.9.2/lib/src/token_stream.dart +0 -627
  81. package/antlr4-4.9.2/lib/src/tree/src/pattern/chunk.dart +0 -90
  82. package/antlr4-4.9.2/lib/src/tree/src/pattern/parse_tree_match.dart +0 -635
  83. package/antlr4-4.9.2/lib/src/tree/src/tree.dart +0 -370
  84. package/antlr4-4.9.2/lib/src/tree/src/trees.dart +0 -226
  85. package/antlr4-4.9.2/lib/src/tree/tree.dart +0 -10
  86. package/antlr4-4.9.2/lib/src/util/bit_set.dart +0 -308
  87. package/antlr4-4.9.2/lib/src/util/murmur_hash.dart +0 -77
  88. package/antlr4-4.9.2/lib/src/util/utils.dart +0 -31
  89. package/antlr4-4.9.2/lib/src/vocabulary.dart +0 -254
  90. package/antlr4-4.9.2/pubspec.yaml +0 -13
  91. package/example/node_example/index.js +0 -8
  92. package/example/node_example/package.json +0 -12
  93. package/example/node_example_ts/package-lock.json +0 -70
  94. package/example/node_example_ts/package.json +0 -19
  95. package/example/node_example_ts/src/index.js +0 -5
  96. package/example/node_example_ts/src/index.ts +0 -9
  97. package/example/node_example_ts/tsconfig.json +0 -79
  98. package/js/dart2jsout.js +0 -25898
  99. package/js/dart2jsout.js.map +0 -16
  100. package/js/index.d.ts +0 -1
  101. package/js/index.js +0 -4
  102. package/js/out.js +0 -26023
  103. package/js/out.js.map +0 -16
  104. package/js/package-lock.json +0 -57
  105. package/js/preamble.js +0 -125
  106. package/lib/apexdocs_dart.dart +0 -28
  107. package/lib/src/antlr/grammars/Apexdoc/ApexdocLexer.g4 +0 -120
  108. package/lib/src/antlr/grammars/Apexdoc/ApexdocParser.g4 +0 -158
  109. package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.interp +0 -95
  110. package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.java +0 -238
  111. package/lib/src/antlr/grammars/Apexdoc/gen/ApexdocLexer.tokens +0 -23
  112. package/lib/src/antlr/grammars/apex/ApexLexer.g4 +0 -255
  113. package/lib/src/antlr/grammars/apex/ApexParser.g4 +0 -567
  114. package/lib/src/antlr/grammars/apex/examples/ApexClass.cls +0 -6
  115. package/lib/src/antlr/lib/apex/ApexLexer.dart +0 -1223
  116. package/lib/src/antlr/lib/apex/ApexLexer.interp +0 -393
  117. package/lib/src/antlr/lib/apex/ApexLexer.tokens +0 -212
  118. package/lib/src/antlr/lib/apex/ApexParser.dart +0 -9349
  119. package/lib/src/antlr/lib/apex/ApexParser.interp +0 -326
  120. package/lib/src/antlr/lib/apex/ApexParser.tokens +0 -212
  121. package/lib/src/antlr/lib/apex/ApexParserBaseListener.dart +0 -1036
  122. package/lib/src/antlr/lib/apex/ApexParserListener.dart +0 -975
  123. package/lib/src/antlr/lib/apexdoc/ApexdocLexer.dart +0 -373
  124. package/lib/src/antlr/lib/apexdoc/ApexdocLexer.interp +0 -95
  125. package/lib/src/antlr/lib/apexdoc/ApexdocLexer.tokens +0 -23
  126. package/lib/src/antlr/lib/apexdoc/ApexdocParser.dart +0 -2471
  127. package/lib/src/antlr/lib/apexdoc/ApexdocParser.interp +0 -69
  128. package/lib/src/antlr/lib/apexdoc/ApexdocParser.tokens +0 -23
  129. package/lib/src/antlr/lib/apexdoc/ApexdocParserBaseListener.dart +0 -252
  130. package/lib/src/antlr/lib/apexdoc/ApexdocParserListener.dart +0 -215
  131. package/lib/src/builders/builders.dart +0 -32
  132. package/lib/src/model/apex_file_manifest.dart +0 -37
  133. package/lib/src/model/apex_file_manifest.g.dart +0 -18
  134. package/lib/src/model/declaration.dart +0 -50
  135. package/lib/src/model/doc_comment.dart +0 -117
  136. package/lib/src/model/doc_comment.g.dart +0 -118
  137. package/lib/src/model/members.dart +0 -143
  138. package/lib/src/model/members.g.dart +0 -105
  139. package/lib/src/model/types.dart +0 -159
  140. package/lib/src/model/types.g.dart +0 -111
  141. package/lib/src/service/apex_listener.dart +0 -226
  142. package/lib/src/service/apexdoc_listener.dart +0 -82
  143. package/lib/src/service/parsers.dart +0 -33
  144. package/lib/src/service/utils/parsing/access_modifiers_parser.dart +0 -33
  145. package/lib/src/service/utils/parsing/parameters_parser.dart +0 -18
  146. package/lib/src/service/utils/parsing/parsing_utils.dart +0 -2
  147. package/lib/src/service/walker.dart +0 -82
  148. package/pubspec.yaml +0 -19
  149. package/test/apex_file_manifest_test.dart +0 -16
  150. package/test/apex_listener_test.dart +0 -703
  151. package/test/apexdoc_parser_test.dart +0 -179
  152. package/test/doc_comment_test.dart +0 -89
  153. package/test/members_serialization_test.dart +0 -158
  154. package/test/members_test.dart +0 -178
  155. package/test/types_serialization_test.dart +0 -191
  156. package/test/types_test.dart +0 -311
  157. package/test/walker_test.dart +0 -58
  158. package/tool/grind.dart +0 -20
@@ -1,370 +0,0 @@
1
- /*
2
- * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
3
- * Use of this file is governed by the BSD 3-clause license that
4
- * can be found in the LICENSE.txt file in the project root.
5
- */
6
-
7
- import 'dart:developer';
8
-
9
- import '../../interval_set.dart';
10
- import '../../parser.dart';
11
- import '../../parser_rule_context.dart';
12
- import '../../rule_context.dart';
13
- import '../../token.dart';
14
-
15
- /// The basic notion of a tree has a parent, a payload, and a list of children.
16
- /// It is the most abstract interface for all the trees used by ANTLR.
17
- abstract class Tree {
18
- Tree get parent;
19
-
20
- dynamic get payload;
21
-
22
- Tree getChild<T>(int i);
23
-
24
- // Tree getChild(int i);
25
-
26
- int get childCount;
27
-
28
- String toStringTree();
29
- }
30
-
31
- abstract class SyntaxTree extends Tree {
32
- /// Return an [Interval] indicating the index in the
33
- /// [TokenStream] of the first and last token associated with this
34
- /// subtree. If this node is a leaf, then the interval represents a single
35
- /// token and has interval i..i for token index i.
36
- ///
37
- /// <p>An interval of i..i-1 indicates an empty interval at position
38
- /// i in the input stream, where 0 &lt;= i &lt;= the size of the input
39
- /// token stream. Currently, the code base can only have i=0..n-1 but
40
- /// in concept one could have an empty interval after EOF. </p>
41
- ///
42
- /// <p>If source interval is unknown, this returns {@link Interval#INVALID}.</p>
43
- ///
44
- /// <p>As a weird special case, the source interval for rules matched after
45
- /// EOF is unspecified.</p>
46
- Interval get sourceInterval;
47
- }
48
-
49
- abstract class ParseTree extends SyntaxTree {
50
- // the following methods narrow the return type; they are not additional methods
51
- @override
52
- ParseTree get parent;
53
-
54
- @override
55
- ParseTree getChild<T>(int i);
56
-
57
- /// Set the parent for this node.
58
- ///
59
- /// This is not backward compatible as it changes
60
- /// the interface but no one was able to create custom
61
- /// nodes anyway so I'm adding as it improves internal
62
- /// code quality.
63
- ///
64
- /// One could argue for a restructuring of
65
- /// the class/interface hierarchy so that
66
- /// setParent, addChild are moved up to Tree
67
- /// but that's a major change. So I'll do the
68
- /// minimal change, which is to add this method.
69
- ///
70
- /// @since 4.7
71
- set parent(RuleContext parent);
72
-
73
- /// The [ParseTreeVisitor] needs a double dispatch method. */
74
- T accept<T>(ParseTreeVisitor<T> visitor);
75
-
76
- /// Return the combined text of all leaf nodes. Does not get any
77
- /// off-channel tokens (if any) so won't return whitespace and
78
- /// comments if they are sent to parser on hidden channel.
79
- String get text;
80
-
81
- /// Specialize toStringTree so that it can print out more information
82
- /// based upon the parser.
83
- @override
84
- String toStringTree({Parser parser});
85
- }
86
-
87
- abstract class RuleNode extends ParseTree {
88
- RuleContext get ruleContext;
89
- }
90
-
91
- abstract class TerminalNode extends ParseTree {
92
- Token get symbol;
93
- }
94
-
95
- abstract class ErrorNode extends TerminalNode {}
96
-
97
- abstract class ParseTreeVisitor<T> {
98
- /// {@inheritDoc}
99
- ///
100
- /// <p>The default implementation calls {@link ParseTree#accept} on the
101
- /// specified tree.</p>
102
- T visit(ParseTree tree) {
103
- return tree.accept(this);
104
- }
105
-
106
- /// {@inheritDoc}
107
- ///
108
- /// <p>The default implementation initializes the aggregate result to
109
- /// {@link #defaultResult defaultResult()}. Before visiting each child, it
110
- /// calls {@link #shouldVisitNextChild shouldVisitNextChild}; if the result
111
- /// is [false] no more children are visited and the current aggregate
112
- /// result is returned. After visiting a child, the aggregate result is
113
- /// updated by calling {@link #aggregateResult aggregateResult} with the
114
- /// previous aggregate result and the result of visiting the child.</p>
115
- ///
116
- /// <p>The default implementation is not safe for use in visitors that modify
117
- /// the tree structure. Visitors that modify the tree should override this
118
- /// method to behave properly in respect to the specific algorithm in use.</p>
119
- T visitChildren(RuleNode node) {
120
- var result = defaultResult();
121
- final n = node.childCount;
122
- for (var i = 0; i < n; i++) {
123
- if (!shouldVisitNextChild(node, result)) {
124
- break;
125
- }
126
-
127
- final c = node.getChild(i);
128
- final childResult = c.accept(this);
129
- result = aggregateResult(result, childResult);
130
- }
131
-
132
- return result;
133
- }
134
-
135
- /// {@inheritDoc}
136
- ///
137
- /// <p>The default implementation returns the result of
138
- /// {@link #defaultResult defaultResult}.</p>
139
-
140
- T visitTerminal(TerminalNode node) {
141
- return defaultResult();
142
- }
143
-
144
- /// {@inheritDoc}
145
- ///
146
- /// <p>The default implementation returns the result of
147
- /// {@link #defaultResult defaultResult}.</p>
148
-
149
- T visitErrorNode(ErrorNode node) {
150
- return defaultResult();
151
- }
152
-
153
- /// Gets the default value returned by visitor methods. This value is
154
- /// returned by the default implementations of
155
- /// {@link #visitTerminal visitTerminal}, {@link #visitErrorNode visitErrorNode}.
156
- /// The default implementation of {@link #visitChildren visitChildren}
157
- /// initializes its aggregate result to this value.
158
- ///
159
- /// <p>The base implementation returns null.</p>
160
- ///
161
- /// @return The default value returned by visitor methods.
162
- T defaultResult() {
163
- return null;
164
- }
165
-
166
- /// Aggregates the results of visiting multiple children of a node. After
167
- /// either all children are visited or {@link #shouldVisitNextChild} returns
168
- /// [false], the aggregate value is returned as the result of
169
- /// {@link #visitChildren}.
170
- ///
171
- /// <p>The default implementation returns [nextResult], meaning
172
- /// {@link #visitChildren} will return the result of the last child visited
173
- /// (or return the initial value if the node has no children).</p>
174
- ///
175
- /// @param aggregate The previous aggregate value. In the default
176
- /// implementation, the aggregate value is initialized to
177
- /// {@link #defaultResult}, which is passed as the [aggregate] argument
178
- /// to this method after the first child node is visited.
179
- /// @param nextResult The result of the immediately preceeding call to visit
180
- /// a child node.
181
- ///
182
- /// @return The updated aggregate result.
183
- T aggregateResult(T aggregate, T nextResult) => nextResult;
184
-
185
- /// This method is called after visiting each child in
186
- /// {@link #visitChildren}. This method is first called before the first
187
- /// child is visited; at that point [currentResult] will be the initial
188
- /// value (in the default implementation, the initial value is returned by a
189
- /// call to {@link #defaultResult}. This method is not called after the last
190
- /// child is visited.
191
- ///
192
- /// <p>The default implementation always returns [true], indicating that
193
- /// [visitChildren] should only return after all children are visited.
194
- /// One reason to override this method is to provide a "short circuit"
195
- /// evaluation option for situations where the result of visiting a single
196
- /// child has the potential to determine the result of the visit operation as
197
- /// a whole.</p>
198
- ///
199
- /// @param node The [RuleNode] whose children are currently being
200
- /// visited.
201
- /// @param currentResult The current aggregate result of the children visited
202
- /// to the current point.
203
- ///
204
- /// @return [true] to continue visiting children. Otherwise return
205
- /// [false] to stop visiting children and immediately return the
206
- /// current aggregate result from {@link #visitChildren}.
207
- bool shouldVisitNextChild(RuleNode node, T currentResult) => true;
208
- }
209
-
210
- abstract class ParseTreeListener {
211
- void visitTerminal(TerminalNode node);
212
-
213
- void visitErrorNode(ErrorNode node);
214
-
215
- void enterEveryRule(ParserRuleContext node);
216
-
217
- void exitEveryRule(ParserRuleContext node);
218
- }
219
-
220
- class TraceListener implements ParseTreeListener {
221
- final Parser parser;
222
-
223
- TraceListener(this.parser);
224
-
225
- @override
226
- void enterEveryRule(ParserRuleContext ctx) {
227
- log('enter ' +
228
- parser.ruleNames[ctx.ruleIndex] +
229
- ', LT(1)=${parser.inputStream.LT(1).text}');
230
- }
231
-
232
- @override
233
- void visitTerminal(TerminalNode node) {
234
- log('consume ${node.symbol} rule ' +
235
- parser.ruleNames[parser.context.ruleIndex]);
236
- }
237
-
238
- @override
239
- void visitErrorNode(ErrorNode node) {}
240
-
241
- @override
242
- void exitEveryRule(ParserRuleContext ctx) {
243
- log('exit ${parser.ruleNames[ctx.ruleIndex]}' ', LT(1)=' +
244
- parser.inputStream.LT(1).text);
245
- }
246
- }
247
-
248
- class TrimToSizeListener implements ParseTreeListener {
249
- static final TrimToSizeListener INSTANCE = TrimToSizeListener();
250
-
251
- @override
252
- void enterEveryRule(ParserRuleContext ctx) {}
253
-
254
- @override
255
- void visitTerminal(TerminalNode node) {}
256
-
257
- @override
258
- void visitErrorNode(ErrorNode node) {}
259
-
260
- @override
261
- void exitEveryRule(ParserRuleContext ctx) {
262
- // TODO trim dart List's size
263
- // if (ctx.children is List) {
264
- // (ctx.children).trimToSize();
265
- // }
266
- }
267
- }
268
-
269
- class TerminalNodeImpl extends TerminalNode {
270
- @override
271
- Token symbol;
272
- @override
273
- ParseTree parent;
274
-
275
- TerminalNodeImpl(this.symbol);
276
-
277
- @override
278
- ParseTree getChild<T>(i) {
279
- return null;
280
- }
281
-
282
- @override
283
- Token get payload => symbol;
284
-
285
- @override
286
- Interval get sourceInterval {
287
- if (symbol == null) return Interval.INVALID;
288
-
289
- final tokenIndex = symbol.tokenIndex;
290
- return Interval(tokenIndex, tokenIndex);
291
- }
292
-
293
- @override
294
- int get childCount {
295
- return 0;
296
- }
297
-
298
- @override
299
- T accept<T>(ParseTreeVisitor<T> visitor) {
300
- return visitor.visitTerminal(this);
301
- }
302
-
303
- @override
304
- String get text {
305
- return symbol.text;
306
- }
307
-
308
- @override
309
- String toStringTree({Parser parser}) {
310
- return toString();
311
- }
312
-
313
- @override
314
- String toString() {
315
- if (symbol.type == Token.EOF) return '<EOF>';
316
- return symbol.text;
317
- }
318
- }
319
-
320
- /// Represents a token that was consumed during resynchronization
321
- /// rather than during a valid match operation. For example,
322
- /// we will create this kind of a node during single token insertion
323
- /// and deletion as well as during "consume until error recovery set"
324
- /// upon no viable alternative exceptions.
325
- class ErrorNodeImpl extends TerminalNodeImpl implements ErrorNode {
326
- ErrorNodeImpl(token) : super(token);
327
-
328
- bool isErrorNode() => true;
329
-
330
- @override
331
- T accept<T>(ParseTreeVisitor<T> visitor) {
332
- return visitor.visitErrorNode(this);
333
- }
334
- }
335
-
336
- class ParseTreeWalker {
337
- void walk(ParseTreeListener listener, ParseTree t) {
338
- if (t is ErrorNode) {
339
- listener.visitErrorNode(t);
340
- return;
341
- } else if (t is TerminalNode) {
342
- listener.visitTerminal(t);
343
- return;
344
- }
345
- RuleNode r = t;
346
- enterRule(listener, r);
347
- for (var i = 0; i < r.childCount; i++) {
348
- walk(listener, r.getChild(i));
349
- }
350
- exitRule(listener, r);
351
- }
352
-
353
- /// The discovery of a rule node, involves sending two events: the generic
354
- /// {@link ParseTreeListener#enterEveryRule} and a
355
- /// [RuleContext]-specific event. First we trigger the generic and then
356
- /// the rule specific. We to them in reverse order upon finishing the node.
357
- void enterRule(ParseTreeListener listener, RuleNode r) {
358
- ParserRuleContext ctx = r.ruleContext;
359
- listener.enterEveryRule(ctx);
360
- ctx.enterRule(listener);
361
- }
362
-
363
- void exitRule(ParseTreeListener listener, RuleNode r) {
364
- ParserRuleContext ctx = r.ruleContext;
365
- ctx.exitRule(listener);
366
- listener.exitEveryRule(ctx);
367
- }
368
-
369
- static final DEFAULT = ParseTreeWalker();
370
- }
@@ -1,226 +0,0 @@
1
- /*
2
- * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
3
- * Use of this file is governed by the BSD 3-clause license that
4
- * can be found in the LICENSE.txt file in the project root.
5
- */
6
-
7
- import 'dart:core';
8
-
9
- import '../../atn/atn.dart';
10
- import '../../parser.dart';
11
- import '../../parser_rule_context.dart';
12
- import '../../rule_context.dart';
13
- import '../../token.dart';
14
- import '../../util/utils.dart';
15
- import 'tree.dart';
16
-
17
- /// A set of utility routines useful for all kinds of ANTLR trees. */
18
- class Trees {
19
- /// Print out a whole tree in LISP form. {@link #getNodeText} is used on the
20
- /// node payloads to get the text for the nodes. Detect
21
- /// parse trees and extract data appropriately.
22
- static String toStringTree(Tree t, {Parser recog, List<String> ruleNames}) {
23
- ruleNames ??= recog?.ruleNames;
24
- var s = escapeWhitespace(getNodeText(t, ruleNames: ruleNames), false);
25
- if (t.childCount == 0) return s;
26
- final buf = StringBuffer();
27
- buf.write('(');
28
- s = escapeWhitespace(getNodeText(t, ruleNames: ruleNames), false);
29
- buf.write(s);
30
- buf.write(' ');
31
- for (var i = 0; i < t.childCount; i++) {
32
- if (i > 0) buf.write(' ');
33
- buf.write(toStringTree(t.getChild(i), ruleNames: ruleNames));
34
- }
35
- buf.write(')');
36
- return buf.toString();
37
- }
38
-
39
- static String getNodeText(Tree t, {Parser recog, List<String> ruleNames}) {
40
- ruleNames ??= recog?.ruleNames;
41
- if (ruleNames != null) {
42
- if (t is RuleContext) {
43
- final ruleIndex = t.ruleContext.ruleIndex;
44
- final ruleName = ruleNames[ruleIndex];
45
- final altNumber = t.altNumber;
46
- if (altNumber != ATN.INVALID_ALT_NUMBER) {
47
- return ruleName + ':$altNumber';
48
- }
49
- return ruleName;
50
- } else if (t is ErrorNode) {
51
- return t.toString();
52
- } else if (t is TerminalNode) {
53
- final symbol = (t).symbol;
54
- if (symbol != null) {
55
- final s = symbol.text;
56
- return s;
57
- }
58
- }
59
- }
60
- // no recog for rule names
61
- Object payload = t.payload;
62
- if (payload is Token) {
63
- return payload.text;
64
- }
65
- return t.payload.toString();
66
- }
67
-
68
- /// Return ordered list of all children of this node */
69
- static List<Tree> getChildren(Tree t) {
70
- final kids = <Tree>[];
71
- for (var i = 0; i < t.childCount; i++) {
72
- kids.add(t.getChild(i));
73
- }
74
- return kids;
75
- }
76
-
77
- /// Return a list of all ancestors of this node. The first node of
78
- /// list is the root and the last is the parent of this node.
79
- ///
80
- /// @since 4.5.1
81
- static List<Tree> getAncestors(Tree t) {
82
- if (t.parent == null) return [];
83
- final ancestors = <Tree>[];
84
- t = t.parent;
85
- while (t != null) {
86
- ancestors.insert(0, t); // insert at start
87
- t = t.parent;
88
- }
89
- return ancestors;
90
- }
91
-
92
- /// Return true if t is u's parent or a node on path to root from u.
93
- /// Use == not equals().
94
- ///
95
- /// @since 4.5.1
96
- static bool isAncestorOf(Tree t, Tree u) {
97
- if (t == null || u == null || t.parent == null) return false;
98
- var p = u.parent;
99
- while (p != null) {
100
- if (t == p) return true;
101
- p = p.parent;
102
- }
103
- return false;
104
- }
105
-
106
- static List<ParseTree> findAllTokenNodes(ParseTree t, int ttype) {
107
- return findAllNodes(t, ttype, true);
108
- }
109
-
110
- static List<ParseTree> findAllRuleNodes(ParseTree t, int ruleIndex) {
111
- return findAllNodes(t, ruleIndex, false);
112
- }
113
-
114
- static List<ParseTree> findAllNodes(ParseTree t, int index, bool findTokens) {
115
- final nodes = <ParseTree>[];
116
- _findAllNodes(t, index, findTokens, nodes);
117
- return nodes;
118
- }
119
-
120
- static void _findAllNodes(
121
- ParseTree t, int index, bool findTokens, List<ParseTree> nodes) {
122
- // check this node (the root) first
123
- if (findTokens && t is TerminalNode) {
124
- final tnode = t;
125
- if (tnode.symbol.type == index) nodes.add(t);
126
- } else if (!findTokens && t is ParserRuleContext) {
127
- final ctx = t;
128
- if (ctx.ruleIndex == index) nodes.add(t);
129
- }
130
- // check children
131
- for (var i = 0; i < t.childCount; i++) {
132
- _findAllNodes(t.getChild(i), index, findTokens, nodes);
133
- }
134
- }
135
-
136
- /// Get all descendents; includes t itself.
137
- ///
138
- /// @since 4.5.1
139
- static List<ParseTree> getDescendants(ParseTree t) {
140
- final nodes = <ParseTree>[];
141
- nodes.add(t);
142
-
143
- final n = t.childCount;
144
- for (var i = 0; i < n; i++) {
145
- nodes.addAll(getDescendants(t.getChild(i)));
146
- }
147
- return nodes;
148
- }
149
-
150
- /// @deprecated */
151
- static List<ParseTree> descendants(ParseTree t) {
152
- return getDescendants(t);
153
- }
154
-
155
- /// Find smallest subtree of t enclosing range startTokenIndex..stopTokenIndex
156
- /// inclusively using postorder traversal. Recursive depth-first-search.
157
- ///
158
- /// @since 4.5.1
159
- static ParserRuleContext getRootOfSubtreeEnclosingRegion(
160
- ParseTree t,
161
- int startTokenIndex, // inclusive
162
- int stopTokenIndex) // inclusive
163
- {
164
- final n = t.childCount;
165
- for (var i = 0; i < n; i++) {
166
- final child = t.getChild(i);
167
- final r = getRootOfSubtreeEnclosingRegion(
168
- child, startTokenIndex, stopTokenIndex);
169
- if (r != null) return r;
170
- }
171
- if (t is ParserRuleContext) {
172
- final r = t;
173
- if (startTokenIndex >=
174
- r.start.tokenIndex && // is range fully contained in t?
175
- (r.stop == null || stopTokenIndex <= r.stop.tokenIndex)) {
176
- // note: r.getStop()==null likely implies that we bailed out of parser and there's nothing to the right
177
- return r;
178
- }
179
- }
180
- return null;
181
- }
182
-
183
- /// Replace any subtree siblings of root that are completely to left
184
- /// or right of lookahead range with a CommonToken(Token.INVALID_TYPE,"...")
185
- /// node. The source interval for t is not altered to suit smaller range!
186
- ///
187
- /// WARNING: destructive to t.
188
- ///
189
- /// @since 4.5.1
190
- static void stripChildrenOutOfRange(ParserRuleContext t,
191
- ParserRuleContext root, int startIndex, int stopIndex) {
192
- if (t == null) return;
193
- for (var i = 0; i < t.childCount; i++) {
194
- final child = t.getChild(i);
195
- final range = child.sourceInterval;
196
- if (child is ParserRuleContext &&
197
- (range.b < startIndex || range.a > stopIndex)) {
198
- if (isAncestorOf(child, root)) {
199
- // replace only if subtree doesn't have displayed root
200
- final abbrev = CommonToken(Token.INVALID_TYPE, text: '...');
201
- t.children[i] = TerminalNodeImpl(abbrev);
202
- }
203
- }
204
- }
205
- }
206
-
207
- /// Return first node satisfying the pred
208
- ///
209
- /// @since 4.5.1
210
- static Tree findNodeSuchThat(Tree t, Predicate<Tree> pred) {
211
- if (pred.test(t)) return t;
212
-
213
- if (t == null) return null;
214
-
215
- final n = t.childCount;
216
- for (var i = 0; i < n; i++) {
217
- final u = findNodeSuchThat(t.getChild(i), pred);
218
- if (u != null) return u;
219
- }
220
- return null;
221
- }
222
- }
223
-
224
- abstract class Predicate<T> {
225
- bool test(T t);
226
- }
@@ -1,10 +0,0 @@
1
- /*
2
- * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
3
- * Use of this file is governed by the BSD 3-clause license that
4
- * can be found in the LICENSE.txt file in the project root.
5
- */
6
-
7
- export 'src/pattern/chunk.dart';
8
- export 'src/pattern/parse_tree_match.dart';
9
- export 'src/tree.dart';
10
- export 'src/trees.dart';