Class ClassDecompiler


  • public class ClassDecompiler
    extends Object
    Decompiler that turns a ClassFile into formatted Java source: the class declaration, fields, and recovered method bodies.
    • 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 decompile
        config - the emitter configuration
      • ClassDecompiler

        public ClassDecompiler​(ClassFile classFile,
                               DecompilerConfig config)
        Creates a decompiler with a full decompiler configuration.
        Parameters:
        classFile - the class to decompile
        config - 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 synthetic LocalVariableTableAttribute from the recovered slot names, keyed to the original bytecode offsets, for injecting named locals into a stripped class - the names match what decompile() 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 decompile
        config - the emitter configuration
        Returns:
        the Java source text