Class ClassDecompiler
- java.lang.Object
-
- com.tonic.analysis.source.decompile.ClassDecompiler
-
public class ClassDecompiler extends Object
Decompiler that turns a ClassFile into formatted Java source: the class declaration, fields, and recovered method bodies.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClassDecompiler.BuilderBuilder for ClassDecompiler with a fluent configuration API.
-
Constructor Summary
Constructors Constructor Description ClassDecompiler(ClassFile classFile)Creates a decompiler for the class with the default configuration.ClassDecompiler(ClassFile classFile, DecompilerConfig config)Creates a decompiler with a full decompiler configuration.ClassDecompiler(ClassFile classFile, SourceEmitterConfig config)Creates a decompiler with a custom source emitter configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClassDecompiler.Builderbuilder(ClassFile classFile)Creates a builder for configuring a ClassDecompiler.Stringdecompile()Decompiles the entire class.voiddecompile(IndentingWriter writer)Decompiles the entire class to the given writer.static Stringdecompile(ClassFile classFile)Decompiles a class with the default configuration.static Stringdecompile(ClassFile classFile, SourceEmitterConfig config)Decompiles a class with a custom emitter configuration.DecompileResultdecompileWithLineMap()Decompiles the class and additionally collects, per method, a map from bytecode offset to the 1-based output line of the statement recovered from that offset.LocalVariableTableAttributelocalVariableTableFor(MethodEntry method)Builds a syntheticLocalVariableTableAttributefrom the recovered slot names, keyed to the original bytecode offsets, for injecting named locals into a stripped class - the names match whatdecompile()renders.
-
-
-
Constructor Detail
-
ClassDecompiler
public ClassDecompiler(ClassFile classFile)
Creates a decompiler for the class with the default configuration.- Parameters:
classFile- the class to decompile
-
ClassDecompiler
public ClassDecompiler(ClassFile classFile, SourceEmitterConfig config)
Creates a decompiler with a custom source emitter configuration.- Parameters:
classFile- the class to decompileconfig- the emitter configuration
-
ClassDecompiler
public ClassDecompiler(ClassFile classFile, DecompilerConfig config)
Creates a decompiler with a full decompiler configuration.- Parameters:
classFile- the class to decompileconfig- the configuration; defaults are used when null
-
-
Method Detail
-
builder
public static ClassDecompiler.Builder builder(ClassFile classFile)
Creates a builder for configuring a ClassDecompiler.- Parameters:
classFile- the class file to decompile- Returns:
- a new builder instance
-
localVariableTableFor
public LocalVariableTableAttribute localVariableTableFor(MethodEntry method)
Builds a syntheticLocalVariableTableAttributefrom the recovered slot names, keyed to the original bytecode offsets, for injecting named locals into a stripped class - the names match whatdecompile()renders.- Parameters:
method- the method to recover slot names for- Returns:
- the synthetic table, or null if the method has no Code or recovery fails
-
decompile
public String decompile()
Decompiles the entire class.- Returns:
- the Java source text
-
decompileWithLineMap
public DecompileResult decompileWithLineMap()
Decompiles the class and additionally collects, per method, a map from bytecode offset to the 1-based output line of the statement recovered from that offset.- Returns:
- the source text together with the per-method line maps and declaration spans
-
decompile
public void decompile(IndentingWriter writer)
Decompiles the entire class to the given writer.- Parameters:
writer- the writer that receives the source text
-
decompile
public static String decompile(ClassFile classFile)
Decompiles a class with the default configuration.- Parameters:
classFile- the class to decompile- Returns:
- the Java source text
-
decompile
public static String decompile(ClassFile classFile, SourceEmitterConfig config)
Decompiles a class with a custom emitter configuration.- Parameters:
classFile- the class to decompileconfig- the emitter configuration- Returns:
- the Java source text
-
-