Skip to content

Commit 206de7a

Browse files
committed
Start on decompiler settings refactor
1 parent 77d69e2 commit 206de7a

File tree

9 files changed

+447
-490
lines changed

9 files changed

+447
-490
lines changed

src/main/java/the/bytecode/club/jda/decompilers/CFRDecompiler.java

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import the.bytecode.club.jda.JDA;
2323
import the.bytecode.club.jda.JarUtils;
2424
import the.bytecode.club.jda.settings.DecompilerSettings;
25+
import the.bytecode.club.jda.settings.Setting;
2526

2627
import java.io.File;
2728
import java.io.IOException;
@@ -37,9 +38,9 @@
3738
public final class CFRDecompiler extends Decompiler {
3839

3940
public CFRDecompiler() {
40-
for (Settings setting : Settings.values()) {
41-
settings.registerSetting(setting);
42-
}
41+
// for (Settings setting : Settings.values()) {
42+
// settings.registerSetting(setting);
43+
// }
4344
}
4445

4546
@Override
@@ -98,14 +99,15 @@ public void decompileToZip(String zipName) {
9899
}
99100

100101
public String[] generateMainMethod() {
101-
String[] result = new String[getSettings().size() * 2 + 1];
102-
result[0] = "bytecodeviewer";
103-
int index = 1;
104-
for (Settings setting : Settings.values()) {
105-
result[index++] = "--" + setting.getParam();
106-
result[index++] = String.valueOf(getSettings().getBoolean(setting));
107-
}
108-
return result;
102+
// String[] result = new String[getSettings().size() * 2 + 1];
103+
// result[0] = "bytecodeviewer";
104+
// int index = 1;
105+
// for (Settings setting : Settings.values()) {
106+
// result[index++] = "--" + setting.getParam();
107+
// result[index++] = String.valueOf(getSettings().getBoolean(setting));
108+
// }
109+
// return result;
110+
return new String[0];
109111
}
110112

111113
public static String doClass(DCCommonState dcCommonState, byte[] content1) throws Exception {
@@ -192,51 +194,52 @@ public static void doJar(DCCommonState dcCommonState, Path input, Path output) t
192194
}
193195

194196
// TODO: Rewrite!
195-
public enum Settings implements DecompilerSettings.SettingsEntry {
196-
DECODE_ENUM_SWITCH("decodeenumswitch", "Decode Enum Switch", true),
197-
SUGAR_ENUMS("sugarenums", "SugarEnums", true),
198-
DECODE_STRING_SWITCH("decodestringswitch", "Decode String Switch", true),
199-
ARRAYITER("arrayiter", "Arrayiter", true),
200-
COLLECTIONITER("collectioniter", "Collectioniter", true),
201-
INNER_CLASSES("innerclasses", "Inner Classes", true),
202-
REMOVE_BOILER_PLATE("removeboilerplate", "Remove Boiler Plate", true),
203-
REMOVE_INNER_CLASS_SYNTHETICS("removeinnerclasssynthetics", "Remove Inner Class Synthetics", true),
204-
DECODE_LAMBDAS("decodelambdas", "Decode Lambdas", true),
205-
HIDE_BRIDGE_METHODS("hidebridgemethods", "Hide Bridge Methods", true),
206-
LIFT_CONSTRUCTOR_INIT("liftconstructorinit", "Lift Constructor Init", true),
207-
REMOVE_DEAD_METHODS("removedeadmethods", "Remove Dead Methods", true),
208-
REMOVE_BAD_GENERICS("removebadgenerics", "Remove Bad Generics", true),
209-
SUGAR_ASSERTS("sugarasserts", "Sugar Asserts", true),
210-
SUGAR_BOXING("sugarboxing", "Sugar Boxing", true),
211-
SHOW_VERSION("showversion", "Show Version", true),
212-
DECODE_FINALLY("decodefinally", "Decode Finally", true),
213-
TIDY_MONITORS("tidymonitors", "Tidy Monitors", true),
214-
LENIENT("lenient", "Lenient"),
215-
DUMP_CLASS_PATH("dumpclasspath", "Dump Classpath"),
216-
COMMENTS("comments", "Comments", true),
217-
FORCE_TOP_SORT("forcetopsort", "Force Top Sort", true),
218-
FORCE_TOP_SORT_AGGRESSIVE("forcetopsortaggress", "Force Top Sort Aggressive", true),
219-
STRINGBUFFER("stringbuffer", "StringBuffer"),
220-
STRINGBUILDER("stringbuilder", "StringBuilder", true),
221-
SILENT("silent", "Silent", true),
222-
RECOVER("recover", "Recover", true),
223-
ECLIPSE("eclipse", "Eclipse", true),
224-
OVERRIDE("override", "Override", true),
225-
SHOW_INFERRABLE("showinferrable", "Show Inferrable", true),
226-
FORCE_AGGRESSIVE_EXCEPTION_AGG("aexagg", "Force Aggressive Exception Aggregation", true),
227-
FORCE_COND_PROPAGATE("forcecondpropagate", "Force Conditional Propogation", true),
228-
HIDE_UTF("hideutf", "Hide UTF", true),
229-
HIDE_LONG_STRINGS("hidelongstrings", "Hide Long Strings"),
230-
COMMENT_MONITORS("commentmonitors", "Comment Monitors"),
231-
ALLOW_CORRECTING("allowcorrecting", "Allow Correcting", true),
232-
LABELLED_BLOCKS("labelledblocks", "Labelled Blocks", true),
233-
J14_CLASS_OBJ("j14classobj", "Java 1.4 Class Objects"),
234-
HIDE_LANG_IMPORTS("hidelangimports", "Hide Lang Imports", true),
235-
RECOVER_TYPE_CLASH("recovertypeclash", "Recover Type Clash", true),
236-
RECOVER_TYPE_HINTS("recovertypehints", "Recover Type Hints", true),
237-
FORCE_RETURNING_IFS("forcereturningifs", "Force Returning Ifs", true),
238-
FOR_LOOP_AGG_CAPTURE("forloopaggcapture", "For Loop Aggressive Capture", true);
239-
197+
public enum Settings {
198+
;
199+
// DECODE_ENUM_SWITCH("decodeenumswitch", "Decode Enum Switch", true),
200+
// SUGAR_ENUMS("sugarenums", "SugarEnums", true),
201+
// DECODE_STRING_SWITCH("decodestringswitch", "Decode String Switch", true),
202+
// ARRAYITER("arrayiter", "Arrayiter", true),
203+
// COLLECTIONITER("collectioniter", "Collectioniter", true),
204+
// INNER_CLASSES("innerclasses", "Inner Classes", true),
205+
// REMOVE_BOILER_PLATE("removeboilerplate", "Remove Boiler Plate", true),
206+
// REMOVE_INNER_CLASS_SYNTHETICS("removeinnerclasssynthetics", "Remove Inner Class Synthetics", true),
207+
// DECODE_LAMBDAS("decodelambdas", "Decode Lambdas", true),
208+
// HIDE_BRIDGE_METHODS("hidebridgemethods", "Hide Bridge Methods", true),
209+
// LIFT_CONSTRUCTOR_INIT("liftconstructorinit", "Lift Constructor Init", true),
210+
// REMOVE_DEAD_METHODS("removedeadmethods", "Remove Dead Methods", true),
211+
// REMOVE_BAD_GENERICS("removebadgenerics", "Remove Bad Generics", true),
212+
// SUGAR_ASSERTS("sugarasserts", "Sugar Asserts", true),
213+
// SUGAR_BOXING("sugarboxing", "Sugar Boxing", true),
214+
// SHOW_VERSION("showversion", "Show Version", true),
215+
// DECODE_FINALLY("decodefinally", "Decode Finally", true),
216+
// TIDY_MONITORS("tidymonitors", "Tidy Monitors", true),
217+
// LENIENT("lenient", "Lenient"),
218+
// DUMP_CLASS_PATH("dumpclasspath", "Dump Classpath"),
219+
// COMMENTS("comments", "Comments", true),
220+
// FORCE_TOP_SORT("forcetopsort", "Force Top Sort", true),
221+
// FORCE_TOP_SORT_AGGRESSIVE("forcetopsortaggress", "Force Top Sort Aggressive", true),
222+
// STRINGBUFFER("stringbuffer", "StringBuffer"),
223+
// STRINGBUILDER("stringbuilder", "StringBuilder", true),
224+
// SILENT("silent", "Silent", true),
225+
// RECOVER("recover", "Recover", true),
226+
// ECLIPSE("eclipse", "Eclipse", true),
227+
// OVERRIDE("override", "Override", true),
228+
// SHOW_INFERRABLE("showinferrable", "Show Inferrable", true),
229+
// FORCE_AGGRESSIVE_EXCEPTION_AGG("aexagg", "Force Aggressive Exception Aggregation", true),
230+
// FORCE_COND_PROPAGATE("forcecondpropagate", "Force Conditional Propogation", true),
231+
// HIDE_UTF("hideutf", "Hide UTF", true),
232+
// HIDE_LONG_STRINGS("hidelongstrings", "Hide Long Strings"),
233+
// COMMENT_MONITORS("commentmonitors", "Comment Monitors"),
234+
// ALLOW_CORRECTING("allowcorrecting", "Allow Correcting", true),
235+
// LABELLED_BLOCKS("labelledblocks", "Labelled Blocks", true),
236+
// J14_CLASS_OBJ("j14classobj", "Java 1.4 Class Objects"),
237+
// HIDE_LANG_IMPORTS("hidelangimports", "Hide Lang Imports", true),
238+
// RECOVER_TYPE_CLASH("recovertypeclash", "Recover Type Clash", true),
239+
// RECOVER_TYPE_HINTS("recovertypehints", "Recover Type Hints", true),
240+
// FORCE_RETURNING_IFS("forcereturningifs", "Force Returning Ifs", true),
241+
// FOR_LOOP_AGG_CAPTURE("forloopaggcapture", "For Loop Aggressive Capture", true);
242+
//
240243
private String name;
241244
private String param;
242245
private boolean on;
@@ -263,8 +266,8 @@ public String getDefaultValue() {
263266
return String.valueOf(on);
264267
}
265268

266-
public SettingType getType() {
267-
return SettingType.BOOLEAN;
269+
public Setting.SettingType getType() {
270+
return Setting.SettingType.BOOLEAN;
268271
}
269272
}
270273
}

src/main/java/the/bytecode/club/jda/decompilers/Decompilers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class Decompilers {
1111
static final Map<String, Decompiler> BY_NAME = new LinkedHashMap<>();
1212

13-
public final static Decompiler PROCYON = new ProcyonDecompiler();
13+
public final static Decompiler PROCYON = new FernflowerDecompiler(); //TODo
1414
public final static Decompiler CFR = new CFRDecompiler();
1515
public final static Decompiler FERNFLOWER = new FernflowerDecompiler();
1616
public final static Decompiler BYTECODE = new ClassNodeDecompiler();

src/main/java/the/bytecode/club/jda/decompilers/FernflowerDecompiler.java

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
import org.objectweb.asm.tree.InnerClassNode;
1010
import the.bytecode.club.jda.JDA;
1111
import the.bytecode.club.jda.JarUtils;
12-
import the.bytecode.club.jda.settings.DecompilerSettings;
12+
import the.bytecode.club.jda.settings.DecompilerSettings.SettingsEntry;
13+
import the.bytecode.club.jda.settings.Setting;
1314

1415
import java.io.File;
1516
import java.nio.file.Files;
1617
import java.nio.file.Path;
18+
import java.util.ArrayList;
1719
import java.util.HashMap;
20+
import java.util.List;
1821
import java.util.Map;
1922
import java.util.concurrent.atomic.AtomicReference;
2023
import java.util.jar.Manifest;
@@ -28,9 +31,6 @@
2831

2932
public final class FernflowerDecompiler extends Decompiler {
3033
public FernflowerDecompiler() {
31-
for (Settings setting : Settings.values()) {
32-
settings.registerSetting(setting);
33-
}
3434
}
3535

3636
@Override
@@ -131,72 +131,69 @@ public void decompileToZip(String zipName) {
131131
}
132132
}
133133

134-
private Map<String, Object> generateFernflowerArgs() {
134+
private static Map<String, Object> generateFernflowerArgs() {
135135
Map<String, Object> options = new HashMap<>();
136-
for (Settings setting : Settings.values()) {
137-
options.put(setting.getParam(), getSettings().getValue(setting));
136+
for (SettingsEntry setting : FernflowerDecompiler.settings) {
137+
options.put(setting.param, setting.get());
138+
System.out.println(setting.param + " " + setting.get());
138139
}
139140
return options;
140141
}
141142

142-
public enum Settings implements DecompilerSettings.SettingsEntry {
143-
HIDE_BRIDGE_METHODS("rbr", "Hide Bridge Methods", "true"),
144-
HIDE_SYNTHETIC_CLASS_MEMBERS("rsy", "Hide Synthetic Class Members", "false"),
145-
DECOMPILE_INNER_CLASSES("din", "Decompile Inner Classes", "true"),
146-
COLLAPSE_14_CLASS_REFERENCES("dc4", "Collapse 1.4 Class References", "true"),
147-
DECOMPILE_ASSERTIONS("das", "Decompile Assertions", "true"),
148-
HIDE_EMPTY_SUPER_INVOCATION("hes", "Hide Empty Super Invocation", "true"),
149-
HIDE_EMPTY_DEFAULT_CONSTRUCTOR("hec", "Hide Empty Default Constructor", "true"),
150-
DECOMPILE_GENERIC_SIGNATURES("dgs", "Decompile Generic Signatures", "false"),
151-
ASSUME_RETURN_NOT_THROWING_EXCEPTIONS("ner", "Assume return not throwing exceptions", "true"),
152-
DECOMPILE_ENUMS("den", "Decompile enumerations", "true"),
153-
REMOVE_GETCLASS("rgn", "Remove getClass()", "true"),
154-
OUTPUT_NUMBERIC_LITERALS("lit", "Output numeric literals 'as-is'", "false"),
155-
ENCODE_UNICODE("asc", "Encode non-ASCII as unicode escapes", "true"),
156-
INT_1_AS_BOOLEAN_TRUE("bto", "Assume int 1 is boolean true", "true"),
157-
ALLOW_NOT_SET_SYNTHETIC("nns", "Allow not set synthetic attribute", "true"),
158-
NAMELESS_TYPES_AS_OBJECT("uto", "Consider nameless types as java.lang.Object", "true"),
159-
RECOVER_VARIABLE_NAMES("udv", "Recover variable names", "true"),
160-
REMOVE_EMPTY_EXCEPTIONS("rer", "Remove empty exceptions", "true"),
161-
DEINLINE_FINALLY("fdi", "De-inline finally", "true"),
162-
TIME_LIMIT("mpm", "Maximum processing time", "0", SettingType.INT), // this is a numeric setting!
163-
RENAME_AMBIGIOUS_MEMBERS("ren", "Rename ambigious members", "false"),
143+
private static List<SettingsEntry> settings = new ArrayList<>();
144+
145+
static
146+
{
147+
SettingsEntry HIDE_BRIDGE_METHODS = new SettingsEntry("rbr", "Hide Bridge Methods", "true");
148+
SettingsEntry HIDE_SYNTHETIC_CLASS_MEMBERS = new SettingsEntry("rsy", "Hide Synthetic Class Members", "false");
149+
SettingsEntry DECOMPILE_INNER_CLASSES = new SettingsEntry("din", "Decompile Inner Classes", "true");
150+
SettingsEntry COLLAPSE_14_CLASS_REFERENCES = new SettingsEntry("dc4", "Collapse 1.4 Class References", "true");
151+
SettingsEntry DECOMPILE_ASSERTIONS = new SettingsEntry("das", "Decompile Assertions", "true");
152+
SettingsEntry HIDE_EMPTY_SUPER_INVOCATION = new SettingsEntry("hes", "Hide Empty Super Invocation", "true");
153+
SettingsEntry HIDE_EMPTY_DEFAULT_CONSTRUCTOR = new SettingsEntry("hec", "Hide Empty Default Constructor", "true");
154+
SettingsEntry DECOMPILE_GENERIC_SIGNATURES = new SettingsEntry("dgs", "Decompile Generic Signatures", "false");
155+
SettingsEntry ASSUME_RETURN_NOT_THROWING_EXCEPTIONS = new SettingsEntry("ner", "Assume return not throwing exceptions", "true");
156+
SettingsEntry DECOMPILE_ENUMS = new SettingsEntry("den", "Decompile enumerations", "true");
157+
SettingsEntry REMOVE_GETCLASS = new SettingsEntry("rgn", "Remove getClass = new SettingsEntry()", "true");
158+
SettingsEntry OUTPUT_NUMBERIC_LITERALS = new SettingsEntry("lit", "Output numeric literals 'as-is'", "false");
159+
SettingsEntry ENCODE_UNICODE = new SettingsEntry("asc", "Encode non-ASCII as unicode escapes", "true");
160+
SettingsEntry INT_1_AS_BOOLEAN_TRUE = new SettingsEntry("bto", "Assume int 1 is boolean true", "true");
161+
SettingsEntry ALLOW_NOT_SET_SYNTHETIC = new SettingsEntry("nns", "Allow not set synthetic attribute", "true");
162+
SettingsEntry NAMELESS_TYPES_AS_OBJECT = new SettingsEntry("uto", "Consider nameless types as java.lang.Object", "true");
163+
SettingsEntry RECOVER_VARIABLE_NAMES = new SettingsEntry("udv", "Recover variable names", "true");
164+
SettingsEntry REMOVE_EMPTY_EXCEPTIONS = new SettingsEntry("rer", "Remove empty exceptions", "true");
165+
SettingsEntry DEINLINE_FINALLY = new SettingsEntry("fdi", "De-inline finally", "true");
166+
SettingsEntry TIME_LIMIT = new SettingsEntry("mpm", "Maximum processing time", "0", Setting.SettingType.INT); // this is a numeric setting!
167+
SettingsEntry RENAME_AMBIGIOUS_MEMBERS = new SettingsEntry("ren", "Rename ambigious members", "false");
164168
// urc: IIDentifierRenamer
165-
REMOVE_INTELLIJ_NOTNULL("inn", "Remove IntelliJ @NotNull", "true"),
166-
DECOMPILE_LAMBDA_TO_ANONYMOUS("lac", "Decompile lambdas to anonymous classes", "false"),
167-
// NEWLINE_TYPE("nls", "Newline character"); // this is an optional argument!
168-
INDENTATION("ind", "Indentation string", " ", SettingType.STRING);
169-
170-
private final String name;
171-
private final String param;
172-
private final String defaultValue;
173-
private final SettingType type;
174-
175-
Settings(String param, String name, String defaultValue) {
176-
this(param, name, defaultValue, SettingType.BOOLEAN);
177-
}
178-
179-
Settings(String param, String name, String defaultValue, SettingType type) {
180-
this.name = name;
181-
this.param = param;
182-
this.defaultValue = defaultValue;
183-
this.type = type;
184-
}
185-
186-
public String getText() {
187-
return name;
188-
}
189-
190-
public String getParam() {
191-
return param;
192-
}
193-
194-
public String getDefaultValue() {
195-
return defaultValue;
196-
}
197-
198-
public SettingType getType() {
199-
return type;
200-
}
169+
SettingsEntry REMOVE_INTELLIJ_NOTNULL = new SettingsEntry("inn", "Remove IntelliJ @NotNull", "true");
170+
SettingsEntry DECOMPILE_LAMBDA_TO_ANONYMOUS = new SettingsEntry("lac", "Decompile lambdas to anonymous classes", "false");
171+
// NEWLINE_TYPE = new SettingsEntry("nls", "Newline character"); // this is an optional argument!
172+
SettingsEntry INDENTATION = new SettingsEntry("ind", "Indentation string", " ", Setting.SettingType.STRING);
173+
174+
settings.add(HIDE_BRIDGE_METHODS);
175+
settings.add(HIDE_SYNTHETIC_CLASS_MEMBERS);
176+
settings.add(DECOMPILE_INNER_CLASSES);
177+
settings.add(COLLAPSE_14_CLASS_REFERENCES);
178+
settings.add(DECOMPILE_ASSERTIONS);
179+
settings.add(HIDE_EMPTY_SUPER_INVOCATION);
180+
settings.add(HIDE_EMPTY_DEFAULT_CONSTRUCTOR);
181+
settings.add(DECOMPILE_GENERIC_SIGNATURES);
182+
settings.add(ASSUME_RETURN_NOT_THROWING_EXCEPTIONS);
183+
settings.add(DECOMPILE_ENUMS);
184+
settings.add(REMOVE_GETCLASS);
185+
settings.add(OUTPUT_NUMBERIC_LITERALS);
186+
settings.add(ENCODE_UNICODE);
187+
settings.add(INT_1_AS_BOOLEAN_TRUE);
188+
settings.add(ALLOW_NOT_SET_SYNTHETIC);
189+
settings.add(NAMELESS_TYPES_AS_OBJECT);
190+
settings.add(RECOVER_VARIABLE_NAMES);
191+
settings.add(REMOVE_EMPTY_EXCEPTIONS);
192+
settings.add(DEINLINE_FINALLY);
193+
settings.add(TIME_LIMIT);
194+
settings.add(RENAME_AMBIGIOUS_MEMBERS);
195+
settings.add(REMOVE_INTELLIJ_NOTNULL);
196+
settings.add(DECOMPILE_LAMBDA_TO_ANONYMOUS);
197+
settings.add(INDENTATION);
201198
}
202199
}

0 commit comments

Comments
 (0)