Class AsmDecompiler

java.lang.Object
org.codehaus.groovy.ast.decompiled.AsmDecompiler

public abstract class AsmDecompiler extends Object
Utility class responsible for decompiling JVM class files into ClassStub objects that reflect their bytecode structure. Uses ASM to parse compiled bytecode and extract class metadata including fields, methods, constructors, and annotations without requiring access to source code.

Parsed stubs are cached using soft references indexed by URI, enabling efficient reuse across multiple compilations in the same JVM and in test scenarios. The cache occasionally allows misses when multiple threads simultaneously load the same class, but this is acceptable as it avoids serious memory issues.

The decompiler skips synthetic class initializers (<clinit>) and frame debug information during parsing.

See Also:
  • Constructor Details

    • AsmDecompiler

      public AsmDecompiler()
  • Method Details

    • parseClass

      public static ClassStub parseClass(URL url) throws IOException
      Loads the URL contents and parses them with ASM, producing a ClassStub object representing the structure of the corresponding class file. Stubs are cached and reused if queried several times with equal URLs.
      Parameters:
      url - a URL from a class loader, most likely a file system file or a JAR entry
      Returns:
      the class stub containing all extracted bytecode metadata
      Throws:
      IOException - if reading from this URL is impossible
      GroovyRuntimeException - if the URL cannot be converted to a valid URI
    • readClassName

      public static String readClassName(URL url) throws IOException
      Reads the binary name of the class at url after parseClass(URL). Hits the stub cache, so a resolver that already decompiled url does not parse again when a class loader later asks the same question.
      Throws:
      IOException