Class NameUtils

java.lang.Object
org.jibx.schema.codegen.NameUtils

public class NameUtils extends Object
Support methods for working with Java names.
Author:
Dennis M. Sosnoski
  • Field Details

    • s_reservedWords

      private static final HashSet s_reservedWords
      Reserved words for Java (keywords and literals).
    • s_defaultImportClassNames

      private static final HashSet s_defaultImportClassNames
      Java default import class names (not exhaustive, but anything that might represent generated code conflict).
  • Constructor Details

    • NameUtils

      public NameUtils()
  • Method Details

    • isReserved

      public static boolean isReserved(String name)
      Check if a name is reserved in Java.
      Parameters:
      name -
      Returns:
      is reserved
    • convertReserved

      public static String convertReserved(String name)
      Convert name if it is reserved in Java.
      Parameters:
      name -
      Returns:
      non-reserved name
    • isDefaultImport

      public static boolean isDefaultImport(String name)
      Check if a class name is a default import in Java.
      Parameters:
      name -
      Returns:
      is reserved
    • sanitizePackageName

      public static String sanitizePackageName(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 String toNameWord(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 String toNameLead(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