Class ClassNameUtil


  • public final class ClassNameUtil
    extends Object
    Conversions between internal, source, simple and package class names.
    • Method Detail

      • getSimpleName

        public static String getSimpleName​(String internalName)
        Gets the simple class name from an internal name.
        Parameters:
        internalName - the internal class name (e.g., "com/foo/Bar$Inner")
        Returns:
        the simple name (e.g., "Inner" or "Bar" if no inner class)
      • getSimpleNameWithInnerClasses

        public static String getSimpleNameWithInnerClasses​(String internalName)
        Gets the simple class name from an internal name, ignoring inner class separators.
        Parameters:
        internalName - the internal class name (e.g., "com/foo/Bar$Inner")
        Returns:
        the simple name without inner class handling (e.g., "Bar$Inner")
      • getPackageName

        public static String getPackageName​(String internalName)
        Gets the package name from an internal name.
        Parameters:
        internalName - the internal class name (e.g., "com/foo/Bar")
        Returns:
        the package in internal format (e.g., "com/foo"), or empty string if no package
      • getPackageNameAsSource

        public static String getPackageNameAsSource​(String internalName)
        Gets the package name from an internal name in source format (with dots).
        Parameters:
        internalName - the internal class name (e.g., "com/foo/Bar")
        Returns:
        the package in source format (e.g., "com.foo"), or empty string if no package
      • toSourceName

        public static String toSourceName​(String internalName)
        Converts an internal name to a source name (dots instead of slashes).
        Parameters:
        internalName - the internal class name (e.g., "com/foo/Bar")
        Returns:
        the source name (e.g., "com.foo.Bar")
      • toSourceNameWithInnerClasses

        public static String toSourceNameWithInnerClasses​(String internalName)
        Like toSourceName(java.lang.String) but also renders a $ that separates a named nested class as ..
        Parameters:
        internalName - the internal class name, or null
        Returns:
        the source name, or null when the input is null
      • toInternalName

        public static String toInternalName​(String sourceName)
        Converts a source name to an internal name (slashes instead of dots).
        Parameters:
        sourceName - the source class name (e.g., "com.foo.Bar")
        Returns:
        the internal name (e.g., "com/foo/Bar")
      • isInnerClass

        public static boolean isInnerClass​(String internalName)
        Checks if the given internal name represents an inner class.
        Parameters:
        internalName - the internal class name
        Returns:
        true if this is an inner class (contains '$')
      • getOuterClassName

        public static String getOuterClassName​(String internalName)
        Gets the outer class name from an inner class name.
        Parameters:
        internalName - the internal class name (e.g., "com/foo/Bar$Inner")
        Returns:
        the outer class name (e.g., "com/foo/Bar"), or the original if not an inner class