Package com.google.javascript.jscomp
Class DefaultNameGenerator
java.lang.Object
com.google.javascript.jscomp.DefaultNameGenerator
- All Implemented Interfaces:
NameGenerator
,Serializable
A simple class for generating unique JavaScript variable/property names.
This class is not thread safe.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultNameGenerator
(Set<String> reservedNames, String prefix, char @Nullable [] reservedCharacters) DefaultNameGenerator
(Set<String> reservedNames, String prefix, char @Nullable [] reservedFirstCharacters, char @Nullable [] reservedNonFirstCharacters) Creates a DefaultNameGenerator. -
Method Summary
Modifier and TypeMethodDescriptionReturns a clone of this NameGenerator, reconfigured and reset.Generates the next short name.void
Reconfigures this NameGenerator, and resets it to the initial state.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.
-
Constructor Details
-
DefaultNameGenerator
public DefaultNameGenerator() -
DefaultNameGenerator
-
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 characterreservedNonFirstCharacters
- If specified these characters won't be used in generated names for characters after the first
-
-
Method Details
-
reset
Description copied from interface:NameGenerator
Reconfigures this NameGenerator, and resets it to the initial state.- Specified by:
reset
in interfaceNameGenerator
- 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 interfaceNameGenerator
- 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 namesreservedNonFirstCharacters
- 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 interfaceNameGenerator
-
generateNextName
Generates the next short name.- Specified by:
generateNextName
in interfaceNameGenerator
-