Module uk.autores

Class Namer

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"); // "foo.bar"
          String className = namer.nameClass(simple);                              // "bar_baz"
      
  • Constructor Details

    • Namer

      public Namer()
      Public no-args constructor as per contract.
  • Method Details

    • 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
    • simplifyResourceName

      public String simplifyResourceName(String resource)
      Reduces a resource name to a simpler form.
      Parameters:
      resource - resource name
      Returns:
      name stripped of path and extension