Skip to content

Commit edac706

Browse files
committed
Make bytecode decompilers more extensible
1 parent 9e7f396 commit edac706

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
* @author Bibl
1818
*/
1919
public class InstructionPrinter {
20-
private final MethodNodeDecompiler parent;
20+
protected final MethodNodeDecompiler parent;
2121

2222
/**
2323
* The MethodNode to print
2424
**/
25-
protected MethodNode mNode;
26-
private TypeAndName[] args;
25+
protected final MethodNode mNode;
26+
protected final TypeAndName[] args;
2727

2828
protected int[] pattern;
2929
protected boolean match;

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

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616

1717
public class MethodNodeDecompiler {
18-
private final BytecodeDecompiler parent;
18+
protected final BytecodeDecompiler parent;
1919
protected final PrefixedStringBuilder sb;
2020
protected final MethodNode mn;
2121
protected final ClassNode cn;
22+
protected boolean printDetailedMetadata = true;
2223

2324
public MethodNodeDecompiler(BytecodeDecompiler parent, PrefixedStringBuilder sb, MethodNode mn, ClassNode cn) {
2425
this.parent = parent;
@@ -134,31 +135,33 @@ else if (mn.name.equals("<init>"))
134135

135136
InstructionPrinter insnPrinter = getInstructionPrinter(mn, args);
136137

137-
addAttrList(mn.attrs, "attr", sb, insnPrinter);
138-
addAttrList(mn.invisibleAnnotations, "invisAnno", sb, insnPrinter);
139-
addAttrList(mn.invisibleAnnotations, "invisLocalVarAnno", sb, insnPrinter);
140-
addAttrList(mn.invisibleTypeAnnotations, "invisTypeAnno", sb, insnPrinter);
141-
addAttrList(mn.localVariables, "localVar", sb, insnPrinter);
142-
addAttrList(mn.visibleAnnotations, "visAnno", sb, insnPrinter);
143-
addAttrList(mn.visibleLocalVariableAnnotations, "visLocalVarAnno", sb, insnPrinter);
144-
addAttrList(mn.visibleTypeAnnotations, "visTypeAnno", sb, insnPrinter);
145-
146-
// Exception table
147-
for (Object o : mn.tryCatchBlocks) {
148-
TryCatchBlockNode tcbn = (TryCatchBlockNode) o;
149-
sb.append(" ");
150-
sb.append("TryCatch: L");
151-
sb.append(insnPrinter.resolveLabel(tcbn.start));
152-
sb.append(" to L");
153-
sb.append(insnPrinter.resolveLabel(tcbn.end));
154-
sb.append(" handled by L");
155-
sb.append(insnPrinter.resolveLabel(tcbn.handler));
156-
sb.append(": ");
157-
if (tcbn.type != null)
158-
sb.append(tcbn.type);
159-
else
160-
sb.append("Type is null.");
161-
sb.append(JDA.nl);
138+
if (printDetailedMetadata) {
139+
addAttrList(mn.attrs, "attr", sb, insnPrinter);
140+
addAttrList(mn.invisibleAnnotations, "invisAnno", sb, insnPrinter);
141+
addAttrList(mn.invisibleAnnotations, "invisLocalVarAnno", sb, insnPrinter);
142+
addAttrList(mn.invisibleTypeAnnotations, "invisTypeAnno", sb, insnPrinter);
143+
addAttrList(mn.localVariables, "localVar", sb, insnPrinter);
144+
addAttrList(mn.visibleAnnotations, "visAnno", sb, insnPrinter);
145+
addAttrList(mn.visibleLocalVariableAnnotations, "visLocalVarAnno", sb, insnPrinter);
146+
addAttrList(mn.visibleTypeAnnotations, "visTypeAnno", sb, insnPrinter);
147+
148+
// Exception table
149+
for (Object o : mn.tryCatchBlocks) {
150+
TryCatchBlockNode tcbn = (TryCatchBlockNode) o;
151+
sb.append(" ");
152+
sb.append("TryCatch: L");
153+
sb.append(insnPrinter.resolveLabel(tcbn.start));
154+
sb.append(" to L");
155+
sb.append(insnPrinter.resolveLabel(tcbn.end));
156+
sb.append(" handled by L");
157+
sb.append(insnPrinter.resolveLabel(tcbn.handler));
158+
sb.append(": ");
159+
if (tcbn.type != null)
160+
sb.append(tcbn.type);
161+
else
162+
sb.append("Type is null.");
163+
sb.append(JDA.nl);
164+
}
162165
}
163166

164167
// Instructions
@@ -269,4 +272,8 @@ boolean createDescriptors() {
269272
boolean appendHandlerComments() {
270273
return parent.getSettings().getEntry("append-handler-comments").getBool();
271274
}
275+
276+
public BytecodeDecompiler getParent() {
277+
return parent;
278+
}
272279
}

0 commit comments

Comments
 (0)