Package com.tonic.analysis.source.emit
Class IdentifierNormalizer
- java.lang.Object
-
- com.tonic.analysis.source.emit.IdentifierNormalizer
-
public class IdentifierNormalizer extends Object
Rewriter of identifiers per the configured mode: raw, unicode-escaped, or semantically renamed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIdentifierNormalizer.IdentifierTypeIdentifier kinds, each with its own semantic-rename prefix and counter.
-
Constructor Summary
Constructors Constructor Description IdentifierNormalizer(IdentifierMode mode)Creates a normalizer applying the given mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringescapeToUnicode(String s)Escapes characters not valid in Java identifiers to unicode escape sequences.booleanisValidJavaIdentifier(String s)Stringnormalize(String identifier, IdentifierNormalizer.IdentifierType type)Normalizes an identifier according to the configured mode.StringnormalizeClassName(String internalName)Normalizes a class name in internal (slashed) or source (dotted) form.voidreset()Resets all counters and rename caches for a fresh per-class run.
-
-
-
Constructor Detail
-
IdentifierNormalizer
public IdentifierNormalizer(IdentifierMode mode)
Creates a normalizer applying the given mode.- Parameters:
mode- the normalization strategy
-
-
Method Detail
-
normalize
public String normalize(String identifier, IdentifierNormalizer.IdentifierType type)
Normalizes an identifier according to the configured mode.- Parameters:
identifier- the identifier to normalize; null or empty is returned unchangedtype- the identifier kind, selecting the semantic-rename prefix- Returns:
- the normalized identifier
-
normalizeClassName
public String normalizeClassName(String internalName)
Normalizes a class name in internal (slashed) or source (dotted) form.- Parameters:
internalName- the class name; null or empty is returned unchanged- Returns:
- the normalized name with separators preserved
-
escapeToUnicode
public String escapeToUnicode(String s)
Escapes characters not valid in Java identifiers to unicode escape sequences.- Parameters:
s- the string to escape, may be null- Returns:
- the escaped string, or null if s is null
-
isValidJavaIdentifier
public boolean isValidJavaIdentifier(String s)
- Parameters:
s- the string to test- Returns:
- true if s is a well-formed Java identifier and not a keyword
-
reset
public void reset()
Resets all counters and rename caches for a fresh per-class run.
-
-