Class Naming

java.lang.Object
org.immutables.generator.Naming
All Implemented Interfaces:
com.google.common.base.Function<String,String>, Function<String,String>
Direct Known Subclasses:
Naming.ConstantNaming, Naming.JavaBeanNaming, Naming.PrefixSuffixNaming

public abstract class Naming extends Object implements com.google.common.base.Function<String,String>
Converter-like function to apply or extract naming, derived from input.
  • Field Details

    • NOT_DETECTED

      private static final String NOT_DETECTED
      See Also:
    • NAME_PLACEHOLDER

      private static final String NAME_PLACEHOLDER
      See Also:
    • TEMPLATE_SPLITTER

      private static final com.google.common.base.Splitter TEMPLATE_SPLITTER
    • TEMPLATE_CHAR_MATCHER

      private static final com.google.common.base.CharMatcher TEMPLATE_CHAR_MATCHER
    • IDENTITY_NAMING

      private static final Naming IDENTITY_NAMING
  • Constructor Details

    • Naming

      private Naming()
  • Method Details

    • apply

      public abstract String apply(String input)
      Applies naming to input identifier, converting it to desired naming.
      Specified by:
      apply in interface com.google.common.base.Function<String,String>
      Specified by:
      apply in interface Function<String,String>
      Parameters:
      input - the input identifier
      Returns:
      applied naming
    • detect

      public abstract String detect(String identifier)
      Tries to extract source identifier name out of already applied naming.
      Parameters:
      identifier - to detect naming from
      Returns:
      empty string if nothing detected
    • isIdentity

      public abstract boolean isIdentity()
      Checks if it's identity naming.
      Returns:
      true, if is identity naming
      See Also:
    • isConstant

      public abstract boolean isConstant()
      Checks if is constant naming. Verbatim naming convention do not use any supplied input name as base. Consider example factory method "from" constant naming, contrary to the factory method "newMyType" uses "MyType" as and input applying "new" prefix.
      Returns:
      true, if is constant
    • requireNonConstant

      public abstract Naming requireNonConstant(Naming.Preference preference)
      Returns non-contant naming which is this. Sometimes context require naming should be non-contant, otherwise names will clash in shared identifier scope. If this naming is constant, then it is turned into corresponding prefix naming.
      Parameters:
      preference - preference for prefix or suffix naming
      Returns:
      non-constant naming template or this if already non-constant
    • requireJavaBeanConvention

      public abstract Naming requireJavaBeanConvention()
      Require naming to follow JavaBeam capitalization convention.

      See 8.8 Capitalization of inferred names

       Thus when we extract a property or event name from the middle of an existing Java name, we
       normally convert the first character to lower case. However to support the occasional use of all
       upper-case names, we check if the first two characters of the name are both upper case and if
       so leave it alone. So for example, "FooBah" becomes "fooBah", "Z" becomes "z", "URL" becomes "URL"
       
      See Also:
    • identity

      public static Naming identity()
      Naming the repeats the input name
      Returns:
      identity naming
    • from

      public static Naming from(String template)
      Parameters:
      template - template string
      Returns:
      naming that could be applied or detected following template
    • fromAll

      public static Naming[] fromAll(String... templates)