Package org.jibx.schema.codegen
Class NameUtils
- java.lang.Object
-
- org.jibx.schema.codegen.NameUtils
-
public class NameUtils extends java.lang.Object
Support methods for working with Java names.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.HashSet
s_defaultImportClassNames
Java default import class names (not exhaustive, but anything that might represent generated code conflict).private static java.util.HashSet
s_reservedWords
Reserved words for Java (keywords and literals).
-
Constructor Summary
Constructors Constructor Description NameUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
convertReserved(java.lang.String name)
Convert name if it is reserved in Java.static boolean
isDefaultImport(java.lang.String name)
Check if a class name is a default import in Java.static boolean
isReserved(java.lang.String name)
Check if a name is reserved in Java.static java.lang.String
sanitizePackageName(java.lang.String raw)
Convert a raw package name to a legal Java package name.static java.lang.String
toNameLead(java.lang.String word)
Convert a word to a leading name component.static java.lang.String
toNameWord(java.lang.String word)
Convert a word to a name component.
-
-
-
Field Detail
-
s_reservedWords
private static final java.util.HashSet s_reservedWords
Reserved words for Java (keywords and literals).
-
s_defaultImportClassNames
private static final java.util.HashSet s_defaultImportClassNames
Java default import class names (not exhaustive, but anything that might represent generated code conflict).
-
-
Method Detail
-
isReserved
public static boolean isReserved(java.lang.String name)
Check if a name is reserved in Java.- Parameters:
name
-- Returns:
- is reserved
-
convertReserved
public static java.lang.String convertReserved(java.lang.String name)
Convert name if it is reserved in Java.- Parameters:
name
-- Returns:
- non-reserved name
-
isDefaultImport
public static boolean isDefaultImport(java.lang.String name)
Check if a class name is a default import in Java.- Parameters:
name
-- Returns:
- is reserved
-
sanitizePackageName
public static java.lang.String sanitizePackageName(java.lang.String raw)
Convert a raw package name to a legal Java package name. The raw package name must be in standard package name form, with periods separating the individual directory components of the package name.- Parameters:
raw
- basic package name, which may include illegal characters- Returns:
- sanitized package name
-
toNameWord
public static java.lang.String toNameWord(java.lang.String word)
Convert a word to a name component. This is intended for use when composing names, as when generating access method names for a property. If the supplied word starts with one or more underscores, this first strips the the underscores. If the resulting text starts with a lower case letter this then converts that character to upper case. Finally, if the result either begins with a digit or is the word "Class" this prepends a leading underscore back on.- Parameters:
word
-- Returns:
- word with uppercase initial letter
-
toNameLead
public static java.lang.String toNameLead(java.lang.String word)
Convert a word to a leading name component. If the supplied word starts with an uppercase letter which is not followed by another uppercase letter, this converts the initial uppercase to lowercase.- Parameters:
word
-- Returns:
- word with lowercase initial letter
-
-