Skip to content

Latest commit

 

History

History
 
 

tree_shaker

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

J2ObjC Tree Shaker

About: The tree shaker project is an experimental tool in the J2ObjC family that lets users detect any unused code in their Java program. The purpose of the tool is to provide the translator with a list of unused elements in the code that it can remove to reduce the size of the translated project.

Usage: The tree shaker can be used in two ways:

  1. Manual Analysis: Using the tree shaker by itself on a package of source files, it will report a set of classes and methods that it detected as unused.
  2. Dead Code Elimination in Translator: The tree-shaker-report output file, generated by the tree shaker, can be used as an input to the translator, using its Dead Code Elimination functionality (see the docs for translator). This will automatically remove the unused code reported by the tree shaker from the final translated source code.

Running Tree Shaker: The tree shaker command takes in a few flags, as seen in the help message: help-message = Usage: tree_shaker where possible options include: -sourcepath Specify where to find input source files. -classpath Specify where to find user class files. --tree-shaker-roots Specify a file that lists the public root classes and methods. -s, --sourcefilelist Specify a file that lists the source files to be analyzed.

All elements in the input source files that can be reached from the public roots will be kept, and the others marked as unused. The input file formatting for classes is the full packageName.className for the class (eg. com.google.devtools.treeshaker.TreeShaker), and accepts one class per line. When indicating a class as a public root, the tree shaker will take all public methods inside that class and add them to the public root set, for convenience. To add specific methods to the public root set, add their enclosing class's packageName.className, followed by a colon, and all of the root set methods inside that class on the following lines, one on each line, preceded by 4 spaces (eg: simple.B: void test2())

Ending Note: The tree shaker tool is an experimental project, used at the user's own risk. The manual analysis use case is completely safe, and is the recommended way to analyze source code for unused elements while the tree shaker is still in testing. More adventurous users are encouraged to experiment with dead code elimination, find and/or fix bugs, and submit pull requests.