-
Notifications
You must be signed in to change notification settings - Fork 178
/
Nodes.java
8403 lines (7319 loc) · 271 KB
/
Nodes.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************/
/* This file is generated by the templates/template.rb script and should not */
/* be modified manually. See */
/* templates/java/org/prism/Nodes.java.erb */
/* if you are looking to modify the */
/* template */
/******************************************************************************/
package org.prism;
import java.lang.Override;
import java.lang.String;
import java.lang.StringBuilder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
// GENERATED BY Nodes.java.erb
// @formatter:off
public abstract class Nodes {
public static final byte[][] EMPTY_BYTE_ARRAY_ARRAY = {};
public static final String[] EMPTY_STRING_ARRAY = {};
public static final class Location {
public static final Location[] EMPTY_ARRAY = {};
public final int startOffset;
public final int length;
public Location(int startOffset, int length) {
this.startOffset = startOffset;
this.length = length;
}
public int endOffset() {
return startOffset + length;
}
}
public static final class Source {
public final byte[] bytes;
private int startLine;
private final int[] lineOffsets;
public Source(byte[] bytes) {
this(bytes, 1, computeLineOffsets(bytes));
}
public Source(byte[] bytes, int startLine, int[] lineOffsets) {
assert lineOffsets[0] == 0;
this.bytes = bytes;
this.startLine = startLine;
this.lineOffsets = lineOffsets;
}
public void setStartLine(int startLine) {
this.startLine = startLine;
}
public static int[] computeLineOffsets(byte[] bytes) {
int[] lineOffsets = new int[8];
int lineOffsetsSize = 0;
lineOffsets[lineOffsetsSize++] = 0;
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == '\n') {
if (lineOffsetsSize == lineOffsets.length) {
lineOffsets = Arrays.copyOf(lineOffsets, lineOffsets.length * 2);
}
lineOffsets[lineOffsetsSize++] = i + 1;
}
}
return Arrays.copyOf(lineOffsets, lineOffsetsSize);
}
// 1-based
public int line(int byteOffset) {
return startLine + findLine(byteOffset);
}
// 0-based
public int findLine(int byteOffset) {
if (byteOffset >= bytes.length) byteOffset = bytes.length - 1;
assert byteOffset >= 0 : byteOffset;
int index = Arrays.binarySearch(lineOffsets, byteOffset);
int line;
if (index < 0) {
line = -index - 2;
} else {
line = index;
}
assert line >= 0 && line <= getLineCount() : line;
return line;
}
public int getLineCount() {
return lineOffsets.length;
}
}
public static abstract class Node {
public static final Node[] EMPTY_ARRAY = {};
public final int startOffset;
public final int length;
private boolean newLineFlag = false;
public Node(int startOffset, int length) {
this.startOffset = startOffset;
this.length = length;
}
public final int endOffset() {
return startOffset + length;
}
public final boolean hasNewLineFlag() {
return newLineFlag;
}
public void setNewLineFlag(Source source, boolean[] newlineMarked) {
int line = source.findLine(this.startOffset);
if (!newlineMarked[line]) {
newlineMarked[line] = true;
this.newLineFlag = true;
}
}
public abstract <T> T accept(AbstractNodeVisitor<T> visitor);
public abstract <T> void visitChildNodes(AbstractNodeVisitor<T> visitor);
public abstract Node[] childNodes();
@Override
public String toString() {
return toString("");
}
protected abstract String toString(String indent);
}
/**
* Flags for arguments nodes.
*/
public static final class ArgumentsNodeFlags implements Comparable<ArgumentsNodeFlags> {
// if arguments contain keyword splat
public static final short CONTAINS_KEYWORD_SPLAT = 1 << 0;
public static boolean isContainsKeywordSplat(short flags) {
return (flags & CONTAINS_KEYWORD_SPLAT) != 0;
}
private final short flags;
public ArgumentsNodeFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ArgumentsNodeFlags)) {
return false;
}
return flags == ((ArgumentsNodeFlags) other).flags;
}
@Override
public int compareTo(ArgumentsNodeFlags other) {
return flags - other.flags;
}
public boolean isContainsKeywordSplat() {
return (flags & CONTAINS_KEYWORD_SPLAT) != 0;
}
}
/**
* Flags for array nodes.
*/
public static final class ArrayNodeFlags implements Comparable<ArrayNodeFlags> {
// if array contains splat nodes
public static final short CONTAINS_SPLAT = 1 << 0;
public static boolean isContainsSplat(short flags) {
return (flags & CONTAINS_SPLAT) != 0;
}
private final short flags;
public ArrayNodeFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof ArrayNodeFlags)) {
return false;
}
return flags == ((ArrayNodeFlags) other).flags;
}
@Override
public int compareTo(ArrayNodeFlags other) {
return flags - other.flags;
}
public boolean isContainsSplat() {
return (flags & CONTAINS_SPLAT) != 0;
}
}
/**
* Flags for call nodes.
*/
public static final class CallNodeFlags implements Comparable<CallNodeFlags> {
// &. operator
public static final short SAFE_NAVIGATION = 1 << 0;
// a call that could have been a local variable
public static final short VARIABLE_CALL = 1 << 1;
public static boolean isSafeNavigation(short flags) {
return (flags & SAFE_NAVIGATION) != 0;
}
public static boolean isVariableCall(short flags) {
return (flags & VARIABLE_CALL) != 0;
}
private final short flags;
public CallNodeFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof CallNodeFlags)) {
return false;
}
return flags == ((CallNodeFlags) other).flags;
}
@Override
public int compareTo(CallNodeFlags other) {
return flags - other.flags;
}
public boolean isSafeNavigation() {
return (flags & SAFE_NAVIGATION) != 0;
}
public boolean isVariableCall() {
return (flags & VARIABLE_CALL) != 0;
}
}
/**
* Flags for integer nodes that correspond to the base of the integer.
*/
public static final class IntegerBaseFlags implements Comparable<IntegerBaseFlags> {
// 0b prefix
public static final short BINARY = 1 << 0;
// 0o or 0 prefix
public static final short OCTAL = 1 << 1;
// 0d or no prefix
public static final short DECIMAL = 1 << 2;
// 0x prefix
public static final short HEXADECIMAL = 1 << 3;
public static boolean isBinary(short flags) {
return (flags & BINARY) != 0;
}
public static boolean isOctal(short flags) {
return (flags & OCTAL) != 0;
}
public static boolean isDecimal(short flags) {
return (flags & DECIMAL) != 0;
}
public static boolean isHexadecimal(short flags) {
return (flags & HEXADECIMAL) != 0;
}
private final short flags;
public IntegerBaseFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof IntegerBaseFlags)) {
return false;
}
return flags == ((IntegerBaseFlags) other).flags;
}
@Override
public int compareTo(IntegerBaseFlags other) {
return flags - other.flags;
}
public boolean isBinary() {
return (flags & BINARY) != 0;
}
public boolean isOctal() {
return (flags & OCTAL) != 0;
}
public boolean isDecimal() {
return (flags & DECIMAL) != 0;
}
public boolean isHexadecimal() {
return (flags & HEXADECIMAL) != 0;
}
}
/**
* Flags for while and until loop nodes.
*/
public static final class LoopFlags implements Comparable<LoopFlags> {
// a loop after a begin statement, so the body is executed first before the condition
public static final short BEGIN_MODIFIER = 1 << 0;
public static boolean isBeginModifier(short flags) {
return (flags & BEGIN_MODIFIER) != 0;
}
private final short flags;
public LoopFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof LoopFlags)) {
return false;
}
return flags == ((LoopFlags) other).flags;
}
@Override
public int compareTo(LoopFlags other) {
return flags - other.flags;
}
public boolean isBeginModifier() {
return (flags & BEGIN_MODIFIER) != 0;
}
}
/**
* Flags for range and flip-flop nodes.
*/
public static final class RangeFlags implements Comparable<RangeFlags> {
// ... operator
public static final short EXCLUDE_END = 1 << 0;
public static boolean isExcludeEnd(short flags) {
return (flags & EXCLUDE_END) != 0;
}
private final short flags;
public RangeFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof RangeFlags)) {
return false;
}
return flags == ((RangeFlags) other).flags;
}
@Override
public int compareTo(RangeFlags other) {
return flags - other.flags;
}
public boolean isExcludeEnd() {
return (flags & EXCLUDE_END) != 0;
}
}
/**
* Flags for regular expression and match last line nodes.
*/
public static final class RegularExpressionFlags implements Comparable<RegularExpressionFlags> {
// i - ignores the case of characters when matching
public static final short IGNORE_CASE = 1 << 0;
// x - ignores whitespace and allows comments in regular expressions
public static final short EXTENDED = 1 << 1;
// m - allows $ to match the end of lines within strings
public static final short MULTI_LINE = 1 << 2;
// o - only interpolates values into the regular expression once
public static final short ONCE = 1 << 3;
// e - forces the EUC-JP encoding
public static final short EUC_JP = 1 << 4;
// n - forces the ASCII-8BIT encoding
public static final short ASCII_8BIT = 1 << 5;
// s - forces the Windows-31J encoding
public static final short WINDOWS_31J = 1 << 6;
// u - forces the UTF-8 encoding
public static final short UTF_8 = 1 << 7;
public static boolean isIgnoreCase(short flags) {
return (flags & IGNORE_CASE) != 0;
}
public static boolean isExtended(short flags) {
return (flags & EXTENDED) != 0;
}
public static boolean isMultiLine(short flags) {
return (flags & MULTI_LINE) != 0;
}
public static boolean isOnce(short flags) {
return (flags & ONCE) != 0;
}
public static boolean isEucJp(short flags) {
return (flags & EUC_JP) != 0;
}
public static boolean isAscii8bit(short flags) {
return (flags & ASCII_8BIT) != 0;
}
public static boolean isWindows31j(short flags) {
return (flags & WINDOWS_31J) != 0;
}
public static boolean isUtf8(short flags) {
return (flags & UTF_8) != 0;
}
private final short flags;
public RegularExpressionFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof RegularExpressionFlags)) {
return false;
}
return flags == ((RegularExpressionFlags) other).flags;
}
@Override
public int compareTo(RegularExpressionFlags other) {
return flags - other.flags;
}
public boolean isIgnoreCase() {
return (flags & IGNORE_CASE) != 0;
}
public boolean isExtended() {
return (flags & EXTENDED) != 0;
}
public boolean isMultiLine() {
return (flags & MULTI_LINE) != 0;
}
public boolean isOnce() {
return (flags & ONCE) != 0;
}
public boolean isEucJp() {
return (flags & EUC_JP) != 0;
}
public boolean isAscii8bit() {
return (flags & ASCII_8BIT) != 0;
}
public boolean isWindows31j() {
return (flags & WINDOWS_31J) != 0;
}
public boolean isUtf8() {
return (flags & UTF_8) != 0;
}
}
/**
* Flags for string nodes.
*/
public static final class StringFlags implements Comparable<StringFlags> {
// frozen by virtue of a `frozen_string_literal` comment
public static final short FROZEN = 1 << 0;
public static boolean isFrozen(short flags) {
return (flags & FROZEN) != 0;
}
private final short flags;
public StringFlags(short flags) {
this.flags = flags;
}
@Override
public int hashCode() {
return flags;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof StringFlags)) {
return false;
}
return flags == ((StringFlags) other).flags;
}
@Override
public int compareTo(StringFlags other) {
return flags - other.flags;
}
public boolean isFrozen() {
return (flags & FROZEN) != 0;
}
}
/**
* Represents the use of the `alias` keyword to alias a global variable.
*
* alias $foo $bar
* ^^^^^^^^^^^^^^^
*/
public static final class AliasGlobalVariableNode extends Node {
public final Node new_name;
public final Node old_name;
public AliasGlobalVariableNode(Node new_name, Node old_name, int startOffset, int length) {
super(startOffset, length);
this.new_name = new_name;
this.old_name = old_name;
}
public <T> void visitChildNodes(AbstractNodeVisitor<T> visitor) {
this.new_name.accept(visitor);
this.old_name.accept(visitor);
}
public Node[] childNodes() {
return new Node[] { this.new_name, this.old_name };
}
public <T> T accept(AbstractNodeVisitor<T> visitor) {
return visitor.visitAliasGlobalVariableNode(this);
}
@Override
protected String toString(String indent) {
StringBuilder builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
if (hasNewLineFlag()) {
builder.append("[Li]");
}
builder.append('\n');
String nextIndent = indent + " ";
builder.append(nextIndent);
builder.append("new_name: ");
builder.append(this.new_name.toString(nextIndent));
builder.append(nextIndent);
builder.append("old_name: ");
builder.append(this.old_name.toString(nextIndent));
return builder.toString();
}
}
/**
* Represents the use of the `alias` keyword to alias a method.
*
* alias foo bar
* ^^^^^^^^^^^^^
*/
public static final class AliasMethodNode extends Node {
public final Node new_name;
public final Node old_name;
public AliasMethodNode(Node new_name, Node old_name, int startOffset, int length) {
super(startOffset, length);
this.new_name = new_name;
this.old_name = old_name;
}
public <T> void visitChildNodes(AbstractNodeVisitor<T> visitor) {
this.new_name.accept(visitor);
this.old_name.accept(visitor);
}
public Node[] childNodes() {
return new Node[] { this.new_name, this.old_name };
}
public <T> T accept(AbstractNodeVisitor<T> visitor) {
return visitor.visitAliasMethodNode(this);
}
@Override
protected String toString(String indent) {
StringBuilder builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
if (hasNewLineFlag()) {
builder.append("[Li]");
}
builder.append('\n');
String nextIndent = indent + " ";
builder.append(nextIndent);
builder.append("new_name: ");
builder.append(this.new_name.toString(nextIndent));
builder.append(nextIndent);
builder.append("old_name: ");
builder.append(this.old_name.toString(nextIndent));
return builder.toString();
}
}
/**
* Represents an alternation pattern in pattern matching.
*
* foo => bar | baz
* ^^^^^^^^^
*/
public static final class AlternationPatternNode extends Node {
public final Node left;
public final Node right;
public AlternationPatternNode(Node left, Node right, int startOffset, int length) {
super(startOffset, length);
this.left = left;
this.right = right;
}
public <T> void visitChildNodes(AbstractNodeVisitor<T> visitor) {
this.left.accept(visitor);
this.right.accept(visitor);
}
public Node[] childNodes() {
return new Node[] { this.left, this.right };
}
public <T> T accept(AbstractNodeVisitor<T> visitor) {
return visitor.visitAlternationPatternNode(this);
}
@Override
protected String toString(String indent) {
StringBuilder builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
if (hasNewLineFlag()) {
builder.append("[Li]");
}
builder.append('\n');
String nextIndent = indent + " ";
builder.append(nextIndent);
builder.append("left: ");
builder.append(this.left.toString(nextIndent));
builder.append(nextIndent);
builder.append("right: ");
builder.append(this.right.toString(nextIndent));
return builder.toString();
}
}
/**
* Represents the use of the `&&` operator or the `and` keyword.
*
* left and right
* ^^^^^^^^^^^^^^
*/
public static final class AndNode extends Node {
public final Node left;
public final Node right;
public AndNode(Node left, Node right, int startOffset, int length) {
super(startOffset, length);
this.left = left;
this.right = right;
}
public <T> void visitChildNodes(AbstractNodeVisitor<T> visitor) {
this.left.accept(visitor);
this.right.accept(visitor);
}
public Node[] childNodes() {
return new Node[] { this.left, this.right };
}
public <T> T accept(AbstractNodeVisitor<T> visitor) {
return visitor.visitAndNode(this);
}
@Override
protected String toString(String indent) {
StringBuilder builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
if (hasNewLineFlag()) {
builder.append("[Li]");
}
builder.append('\n');
String nextIndent = indent + " ";
builder.append(nextIndent);
builder.append("left: ");
builder.append(this.left.toString(nextIndent));
builder.append(nextIndent);
builder.append("right: ");
builder.append(this.right.toString(nextIndent));
return builder.toString();
}
}
/**
* Represents a set of arguments to a method or a keyword.
*
* return foo, bar, baz
* ^^^^^^^^^^^^^
*/
public static final class ArgumentsNode extends Node {
public final Node[] arguments;
public final short flags;
public ArgumentsNode(Node[] arguments, short flags, int startOffset, int length) {
super(startOffset, length);
this.arguments = arguments;
this.flags = flags;
}
public boolean isContainsKeywordSplat() {
return ArgumentsNodeFlags.isContainsKeywordSplat(this.flags);
}
public <T> void visitChildNodes(AbstractNodeVisitor<T> visitor) {
for (Nodes.Node child : this.arguments) {
child.accept(visitor);
}
}
public Node[] childNodes() {
return this.arguments;
}
public <T> T accept(AbstractNodeVisitor<T> visitor) {
return visitor.visitArgumentsNode(this);
}
@Override
protected String toString(String indent) {
StringBuilder builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
if (hasNewLineFlag()) {
builder.append("[Li]");
}
builder.append('\n');
String nextIndent = indent + " ";
String nextNextIndent = nextIndent + " ";
builder.append(nextIndent);
builder.append("arguments: ");
builder.append('\n');
for (Node child : this.arguments) {
builder.append(nextNextIndent).append(child.toString(nextNextIndent));
}
builder.append(nextIndent);
builder.append("flags: ");
builder.append(this.flags);
builder.append('\n');
return builder.toString();
}
}
/**
* Represents an array literal. This can be a regular array using brackets or
* a special array using % like %w or %i.
*
* [1, 2, 3]
* ^^^^^^^^^
*/
public static final class ArrayNode extends Node {
public final Node[] elements;
public final short flags;
public ArrayNode(Node[] elements, short flags, int startOffset, int length) {
super(startOffset, length);
this.elements = elements;
this.flags = flags;
}
public boolean isContainsSplat() {
return ArrayNodeFlags.isContainsSplat(this.flags);
}
public <T> void visitChildNodes(AbstractNodeVisitor<T> visitor) {
for (Nodes.Node child : this.elements) {
child.accept(visitor);
}
}
public Node[] childNodes() {
return this.elements;
}
public <T> T accept(AbstractNodeVisitor<T> visitor) {
return visitor.visitArrayNode(this);
}
@Override
protected String toString(String indent) {
StringBuilder builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
if (hasNewLineFlag()) {
builder.append("[Li]");
}
builder.append('\n');
String nextIndent = indent + " ";
String nextNextIndent = nextIndent + " ";
builder.append(nextIndent);
builder.append("elements: ");
builder.append('\n');
for (Node child : this.elements) {
builder.append(nextNextIndent).append(child.toString(nextNextIndent));
}
builder.append(nextIndent);
builder.append("flags: ");
builder.append(this.flags);
builder.append('\n');
return builder.toString();
}
}
/**
* Represents an array pattern in pattern matching.
*
* foo in 1, 2
* ^^^^^^^^^^^
*
* foo in [1, 2]
* ^^^^^^^^^^^^^
*
* foo in *1
* ^^^^^^^^^
*
* foo in Bar[]
* ^^^^^^^^^^^^
*
* foo in Bar[1, 2, 3]
* ^^^^^^^^^^^^^^^^^^^
*/
public static final class ArrayPatternNode extends Node {
/** optional (can be null) */
public final Node constant;
public final Node[] requireds;
/** optional (can be null) */
public final Node rest;
public final Node[] posts;
public ArrayPatternNode(Node constant, Node[] requireds, Node rest, Node[] posts, int startOffset, int length) {
super(startOffset, length);
this.constant = constant;
this.requireds = requireds;
this.rest = rest;
this.posts = posts;
}
public <T> void visitChildNodes(AbstractNodeVisitor<T> visitor) {
if (this.constant != null) {
this.constant.accept(visitor);
}
for (Nodes.Node child : this.requireds) {
child.accept(visitor);
}
if (this.rest != null) {
this.rest.accept(visitor);
}
for (Nodes.Node child : this.posts) {
child.accept(visitor);
}
}
public Node[] childNodes() {
ArrayList<Node> childNodes = new ArrayList<>();
childNodes.add(this.constant);
childNodes.addAll(Arrays.asList(this.requireds));
childNodes.add(this.rest);
childNodes.addAll(Arrays.asList(this.posts));
return childNodes.toArray(EMPTY_ARRAY);
}
public <T> T accept(AbstractNodeVisitor<T> visitor) {
return visitor.visitArrayPatternNode(this);
}
@Override
protected String toString(String indent) {
StringBuilder builder = new StringBuilder();
builder.append(this.getClass().getSimpleName());
if (hasNewLineFlag()) {
builder.append("[Li]");
}
builder.append('\n');
String nextIndent = indent + " ";
String nextNextIndent = nextIndent + " ";
builder.append(nextIndent);
builder.append("constant: ");
builder.append(this.constant == null ? "null\n" : this.constant.toString(nextIndent));
builder.append(nextIndent);
builder.append("requireds: ");
builder.append('\n');
for (Node child : this.requireds) {
builder.append(nextNextIndent).append(child.toString(nextNextIndent));
}
builder.append(nextIndent);