@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,735 +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:math';
8
-
9
- import 'package:collection/collection.dart';
10
-
11
- import 'lexer.dart';
12
- import 'token.dart';
13
- import 'util/murmur_hash.dart';
14
- import 'vocabulary.dart';
15
-
16
- /// An immutable inclusive interval a..b */
17
- class Interval {
18
- static final int INTERVAL_POOL_MAX_VALUE = 1000;
19
-
20
- static final Interval INVALID = Interval(-1, -2);
21
-
22
- static List<Interval> cache = List<Interval>(INTERVAL_POOL_MAX_VALUE + 1);
23
-
24
- int a;
25
- int b;
26
-
27
- static int creates = 0;
28
- static int misses = 0;
29
- static int hits = 0;
30
- static int outOfRange = 0;
31
-
32
- Interval(this.a, this.b);
33
-
34
- /// Interval objects are used readonly so share all with the
35
- /// same single value a==b up to some max size. Use an array as a perfect hash.
36
- /// Return shared object for 0..INTERVAL_POOL_MAX_VALUE or a new
37
- /// Interval object with a..a in it. On Java.g4, 218623 IntervalSets
38
- /// have a..a (set with 1 element).
39
- static Interval of(int a, int b) {
40
- // cache just a..a
41
- if (a != b || a < 0 || a > INTERVAL_POOL_MAX_VALUE) {
42
- return Interval(a, b);
43
- }
44
- if (cache[a] == null) {
45
- cache[a] = Interval(a, a);
46
- }
47
- return cache[a];
48
- }
49
-
50
- /// return number of elements between a and b inclusively. x..x is length 1.
51
- /// if b &lt; a, then length is 0. 9..10 has length 2.
52
- int get length {
53
- if (b < a) return 0;
54
- return b - a + 1;
55
- }
56
-
57
- @override
58
- bool operator ==(Object o) {
59
- if (o == null || !(o is Interval)) {
60
- return false;
61
- }
62
- Interval other = o;
63
- return a == other.a && b == other.b;
64
- }
65
-
66
- @override
67
- int get hashCode {
68
- var hash = 23;
69
- hash = hash * 31 + a;
70
- hash = hash * 31 + b;
71
- return hash;
72
- }
73
-
74
- /// Does this start completely before other? Disjoint */
75
- bool startsBeforeDisjoint(Interval other) {
76
- return a < other.a && b < other.a;
77
- }
78
-
79
- /// Does this start at or before other? Nondisjoint */
80
- bool startsBeforeNonDisjoint(Interval other) {
81
- return a <= other.a && b >= other.a;
82
- }
83
-
84
- /// Does this.a start after other.b? May or may not be disjoint */
85
- bool startsAfter(Interval other) {
86
- return a > other.a;
87
- }
88
-
89
- /// Does this start completely after other? Disjoint */
90
- bool startsAfterDisjoint(Interval other) {
91
- return a > other.b;
92
- }
93
-
94
- /// Does this start after other? NonDisjoint */
95
- bool startsAfterNonDisjoint(Interval other) {
96
- return a > other.a && a <= other.b; // this.b>=other.b implied
97
- }
98
-
99
- /// Are both ranges disjoint? I.e., no overlap? */
100
- bool disjoint(Interval other) {
101
- return startsBeforeDisjoint(other) || startsAfterDisjoint(other);
102
- }
103
-
104
- /// Are two intervals adjacent such as 0..41 and 42..42? */
105
- bool adjacent(Interval other) {
106
- return a == other.b + 1 || b == other.a - 1;
107
- }
108
-
109
- bool properlyContains(Interval other) {
110
- return other.a >= a && other.b <= b;
111
- }
112
-
113
- /// Return the interval computed from combining this and other */
114
- Interval union(Interval other) {
115
- return Interval.of(min(a, other.a), max(b, other.b));
116
- }
117
-
118
- /// Return the interval in common between this and o */
119
- Interval intersection(Interval other) {
120
- return Interval.of(max(a, other.a), min(b, other.b));
121
- }
122
-
123
- /// Return the interval with elements from this not in other;
124
- /// other must not be totally enclosed (properly contained)
125
- /// within this, which would result in two disjoint intervals
126
- /// instead of the single one returned by this method.
127
- Interval differenceNotProperlyContained(Interval other) {
128
- Interval diff;
129
- // other.a to left of this.a (or same)
130
- if (other.startsBeforeNonDisjoint(this)) {
131
- diff = Interval.of(max(a, other.b + 1), b);
132
- }
133
-
134
- // other.a to right of this.a
135
- else if (other.startsAfterNonDisjoint(this)) {
136
- diff = Interval.of(a, other.a - 1);
137
- }
138
- return diff;
139
- }
140
-
141
- @override
142
- String toString() {
143
- return '$a..$b';
144
- }
145
- }
146
-
147
- /// This class implements the [IntervalSet] backed by a sorted array of
148
- /// non-overlapping intervals. It is particularly efficient for representing
149
- /// large collections of numbers, where the majority of elements appear as part
150
- /// of a sequential range of numbers that are all part of the set. For example,
151
- /// the set { 1, 2, 3, 4, 7, 8 } may be represented as { [1, 4], [7, 8] }.
152
- ///
153
- /// <p>
154
- /// This class is able to represent sets containing any combination of values in
155
- /// the range {@link int#MIN_VALUE} to {@link int#MAX_VALUE}
156
- /// (inclusive).</p>
157
- class IntervalSet {
158
- static final IntervalSet COMPLETE_CHAR_SET =
159
- IntervalSet.ofRange(Lexer.MIN_CHAR_VALUE, Lexer.MAX_CHAR_VALUE)
160
- ..setReadonly(true);
161
-
162
- static final IntervalSet EMPTY_SET = IntervalSet([])..setReadonly(true);
163
-
164
- /// The list of sorted, disjoint intervals. */
165
- List<Interval> intervals = [];
166
-
167
- bool readonly = false;
168
-
169
- IntervalSet([List<Interval> intervals]) {
170
- this.intervals = intervals ?? [];
171
- }
172
-
173
- IntervalSet.ofSet(IntervalSet set) {
174
- addAll(set);
175
- }
176
-
177
- // TODO
178
- // IntervalSet(int... els) {
179
- //if ( els==null ) {
180
- //intervals = new ArrayList<Interval>(2); // most sets are 1 or 2 elements
181
- //}
182
- //else {
183
- //intervals = new ArrayList<Interval>(els.length);
184
- //for (int e : els) add(e);
185
- //}
186
- //}
187
-
188
- /// Create a set with a single element, el. */
189
-
190
- IntervalSet.ofOne(int a) {
191
- addOne(a);
192
- }
193
-
194
- /// Create a set with all ints within range [a..b] (inclusive) */
195
- static IntervalSet ofRange(int a, int b) {
196
- final s = IntervalSet();
197
- s.addRange(a, b);
198
- return s;
199
- }
200
-
201
- void clear() {
202
- if (readonly) throw StateError("can't alter readonly IntervalSet");
203
- intervals.clear();
204
- }
205
-
206
- /// Add a single element to the set. An isolated element is stored
207
- /// as a range el..el.
208
-
209
- void addOne(int el) {
210
- if (readonly) throw StateError("can't alter readonly IntervalSet");
211
- addRange(el, el);
212
- }
213
-
214
- /// Add interval; i.e., add all integers from a to b to set.
215
- /// If b&lt;a, do nothing.
216
- /// Keep list in sorted order (by left range value).
217
- /// If overlap, combine ranges. For example,
218
- /// If this is {1..5, 10..20}, adding 6..7 yields
219
- /// {1..5, 6..7, 10..20}. Adding 4..8 yields {1..8, 10..20}.
220
- void addRange(int a, int b) {
221
- add(Interval.of(a, b));
222
- }
223
-
224
- // copy on write so we can cache a..a intervals and sets of that
225
- void add(Interval addition) {
226
- if (readonly) throw StateError("can't alter readonly IntervalSet");
227
- //System.out.println("add "+addition+" to "+intervals.toString());
228
- if (addition.b < addition.a) {
229
- return;
230
- }
231
- for (var i = 0; i < intervals.length; i++) {
232
- final r = intervals[i];
233
- if (addition == r) {
234
- return;
235
- }
236
- if (addition.adjacent(r) || !addition.disjoint(r)) {
237
- // next to each other, make a single larger interval
238
- final bigger = addition.union(r);
239
- intervals[i] = bigger;
240
-
241
- // make sure we didn't just create an interval that
242
- // should be merged with next interval in list
243
- for (i++; i < intervals.length; i++) {
244
- final next = intervals[i];
245
- if (!bigger.adjacent(next) && bigger.disjoint(next)) {
246
- break;
247
- }
248
-
249
- // if we bump up against or overlap next, merge
250
- intervals.removeAt(i); // remove this one
251
- intervals[i - 1] =
252
- bigger.union(next); // set previous to 3 merged ones
253
- }
254
- return;
255
- }
256
- if (addition.startsBeforeDisjoint(r)) {
257
- // insert before r
258
- intervals.insert(i, addition);
259
- return;
260
- }
261
- // if disjoint and after r, a future iteration will handle it
262
-
263
- }
264
- // ok, must be after last interval (and disjoint from last interval)
265
- // just add it
266
- intervals.add(addition);
267
- }
268
-
269
- /// combine all sets in the array returned the or'd value */
270
- static IntervalSet or(List<IntervalSet> sets) {
271
- final r = IntervalSet();
272
- for (final s in sets) {
273
- r.addAll(s);
274
- }
275
- return r;
276
- }
277
-
278
- IntervalSet operator |(IntervalSet a) {
279
- final o = IntervalSet();
280
- o.addAll(this);
281
- o.addAll(a);
282
- return o;
283
- }
284
-
285
- IntervalSet addAll(IntervalSet set) {
286
- if (set == null) {
287
- return this;
288
- }
289
-
290
- if (set is IntervalSet) {
291
- final other = set;
292
- // walk set and add each interval
293
- final n = other.intervals.length;
294
- for (var i = 0; i < n; i++) {
295
- final I = other.intervals[i];
296
- addRange(I.a, I.b);
297
- }
298
- } else {
299
- for (final value in set.toList()) {
300
- addOne(value);
301
- }
302
- }
303
-
304
- return this;
305
- }
306
-
307
- IntervalSet complementRange(int minElement, int maxElement) {
308
- return complement(IntervalSet.ofRange(minElement, maxElement));
309
- }
310
-
311
- /// {@inheritDoc} */
312
- IntervalSet complement(IntervalSet vocabulary) {
313
- if (vocabulary == null || vocabulary.isNil) {
314
- return null; // nothing in common with null set
315
- }
316
- IntervalSet vocabularyIS;
317
- if (vocabulary is IntervalSet) {
318
- vocabularyIS = vocabulary;
319
- } else {
320
- vocabularyIS = IntervalSet();
321
- vocabularyIS.addAll(vocabulary);
322
- }
323
-
324
- return vocabularyIS - this;
325
- }
326
-
327
- IntervalSet operator -(IntervalSet a) {
328
- if (a == null || a.isNil) {
329
- return IntervalSet.ofSet(this);
330
- }
331
-
332
- if (a is IntervalSet) {
333
- return subtract(this, a);
334
- }
335
-
336
- final other = IntervalSet();
337
- other.addAll(a);
338
- return subtract(this, other);
339
- }
340
-
341
- /// Compute the set difference between two interval sets. The specific
342
- /// operation is {@code left - right}. If either of the input sets is
343
- /// null, it is treated as though it was an empty set.
344
- static IntervalSet subtract(IntervalSet left, IntervalSet right) {
345
- if (left == null || left.isNil) {
346
- return IntervalSet();
347
- }
348
-
349
- final result = IntervalSet.ofSet(left);
350
- if (right == null || right.isNil) {
351
- // right set has no elements; just return the copy of the current set
352
- return result;
353
- }
354
-
355
- var resultI = 0;
356
- var rightI = 0;
357
- while (
358
- resultI < result.intervals.length && rightI < right.intervals.length) {
359
- final resultInterval = result.intervals[resultI];
360
- final rightInterval = right.intervals[rightI];
361
-
362
- // operation: (resultInterval - rightInterval) and update indexes
363
-
364
- if (rightInterval.b < resultInterval.a) {
365
- rightI++;
366
- continue;
367
- }
368
-
369
- if (rightInterval.a > resultInterval.b) {
370
- resultI++;
371
- continue;
372
- }
373
-
374
- Interval beforeCurrent;
375
- Interval afterCurrent;
376
- if (rightInterval.a > resultInterval.a) {
377
- beforeCurrent = Interval(resultInterval.a, rightInterval.a - 1);
378
- }
379
-
380
- if (rightInterval.b < resultInterval.b) {
381
- afterCurrent = Interval(rightInterval.b + 1, resultInterval.b);
382
- }
383
-
384
- if (beforeCurrent != null) {
385
- if (afterCurrent != null) {
386
- // split the current interval into two
387
- result.intervals[resultI] = beforeCurrent;
388
- result.intervals.insert(resultI + 1, afterCurrent);
389
- resultI++;
390
- rightI++;
391
- continue;
392
- } else {
393
- // replace the current interval
394
- result.intervals[resultI] = beforeCurrent;
395
- resultI++;
396
- continue;
397
- }
398
- } else {
399
- if (afterCurrent != null) {
400
- // replace the current interval
401
- result.intervals[resultI] = afterCurrent;
402
- rightI++;
403
- continue;
404
- } else {
405
- // remove the current interval (thus no need to increment resultI)
406
- result.intervals.removeAt(resultI);
407
- continue;
408
- }
409
- }
410
- }
411
-
412
- // If rightI reached right.intervals.length, no more intervals to subtract from result.
413
- // If resultI reached result.intervals.length, we would be subtracting from an empty set.
414
- // Either way, we are done.
415
- return result;
416
- }
417
-
418
- /// {@inheritDoc} */
419
- IntervalSet operator +(IntervalSet other) {
420
- if (other == null) {
421
- //|| !(other is IntervalSet) ) {
422
- return null; // nothing in common with null set
423
- }
424
-
425
- final myIntervals = intervals;
426
- final theirIntervals = (other).intervals;
427
- IntervalSet intersection;
428
- final mySize = myIntervals.length;
429
- final theirSize = theirIntervals.length;
430
- var i = 0;
431
- var j = 0;
432
- // iterate down both interval lists looking for nondisjoint intervals
433
- while (i < mySize && j < theirSize) {
434
- final mine = myIntervals[i];
435
- final theirs = theirIntervals[j];
436
- //System.out.println("mine="+mine+" and theirs="+theirs);
437
- if (mine.startsBeforeDisjoint(theirs)) {
438
- // move this iterator looking for interval that might overlap
439
- i++;
440
- } else if (theirs.startsBeforeDisjoint(mine)) {
441
- // move other iterator looking for interval that might overlap
442
- j++;
443
- } else if (mine.properlyContains(theirs)) {
444
- // overlap, add intersection, get next theirs
445
- intersection ??= IntervalSet(); intersection.add(mine.intersection(theirs));
446
- j++;
447
- } else if (theirs.properlyContains(mine)) {
448
- // overlap, add intersection, get next mine
449
- intersection ??= IntervalSet(); intersection.add(mine.intersection(theirs));
450
- i++;
451
- } else if (!mine.disjoint(theirs)) {
452
- // overlap, add intersection
453
- intersection ??= IntervalSet(); intersection.add(mine.intersection(theirs));
454
- // Move the iterator of lower range [a..b], but not
455
- // the upper range as it may contain elements that will collide
456
- // with the next iterator. So, if mine=[0..115] and
457
- // theirs=[115..200], then intersection is 115 and move mine
458
- // but not theirs as theirs may collide with the next range
459
- // in thisIter.
460
- // move both iterators to next ranges
461
- if (mine.startsAfterNonDisjoint(theirs)) {
462
- j++;
463
- } else if (theirs.startsAfterNonDisjoint(mine)) {
464
- i++;
465
- }
466
- }
467
- }
468
- if (intersection == null) {
469
- return IntervalSet();
470
- }
471
- return intersection;
472
- }
473
-
474
- /// {@inheritDoc} */
475
-
476
- bool contains(int el) {
477
- final n = intervals.length;
478
- var l = 0;
479
- var r = n - 1;
480
- // Binary search for the element in the (sorted,
481
- // disjoint) array of intervals.
482
- while (l <= r) {
483
- final m = ((l + r) / 2).floor();
484
- final I = intervals[m];
485
- final a = I.a;
486
- final b = I.b;
487
- if (b < el) {
488
- l = m + 1;
489
- } else if (a > el) {
490
- r = m - 1;
491
- } else {
492
- // el >= a && el <= b
493
- return true;
494
- }
495
- }
496
- return false;
497
- }
498
-
499
- /// {@inheritDoc} */
500
-
501
- bool get isNil {
502
- return intervals == null || intervals.isEmpty;
503
- }
504
-
505
- /// Returns the maximum value contained in the set if not isNil().
506
- ///
507
- /// @return the maximum value contained in the set.
508
- /// @throws RuntimeException if set is empty
509
- int get maxElement {
510
- if (isNil) {
511
- throw StateError('set is empty');
512
- }
513
- return intervals.last.b;
514
- }
515
-
516
- /// Returns the minimum value contained in the set if not isNil().
517
- ///
518
- /// @return the minimum value contained in the set.
519
- /// @throws RuntimeException if set is empty
520
- int get minElement {
521
- if (isNil) {
522
- throw StateError('set is empty');
523
- }
524
-
525
- return intervals.first.a;
526
- }
527
-
528
- @override
529
- int get hashCode {
530
- var hash = MurmurHash.initialize();
531
- for (final I in intervals) {
532
- hash = MurmurHash.update(hash, I.a);
533
- hash = MurmurHash.update(hash, I.b);
534
- }
535
-
536
- hash = MurmurHash.finish(hash, intervals.length * 2);
537
- return hash;
538
- }
539
-
540
- /// Are two IntervalSets equal? Because all intervals are sorted
541
- /// and disjoint, equals is a simple linear walk over both lists
542
- /// to make sure they are the same. Interval.equals() is used
543
- /// by the List.equals() method to check the ranges.
544
-
545
- @override
546
- bool operator ==(Object obj) {
547
- if (obj == null || !(obj is IntervalSet)) {
548
- return false;
549
- }
550
- IntervalSet other = obj;
551
- return ListEquality().equals(intervals, other?.intervals);
552
- }
553
-
554
- @override
555
- String toString({bool elemAreChar = false, Vocabulary vocabulary}) {
556
- if (intervals == null || intervals.isEmpty) {
557
- return '{}';
558
- }
559
-
560
- final elemStr = intervals.map((Interval I) {
561
- final buf = StringBuffer();
562
- final a = I.a;
563
- final b = I.b;
564
- if (a == b) {
565
- if (vocabulary != null) {
566
- buf.write(elementName(vocabulary, a));
567
- } else {
568
- if (a == Token.EOF) {
569
- buf.write('<EOF>');
570
- } else if (elemAreChar) {
571
- buf.write("'");
572
- buf.writeCharCode(a);
573
- buf.write("'");
574
- } else {
575
- buf.write(a);
576
- }
577
- }
578
- } else {
579
- if (vocabulary != null) {
580
- for (var i = a; i <= b; i++) {
581
- if (i > a) buf.write(', ');
582
- buf.write(elementName(vocabulary, i));
583
- }
584
- } else {
585
- if (elemAreChar) {
586
- buf.write("'");
587
- buf.writeCharCode(a);
588
- buf.write("'..'");
589
- buf.writeCharCode(b);
590
- buf.write("'");
591
- } else {
592
- buf.write(a);
593
- buf.write('..');
594
- buf.write(b);
595
- }
596
- }
597
- }
598
- return buf;
599
- }).join(', ');
600
- if (length > 1) {
601
- return '{$elemStr}';
602
- }
603
- return elemStr;
604
- }
605
-
606
- String elementName(Vocabulary vocabulary, int a) {
607
- if (a == Token.EOF) {
608
- return '<EOF>';
609
- } else if (a == Token.EPSILON) {
610
- return '<EPSILON>';
611
- } else {
612
- return vocabulary.getDisplayName(a);
613
- }
614
- }
615
-
616
- int get length {
617
- var n = 0;
618
- final numIntervals = intervals.length;
619
- if (numIntervals == 1) {
620
- final firstInterval = intervals[0];
621
- return firstInterval.b - firstInterval.a + 1;
622
- }
623
- for (var i = 0; i < numIntervals; i++) {
624
- final I = intervals[i];
625
- n += (I.b - I.a + 1);
626
- }
627
- return n;
628
- }
629
-
630
- List<int> toIntegerList() {
631
- final values = List<int>(length);
632
- final n = intervals.length;
633
- for (var i = 0; i < n; i++) {
634
- final I = intervals[i];
635
- final a = I.a;
636
- final b = I.b;
637
- for (var v = a; v <= b; v++) {
638
- values.add(v);
639
- }
640
- }
641
- return values;
642
- }
643
-
644
- List<int> toList() {
645
- final values = <int>[];
646
- final n = intervals.length;
647
- for (var i = 0; i < n; i++) {
648
- final I = intervals[i];
649
- final a = I.a;
650
- final b = I.b;
651
- for (var v = a; v <= b; v++) {
652
- values.add(v);
653
- }
654
- }
655
- return values;
656
- }
657
-
658
- Set<int> toSet() {
659
- final s = <int>{};
660
- for (final I in intervals) {
661
- final a = I.a;
662
- final b = I.b;
663
- for (var v = a; v <= b; v++) {
664
- s.add(v);
665
- }
666
- }
667
- return s;
668
- }
669
-
670
- /// Get the ith element of ordered set. Used only by RandomPhrase so
671
- /// don't bother to implement if you're not doing that for a new
672
- /// ANTLR code gen target.
673
- int get(int i) {
674
- final n = intervals.length;
675
- var index = 0;
676
- for (var j = 0; j < n; j++) {
677
- final I = intervals[j];
678
- final a = I.a;
679
- final b = I.b;
680
- for (var v = a; v <= b; v++) {
681
- if (index == i) {
682
- return v;
683
- }
684
- index++;
685
- }
686
- }
687
- return -1;
688
- }
689
-
690
- void remove(int el) {
691
- if (readonly) throw StateError("can't alter readonly IntervalSet");
692
- final n = intervals.length;
693
- for (var i = 0; i < n; i++) {
694
- final I = intervals[i];
695
- final a = I.a;
696
- final b = I.b;
697
- if (el < a) {
698
- break; // list is sorted and el is before this interval; not here
699
- }
700
- // if whole interval x..x, rm
701
- if (el == a && el == b) {
702
- intervals.removeAt(i);
703
- break;
704
- }
705
- // if on left edge x..b, adjust left
706
- if (el == a) {
707
- I.a++;
708
- break;
709
- }
710
- // if on right edge a..x, adjust right
711
- if (el == b) {
712
- I.b--;
713
- break;
714
- }
715
- // if in middle a..x..b, split interval
716
- if (el > a && el < b) {
717
- // found in this interval
718
- final oldb = I.b;
719
- I.b = el - 1; // [a..x-1]
720
- addRange(el + 1, oldb); // add [x+1..b]
721
- }
722
- }
723
- }
724
-
725
- bool isReadonly() {
726
- return readonly;
727
- }
728
-
729
- void setReadonly(bool readonly) {
730
- if (this.readonly && !readonly) {
731
- throw StateError("can't alter readonly IntervalSet");
732
- }
733
- this.readonly = readonly;
734
- }
735
- }