Class VariableRenamer


  • class VariableRenamer
    extends Object
    • Field Detail

      • sequence

        public final Sequence sequence
        The sequence in which every variable will be renamed.
      • VAR_NAME_MAX_DEPTH

        private static final int VAR_NAME_MAX_DEPTH
        Maximum depth to concatenate parameterized type names.
        See Also:
        Constant Field Values
    • Constructor Detail

      • VariableRenamer

        public VariableRenamer​(Sequence sequence)
    • Method Detail

      • getVariableName

        static String getVariableName​(Type type)
        Heuristically transforms variables to better names based on its type name. Here are some examples:
        
         int var0 = 1 becomes  int int0 = 1
         ClassName var0 = new ClassName() becomes ClassName className = new ClassName()
         Class var0 = null becomes Class cls = null
         Queue<Set<List<Comparable<String>>>> var0 = null becomes Queue<Set<List<Comparable<String>>>> listSetQueue = null
         ArrayList<String> var0 = null becomes ArrayList<String> strList = null
         
        Parameters:
        type - the type to use as base of variable name
        Returns:
        a variable name based on its type, with the first character lowercase and the final character not a digit
      • getVariableName

        private static String getVariableName​(Type type,
                                              int depth)
        Heuristically renames each variable to a name that is based on the variable's type.
        Parameters:
        type - the type to use as the base of the variable name
        depth - the number of components (i.e. type arguments) of the type that will be used to create a name for the variable
        Returns:
        a variable name based on its type and is camel cased. The first character may be uppercase.
      • capitalizeString

        private static String capitalizeString​(String variableName)
        Capitalize the variable name while preserving any capitalized letters after the first letter.
        Parameters:
        variableName - the name of the variable
        Returns:
        capitalized form of variable name
      • lowercaseFirstCharacter

        private static String lowercaseFirstCharacter​(String variableName)
        Lowercase the first character in the variable name while preserving any capitalized letters after the first letter.
        Parameters:
        variableName - the name of the variable
        Returns:
        variableName with the first letter lowercased