Format ASMifier
We could probably replace the formatter library with one that is more configurable. We're also stuck on Google Java Formatter 1.9 due to us having Java 1.8 support.
This commit is contained in:
parent
13510e3e42
commit
3158e83e0a
|
@ -22,6 +22,7 @@ import org.objectweb.asm.tree.ClassNode;
|
||||||
import org.objectweb.asm.util.ASMifier;
|
import org.objectweb.asm.util.ASMifier;
|
||||||
import org.objectweb.asm.util.TraceClassVisitor;
|
import org.objectweb.asm.util.TraceClassVisitor;
|
||||||
import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler;
|
import the.bytecode.club.bytecodeviewer.decompilers.AbstractDecompiler;
|
||||||
|
import the.bytecode.club.bytecodeviewer.util.JavaFormatterUtils;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -43,7 +44,7 @@ public class ASMifierGenerator extends AbstractDecompiler
|
||||||
{
|
{
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
cn.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer)));
|
cn.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer)));
|
||||||
return writer.toString();
|
return JavaFormatterUtils.formatJavaCode(writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package the.bytecode.club.bytecodeviewer.util;
|
||||||
|
|
||||||
|
import com.google.googlejavaformat.java.Formatter;
|
||||||
|
import com.google.googlejavaformat.java.FormatterException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Konloch
|
||||||
|
* @since 10/2/2024
|
||||||
|
*/
|
||||||
|
public class JavaFormatterUtils
|
||||||
|
{
|
||||||
|
public static String formatJavaCode(String decompiledCode)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new Formatter().formatSource(decompiledCode);
|
||||||
|
}
|
||||||
|
catch (FormatterException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
return decompiledCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user