Class ClassTree

  • All Implemented Interfaces:
    NameMapper

    public class ClassTree
    extends java.lang.Object
    implements NameMapper
    Tree structure of package levels, classes, methods and fields used for obfuscation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char CLASS_LEVEL
      The constant CLASS_LEVEL.
      static char METHOD_FIELD_LEVEL
      The constant METHOD_FIELD_LEVEL.
      static char PACKAGE_LEVEL
      The constant PACKAGE_LEVEL.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassTree()
      Ctor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addClassFile​(ClassFile cf)
      Add a classfile's package, class, method and field entries to database.
      void dump​(java.io.PrintWriter log)
      Dump the content of the class tree to the specified file (used for logging).
      Cl findClassForName​(java.lang.String name)
      walks the tree of TreeItems in order to find a class forName
      TreeItem findSubItem​(TreeItem parent, java.lang.String childName)  
      TreeItem findTreeItem​(java.lang.String[] nameParts)
      finds tree items by looking for name components only...
      void generateNames()
      Traverse the class tree, generating obfuscated names within each namespace.
      java.lang.String[] getAttrsToKeep()
      Return a list of attributes marked to keep.
      java.lang.String[] getAttrsToKeep​(java.lang.String className)
      Return a list of attributes marked to keep.
      Cl getCl​(java.lang.String fullName)
      Get class in tree from the fully qualified name, returning null if name not found.
      java.util.Enumeration getClEnum​(java.lang.String fullName)
      Get classes in tree from the fully qualified name (can be wildcarded).
      java.util.Enumeration getClEnum​(java.lang.String fullName, int classMode)
      Get classes in tree from the fully qualified name (can be wildcarded).
      Fd getFd​(java.lang.String fullName)
      Get field in tree from the fully qualified name.
      java.util.Enumeration getFdEnum​(java.lang.String fullName)
      Get fields in tree from the fully qualified, and possibly wildcarded, name.
      Md getMd​(java.lang.String fullName, java.lang.String descriptor)
      Get method in tree from the fully qualified name.
      java.util.Enumeration getMdEnum​(java.lang.String fullName, java.lang.String descriptor)
      Get methods in tree from the fully qualified, and possibly wildcarded, name.
      static java.util.Enumeration getNameEnum​(java.lang.String name)
      Return a fully qualified name broken into package/class segments.
      java.lang.String getOutName​(java.lang.String inName)
      Update the path of the passed filename, if that path corresponds to a package.
      Pk getPk​(java.lang.String fullName)
      Get package in tree from the fully qualified name, returning null if name not found.
      Pk getRoot()
      Return the root node.
      boolean isPedantic()
      Getter for property pedantic.
      boolean isReplaceClassNameStrings()
      Getter for property replaceClassNameStrings.
      java.lang.String mapAnnotationField​(java.lang.String className, java.lang.String methodName)
      Mapping for annotation field/method name, of fully qualified class.
      java.lang.String mapClass​(java.lang.String className)
      Mapping for fully qualified class name.
      java.lang.String mapDescriptor​(java.lang.String descriptor)
      Mapping for descriptor of field or method.
      java.lang.String mapField​(java.lang.String className, java.lang.String fieldName)
      Mapping for field name, of fully qualified class.
      boolean mapLineNumberTable​(java.lang.String className, java.lang.String methodName, java.lang.String methodSignature, LineNumberTableAttrInfo info)
      Mapping for the line number table.
      java.lang.String mapLocalVariable​(java.lang.String thisClassName, java.lang.String methodName, java.lang.String descriptor, java.lang.String string)
      Map local variable string.
      java.lang.String mapMethod​(java.lang.String className, java.lang.String methodName, java.lang.String descriptor)
      Mapping for method name, of fully qualified class.
      java.lang.String mapPackage​(java.lang.String packageName)
      Mapping for package names.
      java.lang.String mapSignature​(java.lang.String signature)
      Mapping for signatures (used for generics in 1.5).
      java.lang.String mapSourceFile​(java.lang.String className, java.lang.String sourceFileName)
      Mapping for the source file attribute of a file.
      void resolveClasses()
      Resolve the polymorphic dependencies of each class.
      void retainAttribute​(java.lang.String name)
      Mark an attribute type for retention.
      void retainAttributeForClass​(java.lang.String className, java.lang.String attributeDescriptor)
      Retain attribute for class.
      void retainClass​(java.lang.String name, int classLevel, int methodLevel, int fieldLevel, boolean retainHierarchy)
      Mark a class/interface type (and possibly methods and fields defined in class) for retention.
      void retainClassMap​(java.lang.String name, java.lang.String obfName)
      Mark a class/interface type for retention, and specify its new name.
      void retainField​(java.lang.String name)
      Mark a field type for retention.
      void retainFieldMap​(java.lang.String name, java.lang.String obfName)
      Mark a field type for retention, and specify its new name.
      void retainLineNumberTable​(java.lang.String name, LineNumberTableMapper lineNumberTableMapper)
      Retain line number table.
      void retainMethod​(java.lang.String name, java.lang.String descriptor)
      Mark a method type for retention.
      void retainMethodMap​(java.lang.String name, java.lang.String descriptor, java.lang.String obfName)
      Mark a method type for retention, and specify its new name.
      void retainPackage​(java.lang.String packageName)
      Retain package.
      void retainPackageMap​(java.lang.String name, java.lang.String obfName)
      Mark a package for retention, and specify its new name.
      void retainSourceFileAttributeMap​(java.lang.String name, java.lang.String obfName)
      Retain source file attribute map.
      void setPedantic​(boolean pedantic)
      Setter for property pedantic.
      void setReplaceClassNameStrings​(boolean replaceClassNameStrings)
      Setter for property replaceClassNameStrings.
      static java.lang.String toUtf8XmlString​(java.lang.String s)
      To utf 8 xml string string.
      void walkTree​(TreeAction ta)
      Walk the whole tree taking action once only on each package level, class, method and field.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PACKAGE_LEVEL

        public static final char PACKAGE_LEVEL
        The constant PACKAGE_LEVEL.
        See Also:
        Constant Field Values
      • CLASS_LEVEL

        public static final char CLASS_LEVEL
        The constant CLASS_LEVEL.
        See Also:
        Constant Field Values
      • METHOD_FIELD_LEVEL

        public static final char METHOD_FIELD_LEVEL
        The constant METHOD_FIELD_LEVEL.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ClassTree

        public ClassTree()
        Ctor.
    • Method Detail

      • getNameEnum

        public static java.util.Enumeration getNameEnum​(java.lang.String name)
        Return a fully qualified name broken into package/class segments.
        Parameters:
        name - the name
        Returns:
        the name enum
      • getRoot

        public Pk getRoot()
        Return the root node.
        Returns:
        the root
      • findTreeItem

        public TreeItem findTreeItem​(java.lang.String[] nameParts)
        finds tree items by looking for name components only...
        Parameters:
        nameParts - the name parts
        Returns:
        the tree item
      • findClassForName

        public Cl findClassForName​(java.lang.String name)
        walks the tree of TreeItems in order to find a class forName
        Parameters:
        name - the name
        Returns:
        the cl
      • findSubItem

        public TreeItem findSubItem​(TreeItem parent,
                                    java.lang.String childName)
      • getOutName

        public java.lang.String getOutName​(java.lang.String inName)
        Update the path of the passed filename, if that path corresponds to a package.
        Parameters:
        inName - the in name
        Returns:
        the out name
      • addClassFile

        public void addClassFile​(ClassFile cf)
        Add a classfile's package, class, method and field entries to database.
        Parameters:
        cf - the cf
      • retainAttribute

        public void retainAttribute​(java.lang.String name)
        Mark an attribute type for retention.
        Parameters:
        name - the name
      • retainClass

        public void retainClass​(java.lang.String name,
                                int classLevel,
                                int methodLevel,
                                int fieldLevel,
                                boolean retainHierarchy)
        Mark a class/interface type (and possibly methods and fields defined in class) for retention.
        Parameters:
        name - the name
        classLevel - the class level
        methodLevel - the method level
        fieldLevel - the field level
        retainHierarchy - the retain hierarchy
      • retainMethod

        public void retainMethod​(java.lang.String name,
                                 java.lang.String descriptor)
        Mark a method type for retention.
        Parameters:
        name - the name
        descriptor - the descriptor
      • retainField

        public void retainField​(java.lang.String name)
        Mark a field type for retention.
        Parameters:
        name - the name
      • retainPackageMap

        public void retainPackageMap​(java.lang.String name,
                                     java.lang.String obfName)
        Mark a package for retention, and specify its new name.
        Parameters:
        name - the name
        obfName - the obf name
      • retainClassMap

        public void retainClassMap​(java.lang.String name,
                                   java.lang.String obfName)
        Mark a class/interface type for retention, and specify its new name.
        Parameters:
        name - the name
        obfName - the obf name
      • retainMethodMap

        public void retainMethodMap​(java.lang.String name,
                                    java.lang.String descriptor,
                                    java.lang.String obfName)
        Mark a method type for retention, and specify its new name.
        Parameters:
        name - the name
        descriptor - the descriptor
        obfName - the obf name
      • retainFieldMap

        public void retainFieldMap​(java.lang.String name,
                                   java.lang.String obfName)
        Mark a field type for retention, and specify its new name.
        Parameters:
        name - the name
        obfName - the obf name
      • generateNames

        public void generateNames()
        Traverse the class tree, generating obfuscated names within each namespace.
      • resolveClasses

        public void resolveClasses()
                            throws java.lang.ClassNotFoundException
        Resolve the polymorphic dependencies of each class. @throws ClassNotFoundException the class not found exception
        Throws:
        java.lang.ClassNotFoundException - the class not found exception
      • getAttrsToKeep

        public java.lang.String[] getAttrsToKeep()
        Return a list of attributes marked to keep.
        Returns:
        the string [ ]
      • getClEnum

        public java.util.Enumeration getClEnum​(java.lang.String fullName)
        Get classes in tree from the fully qualified name (can be wildcarded).
        Parameters:
        fullName - the full name
        Returns:
        the cl enum
      • getClEnum

        public java.util.Enumeration getClEnum​(java.lang.String fullName,
                                               int classMode)
        Get classes in tree from the fully qualified name (can be wildcarded).
        Parameters:
        fullName - the full name
        classMode - the class mode
        Returns:
        the cl enum
      • getMdEnum

        public java.util.Enumeration getMdEnum​(java.lang.String fullName,
                                               java.lang.String descriptor)
        Get methods in tree from the fully qualified, and possibly wildcarded, name.
        Parameters:
        fullName - the full name
        descriptor - the descriptor
        Returns:
        the md enum
      • getFdEnum

        public java.util.Enumeration getFdEnum​(java.lang.String fullName)
        Get fields in tree from the fully qualified, and possibly wildcarded, name.
        Parameters:
        fullName - the full name
        Returns:
        the fd enum
      • getCl

        public Cl getCl​(java.lang.String fullName)
        Get class in tree from the fully qualified name, returning null if name not found.
        Parameters:
        fullName - the full name
        Returns:
        the cl
      • getPk

        public Pk getPk​(java.lang.String fullName)
        Get package in tree from the fully qualified name, returning null if name not found.
        Parameters:
        fullName - the full name
        Returns:
        the pk
      • getMd

        public Md getMd​(java.lang.String fullName,
                        java.lang.String descriptor)
        Get method in tree from the fully qualified name.
        Parameters:
        fullName - the full name
        descriptor - the descriptor
        Returns:
        the md
      • getFd

        public Fd getFd​(java.lang.String fullName)
        Get field in tree from the fully qualified name.
        Parameters:
        fullName - the full name
        Returns:
        the fd
      • getAttrsToKeep

        public java.lang.String[] getAttrsToKeep​(java.lang.String className)
        Description copied from interface: NameMapper
        Return a list of attributes marked to keep.
        Specified by:
        getAttrsToKeep in interface NameMapper
        Parameters:
        className - the class name
        Returns:
        the string [ ]
      • mapLocalVariable

        public java.lang.String mapLocalVariable​(java.lang.String thisClassName,
                                                 java.lang.String methodName,
                                                 java.lang.String descriptor,
                                                 java.lang.String string)
        Description copied from interface: NameMapper
        Map local variable string.
        Specified by:
        mapLocalVariable in interface NameMapper
        Parameters:
        thisClassName - the this class name
        methodName - the method name
        descriptor - the descriptor
        string - the string
        Returns:
        the string
      • mapSourceFile

        public java.lang.String mapSourceFile​(java.lang.String className,
                                              java.lang.String sourceFileName)
        Description copied from interface: NameMapper
        Mapping for the source file attribute of a file.
        Specified by:
        mapSourceFile in interface NameMapper
        Parameters:
        className - the class name
        sourceFileName - the source file
        Returns:
        the string
      • mapLineNumberTable

        public boolean mapLineNumberTable​(java.lang.String className,
                                          java.lang.String methodName,
                                          java.lang.String methodSignature,
                                          LineNumberTableAttrInfo info)
        Description copied from interface: NameMapper
        Mapping for the line number table.
        Specified by:
        mapLineNumberTable in interface NameMapper
        Parameters:
        className - the class name
        methodName - the method name
        methodSignature - the method signature
        info - the info
        Returns:
        false if the line number table may be discarded
      • mapPackage

        public java.lang.String mapPackage​(java.lang.String packageName)
        Mapping for package names.
        Specified by:
        mapPackage in interface NameMapper
        Parameters:
        packageName - the package name
        Returns:
        the string
        See Also:
        NameMapper.mapPackage(String)
      • dump

        public void dump​(java.io.PrintWriter log)
        Dump the content of the class tree to the specified file (used for logging).
        Parameters:
        log - the log
      • toUtf8XmlString

        public static final java.lang.String toUtf8XmlString​(java.lang.String s)
        To utf 8 xml string string.
        Parameters:
        s - the s
        Returns:
        the string
      • walkTree

        public void walkTree​(TreeAction ta)
        Walk the whole tree taking action once only on each package level, class, method and field.
        Parameters:
        ta - the ta
      • isReplaceClassNameStrings

        public boolean isReplaceClassNameStrings()
        Getter for property replaceClassNameStrings.
        Returns:
        Value of property replaceClassNameStrings.
      • setReplaceClassNameStrings

        public void setReplaceClassNameStrings​(boolean replaceClassNameStrings)
        Setter for property replaceClassNameStrings.
        Parameters:
        replaceClassNameStrings - New value of property replaceClassNameStrings.
      • isPedantic

        public boolean isPedantic()
        Getter for property pedantic.
        Returns:
        Value of property pedantic.
      • setPedantic

        public void setPedantic​(boolean pedantic)
        Setter for property pedantic.
        Parameters:
        pedantic - New value of property pedantic.
      • retainSourceFileAttributeMap

        public void retainSourceFileAttributeMap​(java.lang.String name,
                                                 java.lang.String obfName)
        Retain source file attribute map.
        Parameters:
        name - the name
        obfName - the obf name
      • retainLineNumberTable

        public void retainLineNumberTable​(java.lang.String name,
                                          LineNumberTableMapper lineNumberTableMapper)
        Retain line number table.
        Parameters:
        name - the name
        lineNumberTableMapper - the line number table mapper
      • retainAttributeForClass

        public void retainAttributeForClass​(java.lang.String className,
                                            java.lang.String attributeDescriptor)
        Retain attribute for class.
        Parameters:
        className - the class name
        attributeDescriptor - the attribute descriptor
      • retainPackage

        public void retainPackage​(java.lang.String packageName)
        Retain package.
        Parameters:
        packageName - the package name