Package org.immutables.generator
Class Naming
- java.lang.Object
-
- org.immutables.generator.Naming
-
- All Implemented Interfaces:
com.google.common.base.Function<java.lang.String,java.lang.String>,java.util.function.Function<java.lang.String,java.lang.String>
- Direct Known Subclasses:
Naming.ConstantNaming,Naming.JavaBeanNaming,Naming.PrefixSuffixNaming
public abstract class Naming extends java.lang.Object implements com.google.common.base.Function<java.lang.String,java.lang.String>Converter-like function to apply or extract naming, derived from input.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classNaming.ConstantNamingprivate static classNaming.JavaBeanNamingstatic classNaming.Preferenceprivate static classNaming.PrefixSuffixNamingstatic classNaming.Usage
-
Field Summary
Fields Modifier and Type Field Description private static NamingIDENTITY_NAMINGprivate static java.lang.StringNAME_PLACEHOLDERprivate static java.lang.StringNOT_DETECTEDprivate static com.google.common.base.CharMatcherTEMPLATE_CHAR_MATCHERprivate static com.google.common.base.SplitterTEMPLATE_SPLITTER
-
Constructor Summary
Constructors Modifier Constructor Description privateNaming()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.Stringapply(java.lang.String input)Applies naming to input identifier, converting it to desired naming.abstract java.lang.Stringdetect(java.lang.String identifier)Tries to extract source identifier name out of already applied naming.static Namingfrom(java.lang.String template)static Naming[]fromAll(java.lang.String... templates)static Namingidentity()Naming the repeats the input nameabstract booleanisConstant()Checks if is constant naming.abstract booleanisIdentity()Checks if it's identity naming.abstract NamingrequireJavaBeanConvention()Require naming to follow JavaBeam capitalization convention.abstract NamingrequireNonConstant(Naming.Preference preference)Returns non-contant naming which is this.
-
-
-
Field Detail
-
NOT_DETECTED
private static final java.lang.String NOT_DETECTED
- See Also:
- Constant Field Values
-
NAME_PLACEHOLDER
private static final java.lang.String NAME_PLACEHOLDER
- See Also:
- Constant Field Values
-
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
-
-
Method Detail
-
apply
public abstract java.lang.String apply(java.lang.String input)
Applies naming to input identifier, converting it to desired naming.- Specified by:
applyin interfacecom.google.common.base.Function<java.lang.String,java.lang.String>- Specified by:
applyin interfacejava.util.function.Function<java.lang.String,java.lang.String>- Parameters:
input- the input identifier- Returns:
- applied naming
-
detect
public abstract java.lang.String detect(java.lang.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:
identity()
-
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
thisif 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:
- javabean spec
-
identity
public static Naming identity()
Naming the repeats the input name- Returns:
- identity naming
-
from
public static Naming from(java.lang.String template)
- Parameters:
template- template string- Returns:
- naming that could be applied or detected following template
-
fromAll
public static Naming[] fromAll(java.lang.String... templates)
-
-