Skip to content

Commit 66ac974

Browse files
make Command implementations singletons
1 parent b4f655b commit 66ac974

14 files changed

+52
-28
lines changed

enigma-cli/src/main/java/org/quiltmc/enigma/command/CheckMappingsCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import java.util.stream.Collectors;
1212

1313
public final class CheckMappingsCommand extends Command {
14-
public CheckMappingsCommand() {
14+
public static final CheckMappingsCommand INSTANCE = new CheckMappingsCommand();
15+
16+
private CheckMappingsCommand() {
1517
super(CommonArguments.INPUT_JAR, CommonArguments.INPUT_MAPPINGS);
1618
}
1719

enigma-cli/src/main/java/org/quiltmc/enigma/command/ComposeMappingsCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public final class ComposeMappingsCommand extends Command {
3030
Which mappings should overwrite the others when composing conflicting mappings. Allowed values are "left", "right", and "both"."""
3131
);
3232

33-
public ComposeMappingsCommand() {
33+
public static final ComposeMappingsCommand INSTANCE = new ComposeMappingsCommand();
34+
35+
private ComposeMappingsCommand() {
3436
super(LEFT_MAPPINGS, RIGHT_MAPPINGS, CommonArguments.MAPPING_OUTPUT, KEEP_MODE);
3537
}
3638

enigma-cli/src/main/java/org/quiltmc/enigma/command/ConvertMappingsCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import java.nio.file.Path;
1717

1818
public final class ConvertMappingsCommand extends Command {
19-
public ConvertMappingsCommand() {
19+
public static final ConvertMappingsCommand INSTANCE = new ConvertMappingsCommand();
20+
21+
private ConvertMappingsCommand() {
2022
super(
2123
CommonArguments.INPUT_MAPPINGS,
2224
CommonArguments.MAPPING_OUTPUT,

enigma-cli/src/main/java/org/quiltmc/enigma/command/DecompileCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ The decompiler to use when producing output. Allowed values are (case-insensitiv
2222
- BYTECODE"""
2323
);
2424

25-
public DecompileCommand() {
25+
public static final DecompileCommand INSTANCE = new DecompileCommand();
26+
27+
private DecompileCommand() {
2628
super(
2729
ImmutableList.of(DECOMPILER, CommonArguments.INPUT_JAR, CommonArguments.OUTPUT_JAR),
2830
ImmutableList.of(CommonArguments.INPUT_MAPPINGS)

enigma-cli/src/main/java/org/quiltmc/enigma/command/DeobfuscateCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.nio.file.Path;
88

99
public final class DeobfuscateCommand extends Command {
10-
public DeobfuscateCommand() {
10+
public static final DeobfuscateCommand INSTANCE = new DeobfuscateCommand();
11+
12+
private DeobfuscateCommand() {
1113
super(
1214
ImmutableList.of(CommonArguments.INPUT_JAR, CommonArguments.OUTPUT_JAR),
1315
ImmutableList.of(CommonArguments.INPUT_MAPPINGS)

enigma-cli/src/main/java/org/quiltmc/enigma/command/DropInvalidMappingsCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import java.nio.file.attribute.BasicFileAttributes;
1616

1717
public final class DropInvalidMappingsCommand extends Command {
18-
public DropInvalidMappingsCommand() {
18+
public static final DropInvalidMappingsCommand INSTANCE = new DropInvalidMappingsCommand();
19+
20+
private DropInvalidMappingsCommand() {
1921
super(
2022
ImmutableList.of(CommonArguments.INPUT_JAR, CommonArguments.INPUT_MAPPINGS),
2123
ImmutableList.of(CommonArguments.MAPPING_OUTPUT)

enigma-cli/src/main/java/org/quiltmc/enigma/command/FillClassMappingsCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public final class FillClassMappingsCommand extends Command {
2727
Whether to fill all possible mappings. Allowed values are "true" and "false"."""
2828
);
2929

30-
protected FillClassMappingsCommand() {
30+
public static final FillClassMappingsCommand INSTANCE = new FillClassMappingsCommand();
31+
32+
private FillClassMappingsCommand() {
3133
super(
3234
ImmutableList.of(
3335
CommonArguments.INPUT_JAR,
@@ -61,7 +63,7 @@ public String getDescription() {
6163
}
6264

6365
public static void run(Path jar, Path source, Path result, boolean fillAll, @Nullable String obfuscatedNamespace, @Nullable String deobfuscatedNamespace) throws Exception {
64-
boolean debug = shouldDebug(new FillClassMappingsCommand().getName());
66+
boolean debug = shouldDebug(INSTANCE.getName());
6567
JarIndex jarIndex = loadJar(jar);
6668
Enigma enigma = createEnigma();
6769

enigma-cli/src/main/java/org/quiltmc/enigma/command/HelpCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import java.util.Collection;
66

77
public final class HelpCommand extends Command {
8-
protected HelpCommand() {
8+
public static final HelpCommand INSTANCE = new HelpCommand();
9+
10+
private HelpCommand() {
911
super();
1012
}
1113

enigma-cli/src/main/java/org/quiltmc/enigma/command/InsertProposedMappingsCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import javax.annotation.Nullable;
2929

3030
public final class InsertProposedMappingsCommand extends Command {
31-
public InsertProposedMappingsCommand() {
31+
public static final InsertProposedMappingsCommand INSTANCE = new InsertProposedMappingsCommand();
32+
33+
private InsertProposedMappingsCommand() {
3234
super(
3335
ImmutableList.of(
3436
CommonArguments.INPUT_JAR,
@@ -73,7 +75,7 @@ public static void run(Path inJar, Path source, Path output, @Nullable Path prof
7375
}
7476

7577
public static void run(Path inJar, Path source, Path output, Enigma enigma, @Nullable String obfuscatedNamespace, @Nullable String deobfuscatedNamespace) throws Exception {
76-
boolean debug = shouldDebug(new InsertProposedMappingsCommand().getName());
78+
boolean debug = shouldDebug(INSTANCE.getName());
7779
int nameProposalServices = enigma.getServices().get(NameProposalService.TYPE).size();
7880
if (nameProposalServices == 0) {
7981
Logger.error("No name proposal services found!");

enigma-cli/src/main/java/org/quiltmc/enigma/command/InvertMappingsCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public final class InvertMappingsCommand extends Command {
2020
A path to the file or folder to write output to."""
2121
);
2222

23-
public InvertMappingsCommand() {
23+
public static final InvertMappingsCommand INSTANCE = new InvertMappingsCommand();
24+
25+
private InvertMappingsCommand() {
2426
super(
2527
ImmutableList.of(CommonArguments.INPUT_MAPPINGS, OUTPUT_FOLDER),
2628
ImmutableList.of(CommonArguments.OBFUSCATED_NAMESPACE, CommonArguments.DEOBFUSCATED_NAMESPACE)

0 commit comments

Comments
 (0)