Class DotName

java.lang.Object
org.jboss.jandex.DotName
All Implemented Interfaces:
Comparable<DotName>

public final class DotName extends Object implements Comparable<DotName>
A DotName represents a dot separated name, typically a Java package or a Java class. It has two possible variants. A simple wrapper based variant allows for fast construction (it simply wraps the specified name string). Whereas, a componentized variant represents one or more String methodInternal that when combined with a dot character, assemble the full name. The intention of the componentized variant is that the String methodInternal can be reused to offer memory efficiency. This reuse is common in Java where packages and classes follow a tree structure.

Both the simple and componentized variants are considered semantically equivalent if they refer to the same logical name. More specifically the equals and hashCode methods return the same values for the same semantic name regardless of the variant used. Which variant to use when depends on the specific performance and overhead objectives of the specific use pattern.

Simple names are cheap to construct (just a an additional wrapper object), so are ideal for temporary use, like looking for an entry in a Map. Componentized names however require that they be split in advance, and so require some additional time to construct. However the memory benefits of reusing component strings make them desirable when stored in a longer term area such as in a Java data structure.

  • Field Details

    • JAVA_NAME

      static final DotName JAVA_NAME
    • JAVA_LANG_NAME

      static final DotName JAVA_LANG_NAME
    • OBJECT_NAME

      static final DotName OBJECT_NAME
    • ENUM_NAME

      static final DotName ENUM_NAME
    • RECORD_NAME

      static final DotName RECORD_NAME
    • prefix

      private final DotName prefix
    • local

      private final String local
    • hash

      private int hash
    • componentized

      private final boolean componentized
    • innerClass

      private final boolean innerClass
  • Constructor Details

    • DotName

      DotName(DotName prefix, String local, boolean noDots, boolean innerClass)
  • Method Details

    • createSimple

      public static DotName createSimple(String name)
      Constructs a simple DotName which stores the string in it's entirety. This variant is ideal for temporary usage, such as looking up an entry in a Map.
      Parameters:
      name - A fully qualified non-null name (with dots)
      Returns:
      a simple DotName that wraps name
    • createComponentized

      public static DotName createComponentized(DotName prefix, String localName)
      Constructs a componentized DotName. Each DotName refers to a parent prefix (or null if there is no further prefix) in addition to a local name that has no dot separator. The fully qualified name this DotName represents is constructed by recursing all parent prefixes and joining all local name values with the '.' character.
      Parameters:
      prefix - Another DotName that is the portion to the left of localName, this may be null if there is not one
      localName - the local non-null portion of this name, which does not contain '.'
      Returns:
      a componentized DotName.
    • createComponentized

      public static DotName createComponentized(DotName prefix, String localName, boolean innerClass)
      Constructs a componentized DotName. Each DotName refers to a parent prefix (or null if there is no further prefix) in addition to a local name that has no dot separator. The fully qualified name this DotName represents is consructed by recursing all parent prefixes and joining all local name values with the '.' character.
      Parameters:
      prefix - Another DotName that is the portion to the left of localName, this may be null if there is not one
      localName - the local non-null portion of this name, which does not contain '.'
      innerClass - whether or not this localName is an inner class style name, requiring '$' vs '.'
      Returns:
      a componentized DotName.
    • prefix

      public DotName prefix()
      Returns the parent prefix for this DotName or null if there is none. Simple DotName variants never have a prefix.
      Returns:
      the parent prefix for this DotName
    • local

      public String local()
      Returns the local portion of this DotName. In simple variants, the entire fully qualified string is returned. In componentized variants, just the right most portion not including a separator (either . or $) is returned.

      Use withoutPackagePrefix() instead of this method if the desired value is simply the right most portion (including dollar signs if present) after a '.' delimiter.

      Returns:
      the non-null local portion of this DotName
    • withoutPackagePrefix

      public String withoutPackagePrefix()
      Returns the portion of this DotName that does not contain a package prefix. In the case of an inner class syntax name, the $ portion is included in the return value.
      Returns:
      the portion of the name that is not package prefixed
      Since:
      2.1.1
    • stripPackage

      private void stripPackage(StringBuilder builder)
    • packagePrefix

      public String packagePrefix()
      Returns the package portion of this DotName.
      Returns:
      the package name or null if this DotName has no package prefix
      Since:
      2.4
    • isComponentized

      public boolean isComponentized()
      Returns whether this DotName is a componentized variant.
      Returns:
      true if it is componentized, false if it is a simple DotName
    • isInner

      public boolean isInner()
      Returns whether the local portion of a componentized DotName is separated by an inner class style delimiter ('$"). This should not be used to test whether the name truly refers to an inner class, only that the dollar sign delimits the value. Java class names are allowed to contain dollar signs, so the local value could simply be a fragment of a class name, and not an actual inner class. The correct way to determine whether or not a name refers to an actual inner class is to lookup a ClassInfo in the index and call and examine the nesting type like so:
          index.get(name).nestingType() != TOP_LEVEL;
       
      Returns:
      true if local is an inner class style delimited name, false otherwise
    • toString

      public String toString()
      Returns the regular fully qualifier class name.
      Overrides:
      toString in class Object
      Returns:
      The fully qualified class name
    • toString

      public String toString(char delim)
    • buildString

      private void buildString(char delim, StringBuilder builder)
    • hashCode

      public int hashCode()
      Returns a hash code which is based on the semantic representation of this DotName. Whether or not a DotName is componentized has no impact on the calculated hash code.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code representing this object
      See Also:
    • compareTo

      public int compareTo(DotName other)
      Compares a DotName to another DotName and returns whether this DotName is lesser than, greater than, or equal to the specified DotName. If this DotName is lesser, a negative value is returned. If greater, a positive value is returned. If equal, zero is returned.
      Specified by:
      compareTo in interface Comparable<DotName>
      Parameters:
      other - the DotName to compare to
      Returns:
      a negative number if this is less than the specified object, a positive if greater, and zero if equal
      See Also:
    • equals

      public boolean equals(Object o)
      Compares a DotName to another DotName and returns true if the represent the same underlying semantic name. In other words, whether or not a name is componentized or simple has no bearing on the comparison.
      Overrides:
      equals in class Object
      Parameters:
      o - the DotName object to compare to
      Returns:
      true if equal, false if not
      See Also:
    • crossEquals

      private static boolean crossEquals(DotName simple, DotName comp)
    • nextChar

      private int nextChar(DotName.IndexState state, DotName name)