Class Retrofitter

java.lang.Object
org.objectweb.asm.tools.Retrofitter

public final class Retrofitter extends Object
A tool to transform classes in order to make them compatible with Java 1.5, and to check that they use only the JDK 1.5 API and JDK 1.5 class file features. The original classes can either be transformed "in place", or be copied first to destination directory and transformed here (leaving the original classes unchanged).
  • Field Details

    • MODULE_INFO

      private static final String MODULE_INFO
      The name of the module-info file.
      See Also:
    • JAVA_BASE_MODULE

      private static final String JAVA_BASE_MODULE
      The name of the java.base module.
      See Also:
    • STRING_CONCAT_FACTORY_HANDLE

      private static final Handle STRING_CONCAT_FACTORY_HANDLE
      Bootstrap method for the string concatenation using indy.
    • jdkApi

      private final HashSet<String> jdkApi
      The fields and methods of the JDK 1.5 API. Each string has the form "<owner><name><descriptor>".
    • jdkHierarchy

      private final HashMap<String,String> jdkHierarchy
      The class hierarchy of the JDK 1.5 API. Maps each class name to the name of its super class.
    • exports

      private final HashSet<String> exports
      The internal names of the packages exported by the retrofitted classes.
    • imports

      private final HashSet<String> imports
      The internal names of the packages imported by the retrofitted classes.
  • Constructor Details

    • Retrofitter

      public Retrofitter()
  • Method Details

    • main

      public static void main(String[] args) throws IOException
      Transforms the class files in the given directory, in place, in order to make them compatible with the JDK 1.5. Also generates a module-info class in this directory, with the given module version.
      Parameters:
      args - a directory containing compiled classes and the ASM release version.
      Throws:
      IOException - if a file can't be read or written.
    • retrofit

      public void retrofit(Path classesDir, String version) throws IOException
      Transforms the class files in the given directory, in place, in order to make them compatible with the JDK 1.5. Also generates a module-info class in this directory, with the given module version.
      Parameters:
      classesDir - a directory containing compiled classes.
      version - the module-info version.
      Throws:
      IOException - if a file can't be read or written.
    • verify

      public void verify(Path classesDir, String expectedVersion, List<String> expectedExports, List<String> expectedRequires) throws IOException
      Verify that the class files in the given directory only use JDK 1.5 APIs, and that a module-info class is present with the expected content.
      Parameters:
      classesDir - a directory containing compiled classes.
      expectedVersion - the expected module-info version.
      expectedExports - the expected module-info exported packages.
      expectedRequires - the expected module-info required modules.
      Throws:
      IOException - if a file can't be read.
      IllegalArgumentException - if the module-info class does not have the expected content.
    • getClassReaders

      private List<ClassReader> getClassReaders(List<Path> classFiles) throws IOException
      Throws:
      IOException
    • getAllClasses

      private List<Path> getAllClasses(Path path, boolean includeModuleInfo) throws IOException
      Throws:
      IOException
    • checkPrivateMemberAccess

      private static void checkPrivateMemberAccess(List<ClassReader> readers)
      Checks that no code accesses to a private member from another class. If there is a private access, removing the nestmate attributes is not a legal transformation.
    • generateModuleInfoClass

      private void generateModuleInfoClass(Path dstDir, String version) throws IOException
      Throws:
      IOException
    • verifyModuleInfoClass

      private void verifyModuleInfoClass(Path dstDir, String expectedVersion, Set<String> expectedExports, Set<String> expectedRequires) throws IOException
      Throws:
      IOException
    • isAsmModule

      private static boolean isAsmModule(String packageName)
    • readJdkApi

      private void readJdkApi() throws IOException
      Throws:
      IOException