Class DefaultNameGenerator

java.lang.Object
com.google.javascript.jscomp.DefaultNameGenerator
All Implemented Interfaces:
NameGenerator, Serializable

public final class DefaultNameGenerator extends Object implements NameGenerator
A simple class for generating unique JavaScript variable/property names.

This class is not thread safe.

See Also:
  • Constructor Details

    • DefaultNameGenerator

      public DefaultNameGenerator()
    • DefaultNameGenerator

      public DefaultNameGenerator(Set<String> reservedNames, String prefix, char @Nullable [] reservedCharacters)
    • DefaultNameGenerator

      public DefaultNameGenerator(Set<String> reservedNames, String prefix, char @Nullable [] reservedFirstCharacters, char @Nullable [] reservedNonFirstCharacters)
      Creates a DefaultNameGenerator.
      Parameters:
      reservedNames - set of names that are reserved; generated names will not include these names. This set is referenced rather than copied, so changes to the set will be reflected in how names are generated.
      prefix - all generated names begin with this prefix.
      reservedFirstCharacters - If specified these characters won't be used in generated names for the first character
      reservedNonFirstCharacters - If specified these characters won't be used in generated names for characters after the first
  • Method Details

    • reset

      public void reset(Set<String> reservedNames, String prefix, char @Nullable [] reservedCharacters)
      Description copied from interface: NameGenerator
      Reconfigures this NameGenerator, and resets it to the initial state.
      Specified by:
      reset in interface NameGenerator
      Parameters:
      reservedNames - set of names that are reserved; generated names will not include these names. This set is referenced rather than copied, so changes to the set will be reflected in how names are generated.
      prefix - all generated names begin with this prefix.
      reservedCharacters - If specified these characters won't be used in generated names
    • reset

      public void reset(Set<String> reservedNames, String prefix, char @Nullable [] reservedFirstCharacters, char @Nullable [] reservedNonFirstCharacters)
      Note that the history of what characters are most used in the program (set through calls to 'favor') is not deleted. Upon 'reset', that history is taken into account for the names that will be generated later: it re-calculates how characters are prioritized based on how often the they appear in the final output.
      Specified by:
      reset in interface NameGenerator
      Parameters:
      reservedNames - set of names that are reserved; generated names will not include these names. This set is referenced rather than copied, so changes to the set will be reflected in how names are generated.
      prefix - all generated names begin with this prefix.
      reservedFirstCharacters - If specified these characters won't be used as the first character in generated names
      reservedNonFirstCharacters - If specified these characters won't be used for characters (after the first) in generated names
    • clone

      public NameGenerator clone(Set<String> reservedNames, String prefix, char @Nullable [] reservedCharacters)
      Description copied from interface: NameGenerator
      Returns a clone of this NameGenerator, reconfigured and reset.
      Specified by:
      clone in interface NameGenerator
    • generateNextName

      public String generateNextName()
      Generates the next short name.
      Specified by:
      generateNextName in interface NameGenerator