-
Notifications
You must be signed in to change notification settings - Fork 517
Expand file tree
/
Copy pathJ.cs
More file actions
2722 lines (2429 loc) · 124 KB
/
J.cs
File metadata and controls
2722 lines (2429 loc) · 124 KB
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
/*
* Copyright 2026 the original author or authors.
* <p>
* Licensed under the Moderne Source Available License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://docs.moderne.io/licensing/moderne-source-available-license
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using OpenRewrite.Core;
using OpenRewrite.Core.Rpc;
namespace OpenRewrite.Java;
/// <summary>
/// The base interface for all Java-family LST elements.
/// C# LST elements extend J where the syntax is isomorphic.
/// </summary>
public interface J : Tree
{
Space Prefix { get; }
Markers Markers { get; }
}
/// <summary>
/// Marker interface for expressions that produce a value.
/// </summary>
public interface Expression : J
{
}
/// <summary>
/// Marker interface for statements.
/// </summary>
public interface Statement : J
{
}
/// <summary>
/// Marker indicating null-safe navigation (?. operator).
/// Used by languages with safe navigation: C#, Kotlin, Groovy.
/// When present on a MethodInvocation.Name or FieldAccess.Name, prints ?. instead of .
/// </summary>
public sealed class NullSafe : Marker, IRpcCodec<NullSafe>, IEquatable<NullSafe>
{
public Guid Id { get; }
/// <summary>Whitespace between '?' and '.' when they are separated (e.g., by a newline).</summary>
public Space DotPrefix { get; }
public NullSafe(Guid id, Space? dotPrefix = null)
{
Id = id;
DotPrefix = dotPrefix ?? Space.Empty;
}
public NullSafe WithId(Guid id) =>
id == Id ? this : new(id, DotPrefix);
public NullSafe WithDotPrefix(Space dotPrefix) =>
ReferenceEquals(dotPrefix, DotPrefix) ? this : new(Id, dotPrefix);
public static NullSafe Instance { get; } = new(Guid.Empty);
public void RpcSend(NullSafe after, RpcSendQueue q)
{
q.GetAndSend(after, m => m.Id);
q.GetAndSend(after, m => m.DotPrefix, s => new Rpc.JavaSender().VisitSpace(s, q));
}
public NullSafe RpcReceive(NullSafe before, RpcReceiveQueue q) =>
before
.WithId(q.ReceiveAndGet<Guid, string>(before.Id, Guid.Parse))
.WithDotPrefix(q.Receive(before.DotPrefix, s => new Rpc.JavaReceiver().VisitSpace(s, q)));
public bool Equals(NullSafe? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as NullSafe);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// Marker indicating parentheses should be omitted in NewClass.
/// Used for object initializers without constructor arguments: new Foo { X = 1 }
/// </summary>
public sealed class OmitParentheses(
Guid id
) : Marker, IRpcCodec<OmitParentheses>, IEquatable<OmitParentheses>
{
public Guid Id { get; } = id;
public OmitParentheses WithId(Guid id) =>
id == Id ? this : new(id);
public static OmitParentheses Instance { get; } = new(Guid.Empty);
public void RpcSend(OmitParentheses after, RpcSendQueue q) => q.GetAndSend(after, m => m.Id);
public OmitParentheses RpcReceive(OmitParentheses before, RpcReceiveQueue q) =>
before.WithId(q.ReceiveAndGet<Guid, string>(before.Id, Guid.Parse));
public bool Equals(OmitParentheses? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as OmitParentheses);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// Marker indicating a semicolon-terminated element.
/// Used for positional records (record Person(string Name);) and other contexts
/// where a semicolon replaces the expected body/braces.
/// </summary>
public sealed class Semicolon(
Guid id
) : Marker, IRpcCodec<Semicolon>, IEquatable<Semicolon>
{
public Guid Id { get; } = id;
public Semicolon WithId(Guid id) =>
id == Id ? this : new(id);
public void RpcSend(Semicolon after, RpcSendQueue q) => q.GetAndSend(after, m => m.Id);
public Semicolon RpcReceive(Semicolon before, RpcReceiveQueue q) =>
before.WithId(q.ReceiveAndGet<Guid, string>(before.Id, Guid.Parse));
public bool Equals(Semicolon? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Semicolon);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A package/namespace declaration.
/// Java: package com.example;
/// C#: namespace MyApp.Services; (file-scoped)
/// </summary>
public sealed class Package(
Guid id,
Space prefix,
Markers markers,
Expression expression,
IList<Annotation> annotations
) : J, Statement, IEquatable<Package>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public Expression Expression { get; } = expression;
public IList<Annotation> Annotations { get; } = annotations;
public Package WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Expression, Annotations);
public Package WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Expression, Annotations);
public Package WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Expression, Annotations);
public Package WithExpression(Expression expression) =>
ReferenceEquals(expression, Expression) ? this : new(Id, Prefix, Markers, expression, Annotations);
public Package WithAnnotations(IList<Annotation> annotations) =>
ReferenceEquals(annotations, Annotations) ? this : new(Id, Prefix, Markers, Expression, annotations);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Package? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Package);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A literal value (string, number, boolean, char, null).
/// </summary>
public sealed class Literal(
Guid id,
Space prefix,
Markers markers,
object? value,
string? valueSource,
IList<Literal.UnicodeEscape>? unicodeEscapes,
JavaType.Primitive? type
) : J, Expression, IEquatable<Literal>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public object? Value { get; } = value;
public string? ValueSource { get; } = valueSource;
public IList<Literal.UnicodeEscape>? UnicodeEscapes { get; } = unicodeEscapes;
public JavaType.Primitive? Type { get; } = type;
public Literal WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Value, ValueSource, UnicodeEscapes, Type);
public Literal WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Value, ValueSource, UnicodeEscapes, Type);
public Literal WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Value, ValueSource, UnicodeEscapes, Type);
public Literal WithValue(object? value) =>
ReferenceEquals(value, Value) ? this : new(Id, Prefix, Markers, value, ValueSource, UnicodeEscapes, Type);
public Literal WithValueSource(string? valueSource) =>
string.Equals(valueSource, ValueSource, StringComparison.Ordinal) ? this : new(Id, Prefix, Markers, Value, valueSource, UnicodeEscapes, Type);
public Literal WithUnicodeEscapes(IList<Literal.UnicodeEscape>? unicodeEscapes) =>
ReferenceEquals(unicodeEscapes, UnicodeEscapes) ? this : new(Id, Prefix, Markers, Value, ValueSource, unicodeEscapes, Type);
public Literal WithType(JavaType.Primitive? type) =>
ReferenceEquals(type, Type) ? this : new(Id, Prefix, Markers, Value, ValueSource, UnicodeEscapes, type);
public record UnicodeEscape(int ValueSourceIndex, string CodePoint);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Literal? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Literal);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// An expression used as a statement.
/// </summary>
public sealed class ExpressionStatement(
Guid id,
Expression expression
) : J, Statement, IEquatable<ExpressionStatement>
{
public Guid Id { get; } = id;
public Expression Expression { get; } = expression;
public ExpressionStatement WithId(Guid id) =>
id == Id ? this : new(id, Expression);
public ExpressionStatement WithExpression(Expression expression) =>
ReferenceEquals(expression, Expression) ? this : new(Id, expression);
// ExpressionStatement delegates prefix/markers to its expression
public Space Prefix => Expression.Prefix;
public Markers Markers => Expression.Markers;
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(ExpressionStatement? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as ExpressionStatement);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A block of statements enclosed in braces { }.
/// </summary>
public sealed class Block(
Guid id,
Space prefix,
Markers markers,
JRightPadded<bool> @static,
IList<JRightPadded<Statement>> statements,
Space end
) : J, Statement, IEquatable<Block>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public JRightPadded<bool> Static { get; } = @static;
public IList<JRightPadded<Statement>> Statements { get; } = statements;
public Space End { get; } = end;
public Block WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Static, Statements, End);
public Block WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Static, Statements, End);
public Block WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Static, Statements, End);
public Block WithStatic(JRightPadded<bool> @static) =>
ReferenceEquals(@static, Static) ? this : new(Id, Prefix, Markers, @static, Statements, End);
public Block WithStatements(IList<JRightPadded<Statement>> statements) =>
ReferenceEquals(statements, Statements) ? this : new(Id, Prefix, Markers, Static, statements, End);
public Block WithEnd(Space end) =>
ReferenceEquals(end, End) ? this : new(Id, Prefix, Markers, Static, Statements, end);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Block? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Block);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A return statement (e.g., return 1;).
/// </summary>
public sealed class Return(
Guid id,
Space prefix,
Markers markers,
Expression? expression
) : J, Statement, IEquatable<Return>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public Expression? Expression { get; } = expression;
public Return WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Expression);
public Return WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Expression);
public Return WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Expression);
public Return WithExpression(Expression? expression) =>
ReferenceEquals(expression, Expression) ? this : new(Id, Prefix, Markers, expression);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Return? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Return);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// An if statement (e.g., if (condition) { } else { }).
/// </summary>
public sealed class If(
Guid id,
Space prefix,
Markers markers,
ControlParentheses<Expression> condition,
JRightPadded<Statement> thenPart,
If.Else? elsePart
) : J, Statement, IEquatable<If>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public ControlParentheses<Expression> Condition { get; } = condition;
public JRightPadded<Statement> ThenPart { get; } = thenPart;
public If.Else? ElsePart { get; } = elsePart;
public If WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Condition, ThenPart, ElsePart);
public If WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Condition, ThenPart, ElsePart);
public If WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Condition, ThenPart, ElsePart);
public If WithCondition(ControlParentheses<Expression> condition) =>
ReferenceEquals(condition, Condition) ? this : new(Id, Prefix, Markers, condition, ThenPart, ElsePart);
public If WithThenPart(JRightPadded<Statement> thenPart) =>
ReferenceEquals(thenPart, ThenPart) ? this : new(Id, Prefix, Markers, Condition, thenPart, ElsePart);
public If WithElsePart(If.Else? elsePart) =>
ReferenceEquals(elsePart, ElsePart) ? this : new(Id, Prefix, Markers, Condition, ThenPart, elsePart);
public sealed class Else(
Guid id,
Space prefix,
Markers markers,
JRightPadded<Statement> body
) : J, IEquatable<Else>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public JRightPadded<Statement> Body { get; } = body;
public Else WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Body);
public Else WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Body);
public Else WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Body);
public Else WithBody(JRightPadded<Statement> body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, body);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Else? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Else);
public override int GetHashCode() => Id.GetHashCode();
}
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(If? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as If);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// Parentheses used in control structures (if, while, etc.).
/// </summary>
public sealed class ControlParentheses<T>(
Guid id,
Space prefix,
Markers markers,
JRightPadded<T> tree
) : J, Expression, IEquatable<ControlParentheses<T>> where T : J
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public JRightPadded<T> Tree { get; } = tree;
public ControlParentheses<T> WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Tree);
public ControlParentheses<T> WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Tree);
public ControlParentheses<T> WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Tree);
public ControlParentheses<T> WithTree(JRightPadded<T> tree) =>
ReferenceEquals(tree, Tree) ? this : new(Id, Prefix, Markers, tree);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(ControlParentheses<T>? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as ControlParentheses<T>);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A for loop (e.g., for (int i = 0; i < 10; i++) { }).
/// </summary>
public sealed class ForLoop(
Guid id,
Space prefix,
Markers markers,
ForLoop.Control loopControl,
JRightPadded<Statement> body
) : J, Statement, IEquatable<ForLoop>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public ForLoop.Control LoopControl { get; } = loopControl;
public JRightPadded<Statement> Body { get; } = body;
public ForLoop WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, LoopControl, Body);
public ForLoop WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, LoopControl, Body);
public ForLoop WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, LoopControl, Body);
public ForLoop WithLoopControl(ForLoop.Control loopControl) =>
ReferenceEquals(loopControl, LoopControl) ? this : new(Id, Prefix, Markers, loopControl, Body);
public ForLoop WithBody(JRightPadded<Statement> body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, LoopControl, body);
public sealed class Control(
Guid id,
Space prefix,
Markers markers,
IList<JRightPadded<Statement>> init,
JRightPadded<Expression> condition,
IList<JRightPadded<Statement>> update
) : J, IEquatable<Control>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public IList<JRightPadded<Statement>> Init { get; } = init;
public JRightPadded<Expression> Condition { get; } = condition;
public IList<JRightPadded<Statement>> Update { get; } = update;
public Control WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Init, Condition, Update);
public Control WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Init, Condition, Update);
public Control WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Init, Condition, Update);
public Control WithInit(IList<JRightPadded<Statement>> init) =>
ReferenceEquals(init, Init) ? this : new(Id, Prefix, Markers, init, Condition, Update);
public Control WithCondition(JRightPadded<Expression> condition) =>
ReferenceEquals(condition, Condition) ? this : new(Id, Prefix, Markers, Init, condition, Update);
public Control WithUpdate(IList<JRightPadded<Statement>> update) =>
ReferenceEquals(update, Update) ? this : new(Id, Prefix, Markers, Init, Condition, update);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Control? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Control);
public override int GetHashCode() => Id.GetHashCode();
}
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(ForLoop? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as ForLoop);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A foreach loop (e.g., foreach (var x in items) { }).
/// </summary>
public sealed class ForEachLoop(
Guid id,
Space prefix,
Markers markers,
ForEachLoop.Control loopControl,
JRightPadded<Statement> body
) : J, Statement, IEquatable<ForEachLoop>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public ForEachLoop.Control LoopControl { get; } = loopControl;
public JRightPadded<Statement> Body { get; } = body;
public ForEachLoop WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, LoopControl, Body);
public ForEachLoop WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, LoopControl, Body);
public ForEachLoop WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, LoopControl, Body);
public ForEachLoop WithLoopControl(ForEachLoop.Control loopControl) =>
ReferenceEquals(loopControl, LoopControl) ? this : new(Id, Prefix, Markers, loopControl, Body);
public ForEachLoop WithBody(JRightPadded<Statement> body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, LoopControl, body);
public sealed class Control(
Guid id,
Space prefix,
Markers markers,
JRightPadded<VariableDeclarations> variable,
JRightPadded<Expression> iterable
) : J, IEquatable<Control>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public JRightPadded<VariableDeclarations> Variable { get; } = variable;
public JRightPadded<Expression> Iterable { get; } = iterable;
public Control WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Variable, Iterable);
public Control WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Variable, Iterable);
public Control WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Variable, Iterable);
public Control WithVariable(JRightPadded<VariableDeclarations> variable) =>
ReferenceEquals(variable, Variable) ? this : new(Id, Prefix, Markers, variable, Iterable);
public Control WithIterable(JRightPadded<Expression> iterable) =>
ReferenceEquals(iterable, Iterable) ? this : new(Id, Prefix, Markers, Variable, iterable);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Control? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Control);
public override int GetHashCode() => Id.GetHashCode();
}
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(ForEachLoop? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as ForEachLoop);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A while loop (e.g., while (condition) { }).
/// </summary>
public sealed class WhileLoop(
Guid id,
Space prefix,
Markers markers,
ControlParentheses<Expression> condition,
JRightPadded<Statement> body
) : J, Statement, IEquatable<WhileLoop>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public ControlParentheses<Expression> Condition { get; } = condition;
public JRightPadded<Statement> Body { get; } = body;
public WhileLoop WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Condition, Body);
public WhileLoop WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Condition, Body);
public WhileLoop WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Condition, Body);
public WhileLoop WithCondition(ControlParentheses<Expression> condition) =>
ReferenceEquals(condition, Condition) ? this : new(Id, Prefix, Markers, condition, Body);
public WhileLoop WithBody(JRightPadded<Statement> body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, Condition, body);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(WhileLoop? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as WhileLoop);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A do-while loop (e.g., do { } while (condition);).
/// </summary>
public sealed class DoWhileLoop(
Guid id,
Space prefix,
Markers markers,
JRightPadded<Statement> body,
JLeftPadded<ControlParentheses<Expression>> condition
) : J, Statement, IEquatable<DoWhileLoop>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public JRightPadded<Statement> Body { get; } = body;
public JLeftPadded<ControlParentheses<Expression>> Condition { get; } = condition;
public DoWhileLoop WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Body, Condition);
public DoWhileLoop WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Body, Condition);
public DoWhileLoop WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Body, Condition);
public DoWhileLoop WithBody(JRightPadded<Statement> body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, body, Condition);
public DoWhileLoop WithCondition(JLeftPadded<ControlParentheses<Expression>> condition) =>
ReferenceEquals(condition, Condition) ? this : new(Id, Prefix, Markers, Body, condition);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(DoWhileLoop? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as DoWhileLoop);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A synchronized/lock block statement.
/// In Java: synchronized (lock) { body }
/// In C#: lock (lock) { body }
/// </summary>
public sealed class Synchronized(
Guid id,
Space prefix,
Markers markers,
ControlParentheses<Expression> @lock,
Block body
) : J, Statement, IEquatable<Synchronized>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public ControlParentheses<Expression> Lock { get; } = @lock;
public Block Body { get; } = body;
public Synchronized WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Lock, Body);
public Synchronized WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Lock, Body);
public Synchronized WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Lock, Body);
public Synchronized WithLock(ControlParentheses<Expression> @lock) =>
ReferenceEquals(@lock, Lock) ? this : new(Id, Prefix, Markers, @lock, Body);
public Synchronized WithBody(Block body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, Lock, body);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Synchronized? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Synchronized);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A try statement (e.g., try { } catch { } finally { }).
/// </summary>
public sealed class Try(
Guid id,
Space prefix,
Markers markers,
JContainer<Try.Resource>? resources,
Block body,
IList<Try.Catch> catches,
JLeftPadded<Block>? @finally
) : J, Statement, IEquatable<Try>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public JContainer<Try.Resource>? Resources { get; } = resources;
public Block Body { get; } = body;
public IList<Try.Catch> Catches { get; } = catches;
public JLeftPadded<Block>? Finally { get; } = @finally;
public Try WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Resources, Body, Catches, Finally);
public Try WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Resources, Body, Catches, Finally);
public Try WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Resources, Body, Catches, Finally);
public Try WithResources(JContainer<Try.Resource>? resources) =>
ReferenceEquals(resources, Resources) ? this : new(Id, Prefix, Markers, resources, Body, Catches, Finally);
public Try WithBody(Block body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, Resources, body, Catches, Finally);
public Try WithCatches(IList<Try.Catch> catches) =>
ReferenceEquals(catches, Catches) ? this : new(Id, Prefix, Markers, Resources, Body, catches, Finally);
public Try WithFinally(JLeftPadded<Block>? @finally) =>
ReferenceEquals(@finally, Finally) ? this : new(Id, Prefix, Markers, Resources, Body, Catches, @finally);
public sealed class Resource(
Guid id,
Space prefix,
Markers markers,
J variableDeclarations,
bool terminatedWithSemicolon
) : J, IEquatable<Resource>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public J VariableDeclarations { get; } = variableDeclarations;
public bool TerminatedWithSemicolon { get; } = terminatedWithSemicolon;
public Resource WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, VariableDeclarations, TerminatedWithSemicolon);
public Resource WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, VariableDeclarations, TerminatedWithSemicolon);
public Resource WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, VariableDeclarations, TerminatedWithSemicolon);
public Resource WithVariableDeclarations(J variableDeclarations) =>
ReferenceEquals(variableDeclarations, VariableDeclarations) ? this : new(Id, Prefix, Markers, variableDeclarations, TerminatedWithSemicolon);
public Resource WithTerminatedWithSemicolon(bool terminatedWithSemicolon) =>
terminatedWithSemicolon == TerminatedWithSemicolon ? this : new(Id, Prefix, Markers, VariableDeclarations, terminatedWithSemicolon);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Resource? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Resource);
public override int GetHashCode() => Id.GetHashCode();
}
public sealed class Catch(
Guid id,
Space prefix,
Markers markers,
ControlParentheses<VariableDeclarations> parameter,
Block body
) : J, IEquatable<Catch>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public ControlParentheses<VariableDeclarations> Parameter { get; } = parameter;
public Block Body { get; } = body;
public Catch WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Parameter, Body);
public Catch WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Parameter, Body);
public Catch WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Parameter, Body);
public Catch WithParameter(ControlParentheses<VariableDeclarations> parameter) =>
ReferenceEquals(parameter, Parameter) ? this : new(Id, Prefix, Markers, parameter, Body);
public Catch WithBody(Block body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, Parameter, body);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Catch? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Catch);
public override int GetHashCode() => Id.GetHashCode();
}
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Try? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Try);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A throw statement (e.g., throw new Exception();).
/// </summary>
public sealed class Throw(
Guid id,
Space prefix,
Markers markers,
Expression exception
) : J, Statement, IEquatable<Throw>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public Expression Exception { get; } = exception;
public Throw WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Exception);
public Throw WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Exception);
public Throw WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Exception);
public Throw WithException(Expression exception) =>
ReferenceEquals(exception, Exception) ? this : new(Id, Prefix, Markers, exception);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Throw? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Throw);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A break statement.
/// </summary>
public sealed class Break(
Guid id,
Space prefix,
Markers markers,
Identifier? label
) : J, Statement, IEquatable<Break>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public Identifier? Label { get; } = label;
public Break WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Label);
public Break WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Label);
public Break WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Label);
public Break WithLabel(Identifier? label) =>
ReferenceEquals(label, Label) ? this : new(Id, Prefix, Markers, label);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Break? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Break);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A continue statement.
/// </summary>
public sealed class Continue(
Guid id,
Space prefix,
Markers markers,
Identifier? label
) : J, Statement, IEquatable<Continue>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public Identifier? Label { get; } = label;
public Continue WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Label);
public Continue WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Label);
public Continue WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Label);
public Continue WithLabel(Identifier? label) =>
ReferenceEquals(label, Label) ? this : new(Id, Prefix, Markers, label);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Continue? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Continue);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// An empty statement (just a semicolon).
/// </summary>
public sealed class Empty(
Guid id,
Space prefix,
Markers markers
) : J, Statement, Expression, IEquatable<Empty>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public Empty WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers);
public Empty WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers);
public Empty WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Empty? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Empty);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A class, struct, interface, or record declaration.
/// </summary>
public sealed class ClassDeclaration(
Guid id,
Space prefix,
Markers markers,
IList<Annotation> leadingAnnotations,
IList<Modifier> modifiers,
ClassDeclaration.Kind classKind,
Identifier name,
JContainer<TypeParameter>? typeParameters,
JContainer<TypeTree>? primaryConstructor,
JLeftPadded<TypeTree>? extends,
JContainer<TypeTree>? implements,
JContainer<TypeTree>? permits,
Block body,
JavaType.FullyQualified? type
) : J, Statement, IEquatable<ClassDeclaration>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public IList<Annotation> LeadingAnnotations { get; } = leadingAnnotations;
public IList<Modifier> Modifiers { get; } = modifiers;
public ClassDeclaration.Kind ClassKind { get; } = classKind;
public Identifier Name { get; } = name;
public JContainer<TypeParameter>? TypeParameters { get; } = typeParameters;
public JContainer<TypeTree>? PrimaryConstructor { get; } = primaryConstructor;
public JLeftPadded<TypeTree>? Extends { get; } = extends;
public JContainer<TypeTree>? Implements { get; } = implements;
public JContainer<TypeTree>? Permits { get; } = permits;
public Block Body { get; } = body;
public JavaType.FullyQualified? Type { get; } = type;
public ClassDeclaration WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithLeadingAnnotations(IList<Annotation> leadingAnnotations) =>
ReferenceEquals(leadingAnnotations, LeadingAnnotations) ? this : new(Id, Prefix, Markers, leadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithModifiers(IList<Modifier> modifiers) =>
ReferenceEquals(modifiers, Modifiers) ? this : new(Id, Prefix, Markers, LeadingAnnotations, modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithClassKind(ClassDeclaration.Kind classKind) =>
ReferenceEquals(classKind, ClassKind) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, classKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithName(Identifier name) =>
ReferenceEquals(name, Name) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithTypeParameters(JContainer<TypeParameter>? typeParameters) =>
ReferenceEquals(typeParameters, TypeParameters) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, typeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithPrimaryConstructor(JContainer<TypeTree>? primaryConstructor) =>
ReferenceEquals(primaryConstructor, PrimaryConstructor) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, primaryConstructor, Extends, Implements, Permits, Body, Type);
public ClassDeclaration WithExtends(JLeftPadded<TypeTree>? extends) =>
ReferenceEquals(extends, Extends) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, extends, Implements, Permits, Body, Type);
public ClassDeclaration WithImplements(JContainer<TypeTree>? implements) =>
ReferenceEquals(implements, Implements) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, implements, Permits, Body, Type);
public ClassDeclaration WithPermits(JContainer<TypeTree>? permits) =>
ReferenceEquals(permits, Permits) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, permits, Body, Type);
public ClassDeclaration WithBody(Block body) =>
ReferenceEquals(body, Body) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, body, Type);
public ClassDeclaration WithType(JavaType.FullyQualified? type) =>
ReferenceEquals(type, Type) ? this : new(Id, Prefix, Markers, LeadingAnnotations, Modifiers, ClassKind, Name, TypeParameters, PrimaryConstructor, Extends, Implements, Permits, Body, type);
public enum KindType { Class, Enum, Interface, Annotation, Record, Value }
public sealed class Kind(
Guid id,
Space prefix,
Markers markers,
IList<Annotation> annotations,
KindType type
) : J, IEquatable<Kind>
{
public Guid Id { get; } = id;
public Space Prefix { get; } = prefix;
public Markers Markers { get; } = markers;
public IList<Annotation> Annotations { get; } = annotations;
public KindType Type { get; } = type;
public Kind WithId(Guid id) =>
id == Id ? this : new(id, Prefix, Markers, Annotations, Type);
public Kind WithPrefix(Space prefix) =>
ReferenceEquals(prefix, Prefix) ? this : new(Id, prefix, Markers, Annotations, Type);
public Kind WithMarkers(Markers markers) =>
ReferenceEquals(markers, Markers) ? this : new(Id, Prefix, markers, Annotations, Type);
public Kind WithAnnotations(IList<Annotation> annotations) =>
ReferenceEquals(annotations, Annotations) ? this : new(Id, Prefix, Markers, annotations, Type);
public Kind WithType(KindType type) =>
type == Type ? this : new(Id, Prefix, Markers, Annotations, type);
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(Kind? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as Kind);
public override int GetHashCode() => Id.GetHashCode();
}
Tree Tree.WithId(Guid id) => WithId(id);
public bool Equals(ClassDeclaration? other) => other is not null && Id == other.Id;
public override bool Equals(object? obj) => Equals(obj as ClassDeclaration);
public override int GetHashCode() => Id.GetHashCode();
}
/// <summary>
/// A single enum constant/value.
/// Examples:
/// Red
/// Green = 1
/// Blue = 2
/// </summary>
public sealed class EnumValue(
Guid id,