- java.lang.Object
-
- uk.autores.naming.Namer
-
- Direct Known Subclasses:
IdiomaticNamer
public class Namer extends Object
Base type for naming classes, methods and fields. Does the bare minimum to create viable identifiers by replacing invalid codepoints with underscores. Extend this type to provide alternative behaviour and specify using
Processing.namer()
.Implementations MUST:
- Be public
- Have a public no-args constructor
- Be available as compiled types on the compiler classpath
Example of how this type is used in
Handler
implementations:Namer namer = new Namer(); String simple = namer.simplifyResourceName("/META-INF/foo/bar.baz.txt"); // "bar.baz" String className = namer.nameClass(simple); // "bar_baz"
-
-
Constructor Summary
Constructors Constructor Description Namer()
Public no-args constructor as per contract.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
isIdentifier(CharSequence cs)
Tests for valid identifiers - class, method or field names.static boolean
isPackage(CharSequence pkg)
Tests for valid package names.String
nameConstant(String src)
Name a public static final field.String
nameMember(String src)
Name a method/field/etc.String
nameType(String src)
Name a class/interface/etc.String
simplifyResourceName(String resource)
Reduces a resource name to a simpler form.
-
-
-
Method Detail
-
isIdentifier
public static boolean isIdentifier(CharSequence cs)
Tests for valid identifiers - class, method or field names.- Parameters:
cs
- sequence to test- Returns:
- true if valid identifier
-
isPackage
public static boolean isPackage(CharSequence pkg)
Tests for valid package names. Returns false for the empty string.- Parameters:
pkg
- package name- Returns:
- true if valid package name
-
nameType
public String nameType(String src)
Name a class/interface/etc.- Parameters:
src
- source string- Returns:
- source string as a class name
-
nameConstant
public String nameConstant(String src)
Name a public static final field.- Parameters:
src
- source string- Returns:
- source string as a field name if possible
-
nameMember
public String nameMember(String src)
Name a method/field/etc.- Parameters:
src
- source string- Returns:
- source string as a member name
-
-