From 1fd741f7d5019b929affd29741b5ce92d7993f0f Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Thu, 22 Aug 2024 22:04:14 +0800 Subject: Fix bug in checker that made it not execute and made ArgSpec less likely to cause accidental errors. --- ast/src/main/java/lv/enes/orang/ast/ArgSpec.java | 43 +++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'ast/src/main/java/lv') 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 @@ package lv.enes.orang.ast; -public class ArgSpec { - public final Type type; +public sealed interface ArgSpec { + enum Type { + IGNORED, + NOTHING, + NAMED, + } - // non-null if NAMED - public final String name; + Type getType(); - private static final ArgSpec NOTHING = new ArgSpec(Type.NOTHING, null); - private static final ArgSpec IGNORED = new ArgSpec(Type.IGNORED, null); + static Ignored ignored() { + return Ignored.INSTANCE; + } - public static ArgSpec ignored() { - return IGNORED; + static Named named(String name) { + return new Named(name); } - public static ArgSpec nothing() { - return NOTHING; + static Nothing nothing() { + return Nothing.INSTANCE; } - public static ArgSpec named(String name) { - return new ArgSpec(Type.NAMED, name); + final class Ignored implements ArgSpec { + public static final Ignored INSTANCE = new Ignored(); + private Ignored() {} + @Override public Type getType() { return Type.IGNORED; } } - private ArgSpec(Type type, String name) { - this.type = type; - this.name = name; + record Named(String name) implements ArgSpec { + @Override public Type getType() { return Type.NAMED; } } - public enum Type { - IGNORED, - NOTHING, - NAMED, + final class Nothing implements ArgSpec { + public static final Nothing INSTANCE = new Nothing(); + private Nothing() {} + @Override public Type getType() { return Type.NOTHING; } } } -- cgit v1.2.3