Overview
TheNameGenerator class generates unique, sequential obfuscated identifiers in the format _$0, _$1, _$2, etc. It’s used by the RenamePass to create meaningless replacement names for classes, methods, and fields.
Source: lib/src/engine/name_generator.dart:2
Constructor
The prefix for generated names. Defaults to
_$.Methods
next()
The next sequential name, e.g.,
_$0, _$1, _$2, etc.reset()
Properties
currentCount
The current counter value (number of names generated since last reset)
Custom Prefixes
You can customize the prefix to match your obfuscation needs:The default prefix
_$ is chosen because:- Identifiers starting with underscore are private in Dart (library-scoped)
- The
$character is valid in identifiers but uncommon in user code - Together they create names unlikely to collide with existing code
Usage with PassContext
NameGenerator is typically accessed through PassContext:
See Also
RenamePass
Uses NameGenerator to create obfuscated identifiers
PassContext
Provides access to the shared NameGenerator instance
SymbolTable
Records mappings from original to generated names