diff options
| author | 2024-08-22 22:04:14 +0800 | |
|---|---|---|
| committer | 2024-08-22 22:04:14 +0800 | |
| commit | 1fd741f7d5019b929affd29741b5ce92d7993f0f (patch) | |
| tree | 01aa4d15f44f6fd698767606e0d7b8b4d5877b46 /ast/src/main | |
| parent | Simplify build scripts (diff) | |
| download | orang-1fd741f7d5019b929affd29741b5ce92d7993f0f.tar.gz orang-1fd741f7d5019b929affd29741b5ce92d7993f0f.tar.xz orang-1fd741f7d5019b929affd29741b5ce92d7993f0f.zip | |
Fix bug in checker that made it not execute and made ArgSpec less likely to cause accidental errors.
Diffstat (limited to 'ast/src/main')
| -rw-r--r-- | ast/src/main/java/lv/enes/orang/ast/ArgSpec.java | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/ast/src/main/java/lv/enes/orang/ast/ArgSpec.java b/ast/src/main/java/lv/enes/orang/ast/ArgSpec.java index 7fea2f4..8fa52be 100644 --- a/ast/src/main/java/lv/enes/orang/ast/ArgSpec.java +++ b/ast/src/main/java/lv/enes/orang/ast/ArgSpec.java | |||
| @@ -1,34 +1,39 @@ | |||
| 1 | package lv.enes.orang.ast; | 1 | package lv.enes.orang.ast; |
| 2 | 2 | ||
| 3 | public class ArgSpec { | 3 | public sealed interface ArgSpec { |
| 4 | public final Type type; | 4 | enum Type { |
| 5 | IGNORED, | ||
| 6 | NOTHING, | ||
| 7 | NAMED, | ||
| 8 | } | ||
| 5 | 9 | ||
| 6 | // non-null if NAMED | 10 | Type getType(); |
| 7 | public final String name; | ||
| 8 | 11 | ||
| 9 | private static final ArgSpec NOTHING = new ArgSpec(Type.NOTHING, null); | 12 | static Ignored ignored() { |
| 10 | private static final ArgSpec IGNORED = new ArgSpec(Type.IGNORED, null); | 13 | return Ignored.INSTANCE; |
| 14 | } | ||
| 11 | 15 | ||
| 12 | public static ArgSpec ignored() { | 16 | static Named named(String name) { |
| 13 | return IGNORED; | 17 | return new Named(name); |
| 14 | } | 18 | } |
| 15 | 19 | ||
| 16 | public static ArgSpec nothing() { | 20 | static Nothing nothing() { |
| 17 | return NOTHING; | 21 | return Nothing.INSTANCE; |
| 18 | } | 22 | } |
| 19 | 23 | ||
| 20 | public static ArgSpec named(String name) { | 24 | final class Ignored implements ArgSpec { |
| 21 | return new ArgSpec(Type.NAMED, name); | 25 | public static final Ignored INSTANCE = new Ignored(); |
| 26 | private Ignored() {} | ||
| 27 | @Override public Type getType() { return Type.IGNORED; } | ||
| 22 | } | 28 | } |
| 23 | 29 | ||
| 24 | private ArgSpec(Type type, String name) { | 30 | record Named(String name) implements ArgSpec { |
| 25 | this.type = type; | 31 | @Override public Type getType() { return Type.NAMED; } |
| 26 | this.name = name; | ||
| 27 | } | 32 | } |
| 28 | 33 | ||
| 29 | public enum Type { | 34 | final class Nothing implements ArgSpec { |
| 30 | IGNORED, | 35 | public static final Nothing INSTANCE = new Nothing(); |
| 31 | NOTHING, | 36 | private Nothing() {} |
| 32 | NAMED, | 37 | @Override public Type getType() { return Type.NOTHING; } |
| 33 | } | 38 | } |
| 34 | } | 39 | } |