8
8
import org .quiltmc .enigma .api .stats .StatType ;
9
9
import org .quiltmc .enigma .api .stats .StatsGenerator ;
10
10
import org .quiltmc .enigma .command .PrintStatsCommand .Required ;
11
+ import org .quiltmc .enigma .command .PrintStatsCommand .Optional ;
12
+ import org .quiltmc .enigma .util .I18n ;
11
13
import org .tinylog .Logger ;
12
14
13
15
import javax .annotation .Nullable ;
14
16
import java .nio .file .Path ;
17
+ import java .util .EnumSet ;
15
18
import java .util .Set ;
19
+ import java .util .stream .Collectors ;
16
20
17
21
import static org .quiltmc .enigma .command .CommonArguments .ENIGMA_PROFILE ;
18
22
import static org .quiltmc .enigma .command .CommonArguments .INPUT_JAR ;
19
23
import static org .quiltmc .enigma .command .CommonArguments .INPUT_MAPPINGS ;
20
24
21
- public final class PrintStatsCommand extends Command <Required , Path > {
25
+ public final class PrintStatsCommand extends Command <Required , Optional > {
26
+ private static final Argument <Set <StatType >> INCLUDED_TYPES = Argument .ofCollection (
27
+ "included-types" , Argument .alternativesOf (StatType .class , "&|" ),
28
+ """
29
+ The stat types to include.""" ,
30
+ string -> Argument .parseCaseInsensitiveEnum (StatType .class , string ),
31
+ Collectors .toUnmodifiableSet ()
32
+ );
33
+
34
+ private static final Argument <Boolean > INCLUDE_SYNTHETIC = Argument .ofBool ("include-synthetic" ,
35
+ """
36
+ Whether to include synthetic entries."""
37
+ );
38
+
39
+ private static final Argument <Boolean > COUNT_FALLBACK = Argument .ofBool ("count-fallback" ,
40
+ """
41
+ Whether to count fallback-proposed entries as mapped."""
42
+ );
43
+
22
44
public static final PrintStatsCommand INSTANCE = new PrintStatsCommand ();
23
45
24
46
private PrintStatsCommand () {
25
47
super (
26
48
ArgsParser .of (INPUT_JAR , INPUT_MAPPINGS , Required ::new ),
27
- ArgsParser .of (ENIGMA_PROFILE )
49
+ ArgsParser .of (ENIGMA_PROFILE , INCLUDED_TYPES , INCLUDE_SYNTHETIC , COUNT_FALLBACK , Optional :: new )
28
50
);
29
51
}
30
52
31
53
@ Override
32
- void runImpl (Required required , Path enigmaProfile ) throws Exception {
33
- run (required .inputJar , required .inputMappings , enigmaProfile , null );
54
+ void runImpl (Required required , Optional optional ) throws Exception {
55
+ final Set <StatType > includedTypes = optional .includedTypes == null || optional .includedTypes .isEmpty ()
56
+ ? EnumSet .allOf (StatType .class )
57
+ : optional .includedTypes ;
58
+
59
+ final GenerationParameters params = new GenerationParameters (
60
+ includedTypes ,
61
+ Boolean .TRUE .equals (optional .includeSynthetic ),
62
+ Boolean .TRUE .equals (optional .countFallback )
63
+ );
64
+
65
+ run (required .inputJar , required .inputMappings , optional .enigmaProfile , params , null );
34
66
}
35
67
36
68
@ Override
@@ -43,24 +75,44 @@ public String getDescription() {
43
75
return "Generates and prints out the statistics of how well the provided mappings cover the provided JAR file." ;
44
76
}
45
77
46
- public static void run (Path inJar , Path mappings , @ Nullable Path profilePath , @ Nullable Iterable <EnigmaPlugin > plugins ) throws Exception {
78
+ public static void run (
79
+ Path inJar , Path mappings , @ Nullable Path profilePath ,
80
+ @ Nullable GenerationParameters params , @ Nullable Iterable <EnigmaPlugin > plugins
81
+ ) throws Exception {
47
82
EnigmaProfile profile = EnigmaProfile .read (profilePath );
48
83
Enigma enigma = createEnigma (profile , plugins );
49
84
50
- run (inJar , mappings , enigma );
85
+ run (inJar , mappings , enigma , params );
51
86
}
52
87
53
- public static void run (Path inJar , Path mappings , Enigma enigma ) throws Exception {
88
+ public static void run (Path inJar , Path mappings , Enigma enigma , @ Nullable GenerationParameters params ) throws Exception {
54
89
StatsGenerator generator = new StatsGenerator (openProject (inJar , mappings , enigma ));
55
- ProjectStatsResult result = generator .generate (new ConsoleProgressListener (), new GenerationParameters (Set .of (StatType .values ())));
56
90
57
- Logger .info (String .format ("Overall mapped: %.2f%% (%s / %s)" , result .getPercentage (), result .getMapped (), result .getMappable ()));
58
- Logger .info (String .format ("Classes: %.2f%% (%s / %s)" , result .getPercentage (StatType .CLASSES ), result .getMapped (StatType .CLASSES ), result .getMappable (StatType .CLASSES )));
59
- Logger .info (String .format ("Fields: %.2f%% (%s / %s)" , result .getPercentage (StatType .FIELDS ), result .getMapped (StatType .FIELDS ), result .getMappable (StatType .FIELDS )));
60
- Logger .info (String .format ("Methods: %.2f%% (%s / %s)" , result .getPercentage (StatType .METHODS ), result .getMapped (StatType .METHODS ), result .getMappable (StatType .METHODS )));
61
- Logger .info (String .format ("Parameters: %.2f%% (%s / %s)" , result .getPercentage (StatType .PARAMETERS ), result .getMapped (StatType .PARAMETERS ), result .getMappable (StatType .PARAMETERS )));
91
+ if (params == null ) {
92
+ params = new GenerationParameters ();
93
+ }
94
+
95
+ ProjectStatsResult result = generator .generate (new ConsoleProgressListener (), params );
96
+
97
+ final Set <StatType > includedTypes = params .includedTypes ();
98
+
99
+ if (includedTypes .size () > 1 ) {
100
+ final String overall = I18n .translate ("menu.file.stats.overall" );
101
+ logResult (overall , result .getPercentage (), result .getMapped (), result .getMappable ());
102
+ }
103
+
104
+ for (final StatType type : StatType .values ()) {
105
+ if (includedTypes .contains (type )) {
106
+ logResult (type .getName (), result .getPercentage (type ), result .getMapped (type ), result .getMappable (type ));
107
+ }
108
+ }
109
+ }
110
+
111
+ private static void logResult (String label , double percentage , int mapped , int mappable ) {
112
+ Logger .info ("%s: %.2f%% (%s / %s)" .formatted (label , percentage , mapped , mappable ));
62
113
}
63
114
64
115
record Required (Path inputJar , Path inputMappings ) { }
116
+ record Optional (Path enigmaProfile , Set <StatType > includedTypes , Boolean includeSynthetic , Boolean countFallback ) { }
65
117
}
66
118
0 commit comments