@Beta public abstract class AbstractNamingStrategy extends Object implements NamingStrategy
NamingStrategy
. It provides convenience methods (such as
convertToJavaClassName(String, String)
) for inheritors to leverage.Constructor and Description |
---|
AbstractNamingStrategy() |
AbstractNamingStrategy(NameSource nameSource) |
Modifier and Type | Method and Description |
---|---|
protected String |
appendSuffixIfNameIsReservedKeyword(String name,
String suffix)
Appends the given
suffix to the given name , if the name is a reserved keyword. |
protected String |
chooseBetweenNameAndLabel(String name,
String label)
|
protected String |
convertToJavaClassName(String name,
String label)
|
protected String |
convertToJavaConstantName(String name,
String label)
|
protected String |
convertToJavaFieldName(String name,
String label)
|
protected String |
convertToJavaMethodName(String name,
String label)
|
protected String |
finishJavaBuilderMethodNameGeneration(String methodName)
Allows post-processing of the Java identifier generated by
generateJavaBuilderMethodName(String) . |
protected String |
finishJavaClassNameGeneration(String className)
Allows post-processing of the Java identifier generated by
generateJavaClassName(String, String) . |
protected String |
finishJavaConstantNameGeneration(String constantName)
Allows post-processing of the Java identifier generated by
generateJavaConstantName(String, String) . |
protected String |
finishJavaFieldNameGeneration(String fieldName)
Allows post-processing of the Java identifier generated by
generateJavaFieldName(String, String) . |
protected String |
finishJavaFluentHelperClassNameGeneration(String className)
Allows post-processing of the Java identifier generated by
generateJavaFluentHelperClassName(String, String) . |
protected String |
finishJavaMethodNameGeneration(String methodName)
Allows post-processing of the Java identifier generated by
generateJavaMethodName(String) . |
protected String |
finishJavaMethodParameterNameGeneration(String parameterName)
Allows post-processing of the Java identifier generated by
generateJavaMethodParameterName(String, String) . |
protected String |
finishJavaNavigationPropertyConstantNameGeneration(String constantName)
Allows post-processing of the Java identifier generated by
generateJavaNavigationPropertyConstantName(String) . |
protected String |
finishJavaNavigationPropertyFieldNameGeneration(String fieldName)
Allows post-processing of the Java identifier generated by
generateJavaNavigationPropertyFieldName(String) . |
protected String |
finishJavaOperationMethodNameGeneration(String methodName)
Allows post-processing of the Java identifier generated by
generateJavaOperationMethodName(String, String) . |
protected String |
fixAcronymsInConstantNames(String name)
Removes underscores (
"_" ) from in between the letters on acronyms from the given name . |
String |
generateJavaBuilderMethodName(String name)
Called by the VDM generator to convert the name and the label of an OData navigation property into a Lombok
builder method name.
|
String |
generateJavaClassName(String name,
String label)
Called by the VDM generator to convert the name and the label of an OData entity type into a suitable Java class
name.
|
String |
generateJavaConstantName(String name,
String label)
Called by the VDM generator to convert the property name and the label of an OData entity type into a suitable
Java constant (
public static final ) name. |
String |
generateJavaFieldName(String name,
String label)
Called by the VDM generator to convert the name and the label of a property within an OData entity type into a
suitable Java member variable name.
|
String |
generateJavaFluentHelperClassName(String name,
String label)
Called by the VDM generator to convert the name and the label of an OData operation (e.g.
|
String |
generateJavaMethodName(String name)
Called by the VDM generator to convert the name and the label of an OData navigation property into a partial Java
method name.
|
String |
generateJavaMethodParameterName(String name,
String label)
Called by the VDM generator to convert the name and the label of an OData operation (e.g.
|
String |
generateJavaNavigationPropertyConstantName(String name)
Called by the VDM generator to convert the name and the label of an OData navigation property into a suitable
Java constant (
public static final ) name. |
String |
generateJavaNavigationPropertyFieldName(String name)
Called by the VDM generator to convert the name and the label of an OData navigation property into a suitable
Java member variable name.
|
String |
generateJavaOperationMethodName(String name,
String label)
Called by the VDM generator to convert the name and the label of an OData operation (e.g.
|
NameSource |
getNameSource()
Returns the
NameSource used by this NamingStrategy . |
boolean |
isReservedKeyword(String name)
Determines whether the
proposedName is a language reserved keyword. |
protected String |
removeInvalidJavaCharacters(CharSequence name)
Removes all characters that are not valid Java syntax from the given
name . |
protected String |
removeRepeatedUnderscores(String name)
Removes repeated underscores (
"_" ) from the given name . |
protected String |
removeWhiteSpaces(String name)
Removes all white spaces from the given
name . |
void |
setNameSource(NameSource nameSource)
Sets the
NameSource that should be used by this NamingStrategy . |
protected void |
throwIfConversionResultIsNullOrEmpty(String conversionInputName,
String conversionInputLabel,
CharSequence conversionOutput,
String conversionTarget)
|
protected void |
throwIfConversionResultIsReservedKeyword(String conversionInputName,
String conversionInputLabel,
String conversionOutput,
String conversionTarget)
Throws an
IllegalStateException if the given conversionOutput is a reserved keyword. |
protected String |
uncapitalizeLeadingAcronym(String name)
Converts a leading acronym into lower case format.
|
public AbstractNamingStrategy(NameSource nameSource)
public AbstractNamingStrategy()
public boolean isReservedKeyword(@Nonnull String name)
NamingStrategy
proposedName
is a language reserved keyword.isReservedKeyword
in interface NamingStrategy
name
- String to checktrue
if proposedName
is a reserved keyword, false
otherwise.@Nonnull public String generateJavaClassName(@Nonnull String name, @Nullable String label)
NamingStrategy
...FluentHelper
and ...ByKeyFluentHelper
)...CreateFluentHelper
, ...UpdateFluentHelper
,
...DeleteFluentHelper
)generateJavaClassName
in interface NamingStrategy
name
- Provided by the VDM generator. It reads the Name attribute value of an EntityType tag in
the metadata file.label
- Provided by the VDM generator. I reads the sap:label attribute of an EntityType tag in
the metadata file.@Nonnull protected String finishJavaClassNameGeneration(@Nonnull String className)
generateJavaClassName(String, String)
.className
- The Java class name to post-process.@Nonnull public String generateJavaFieldName(@Nonnull String name, @Nullable String label)
NamingStrategy
generateJavaFieldName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a
Property tag, which is within an EntityType tag.label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of
a Property tag, which is within an EntityType tag.@Nonnull protected String finishJavaFieldNameGeneration(@Nonnull String fieldName)
generateJavaFieldName(String, String)
.fieldName
- The Java field name to post-process.@Nonnull public String generateJavaConstantName(@Nonnull String name, @Nullable String label)
NamingStrategy
public static final
) name. These constants are the fluent helper fields and they end up in
the newly generated VDM entity classes.generateJavaConstantName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a
Property tag, which is within an EntityType tag.label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of
a Property tag, which is within an EntityType tag.@Nonnull protected String finishJavaConstantNameGeneration(@Nonnull String constantName)
generateJavaConstantName(String, String)
.constantName
- The Java constant name to post-process.@Nonnull public String generateJavaNavigationPropertyFieldName(@Nonnull String name)
NamingStrategy
generateJavaNavigationPropertyFieldName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a
NavigationProperty tag, which is within an EntityType tag.@Nonnull protected String finishJavaNavigationPropertyFieldNameGeneration(@Nonnull String fieldName)
generateJavaNavigationPropertyFieldName(String)
.fieldName
- The Java field name to post-process.@Nonnull public String generateJavaNavigationPropertyConstantName(@Nonnull String name)
NamingStrategy
public static final
) name. These constants are the fluent helper fields and they end up in
the newly generated VDM entity classes.generateJavaNavigationPropertyConstantName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a
NavigationProperty tag, which is within an EntityType tag.@Nonnull protected String finishJavaNavigationPropertyConstantNameGeneration(@Nonnull String constantName)
generateJavaNavigationPropertyConstantName(String)
.constantName
- The Java constant name to post-process.@Nonnull public String generateJavaMethodName(@Nonnull String name)
NamingStrategy
fetch...()
, get...OrNull()
, get...OrFetch()
set...()
, add...()
generateJavaMethodName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a
NavigationProperty tag, which is within an EntityType tag.@Nonnull protected String finishJavaMethodNameGeneration(@Nonnull String methodName)
generateJavaMethodName(String)
.methodName
- The Java method name to post-process.@Nonnull public String generateJavaBuilderMethodName(@Nonnull String name)
NamingStrategy
generateJavaBuilderMethodName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a
NavigationProperty tag, which is within an EntityType tag.@Nonnull protected String finishJavaBuilderMethodNameGeneration(@Nonnull String methodName)
generateJavaBuilderMethodName(String)
.methodName
- The Java method name to post-process.@Nonnull public String generateJavaOperationMethodName(@Nonnull String name, @Nullable String label)
NamingStrategy
generateJavaOperationMethodName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of an
operation (e.g. FunctionImport inside the EntityContainer tag).label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of
an operation (e.g. FunctionImport inside the EntityContainer tag).@Nonnull protected String finishJavaOperationMethodNameGeneration(@Nonnull String methodName)
generateJavaOperationMethodName(String, String)
.methodName
- The Java method name to post-process.@Nonnull public String generateJavaMethodParameterName(@Nonnull String name, @Nullable String label)
NamingStrategy
generateJavaMethodParameterName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of a
Parameter tag, which is within the operation tag (e.g. FunctionImport inside the
EntityContainer tag).label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of
a Parameter tag, which is within the operation tag (e.g. FunctionImport inside the
EntityContainer tag).@Nonnull protected String finishJavaMethodParameterNameGeneration(@Nonnull String parameterName)
generateJavaMethodParameterName(String, String)
.parameterName
- The Java method parameter name to post-process.@Nonnull public String generateJavaFluentHelperClassName(@Nonnull String name, @Nullable String label)
NamingStrategy
generateJavaFluentHelperClassName
in interface NamingStrategy
name
- Provided by the VDM generator. In the metadata file, it reads the Name attribute value of an
operation (e.g. FunctionImport inside the EntityContainer tag).label
- Provided by the VDM generator. In the metadata file, it reads the sap:label attribute value of
an operation (e.g. FunctionImport inside the EntityContainer tag).@Nonnull protected String finishJavaFluentHelperClassNameGeneration(@Nonnull String className)
generateJavaFluentHelperClassName(String, String)
.className
- The Java class name to post-process.@Nonnull protected String convertToJavaClassName(@Nonnull String name, @Nullable String label)
name
and label
based on the used NameSource
. The chosen string
will then be converted into a syntactically valid Java class name.name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.@Nonnull protected String convertToJavaFieldName(@Nonnull String name, @Nullable String label)
name
and label
based on the used NameSource
. The chosen string
will then be converted into a syntactically valid Java field name.name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.@Nonnull protected String convertToJavaConstantName(@Nonnull String name, @Nullable String label)
name
and label
based on the used NameSource
. The chosen string
will then be converted into a syntactically valid Java constant name.name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.@Nonnull protected String convertToJavaMethodName(@Nonnull String name, @Nullable String label)
name
and label
based on the used NameSource
. The chosen string
will then be converted into a syntactically valid Java method name.name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.@Nonnull protected String chooseBetweenNameAndLabel(@Nonnull String name, @Nullable String label)
name
- The name property of an OData tag (e.g. of an Entity).label
- The sap:label property of an OData tag (e.g. of an Entity), if any.name
or the label
.@Nonnull protected final String removeWhiteSpaces(@Nonnull String name)
name
.name
- The name to modify.name
.@Nonnull protected final String removeInvalidJavaCharacters(@Nonnull CharSequence name)
name
.name
- The name to modify.name
.@Nonnull protected final String uncapitalizeLeadingAcronym(@Nonnull String name)
Example:
uncapitalizeLeadingAcronym("URLAddress") -> "urlAddress"
name
- The name to modify.name
.@Nonnull protected final String removeRepeatedUnderscores(@Nonnull String name)
"_"
) from the given name
.name
- The name to modify.name
.@Nonnull protected final String fixAcronymsInConstantNames(@Nonnull String name)
"_"
) from in between the letters on acronyms from the given name
.
Example:
fixAcronymsInConstantNames("U_R_L_ADDRESS") -> "URL_ADDRESS"
name
- The name to modify.name
.@Nonnull protected final String appendSuffixIfNameIsReservedKeyword(@Nonnull String name, @Nonnull String suffix)
suffix
to the given name
, if the name
is a reserved keyword.name
- The name to modify.suffix
- The suffix to append, in case the name
is a reserved keyword.name
.protected final void throwIfConversionResultIsNullOrEmpty(@Nonnull String conversionInputName, @Nullable String conversionInputLabel, @Nullable CharSequence conversionOutput, @Nonnull String conversionTarget)
conversionInputName
- The original input name, taken for example from the name tag of an OData Entity, which was used
for the conversion.conversionInputLabel
- The original input label, taken for example from the sap:label tag of an OData Entity,
which was used for the conversion.conversionOutput
- The output of the conversion.conversionTarget
- The target type of the conversion. Example: "Java class name"
.protected final void throwIfConversionResultIsReservedKeyword(@Nonnull String conversionInputName, @Nullable String conversionInputLabel, @Nonnull String conversionOutput, @Nonnull String conversionTarget)
IllegalStateException
if the given conversionOutput
is a reserved keyword.conversionInputName
- The original input name, taken for example from the name tag of an OData Entity, which was used
for the conversion.conversionInputLabel
- The original input label, taken for example from the sap:label tag of an OData Entity,
which was used for the conversion.conversionOutput
- The output of the conversion.conversionTarget
- The target type of the conversion. Example: "Java class name"
.public NameSource getNameSource()
NamingStrategy
NameSource
used by this NamingStrategy
.getNameSource
in interface NamingStrategy
NameSource
.public void setNameSource(NameSource nameSource)
NamingStrategy
NameSource
that should be used by this NamingStrategy
.setNameSource
in interface NamingStrategy
nameSource
- The NameSource
to use.Copyright © 2021 SAP SE. All rights reserved.