Package com.google.javascript.jscomp
Class DefaultNameGenerator
- java.lang.Object
-
- com.google.javascript.jscomp.DefaultNameGenerator
-
- All Implemented Interfaces:
NameGenerator
,java.io.Serializable
public final class DefaultNameGenerator extends java.lang.Object implements NameGenerator
A simple class for generating unique JavaScript variable/property names.This class is not thread safe.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DefaultNameGenerator()
DefaultNameGenerator(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, char[] reservedCharacters)
DefaultNameGenerator(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, char[] reservedFirstCharacters, char[] reservedNonFirstCharacters)
Creates a DefaultNameGenerator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NameGenerator
clone(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, char[] reservedCharacters)
Returns a clone of this NameGenerator, reconfigured and reset.java.lang.String
generateNextName()
Generates the next short name.void
reset(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, char[] reservedCharacters)
Reconfigures this NameGenerator, and resets it to the initial state.void
reset(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, char[] reservedFirstCharacters, char[] reservedNonFirstCharacters)
Note that the history of what characters are most used in the program (set through calls to 'favor') is not deleted.
-
-
-
Constructor Detail
-
DefaultNameGenerator
public DefaultNameGenerator()
-
DefaultNameGenerator
public DefaultNameGenerator(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, @Nullable char[] reservedCharacters)
-
DefaultNameGenerator
public DefaultNameGenerator(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, @Nullable char[] reservedFirstCharacters, @Nullable char[] 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 Detail
-
reset
public void reset(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, @Nullable char[] reservedCharacters)
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(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, @Nullable char[] reservedFirstCharacters, @Nullable char[] 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(java.util.Set<java.lang.String> reservedNames, java.lang.String prefix, @Nullable char[] reservedCharacters)
Description copied from interface:NameGenerator
Returns a clone of this NameGenerator, reconfigured and reset.- Specified by:
clone
in interfaceNameGenerator
-
generateNextName
public java.lang.String generateNextName()
Generates the next short name.- Specified by:
generateNextName
in interfaceNameGenerator
-
-