Class Identifier

java.lang.Object
org.glassfish.rmic.tools.java.Identifier
All Implemented Interfaces:
Constants, RuntimeConstants

public final class Identifier extends Object implements Constants
A class to represent identifiers.

An identifier instance is very similar to a String. The difference is that identifier can't be instanciated directly, instead they are looked up in a hash table. This means that identifiers with the same name map to the same identifier object. This makes comparisons of identifiers much faster.

A lot of identifiers are qualified, that is they have '.'s in them. Each qualified identifier is chopped up into the qualifier and the name. The qualifier is cached in the value field.

Unqualified identifiers can have a type. This type is an integer that can be used by a scanner as a token value. This value has to be set using the setType method.

WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.

  • Field Details

    • hash

      static Hashtable<String,Identifier> hash
      The hashtable of identifiers
    • name

      String name
      The name of the identifier
    • value

      Object value
      The value of the identifier, for keywords this is an instance of class Integer, for qualified names this is another identifier (the qualifier).
    • typeObject

      Type typeObject
      The Type which corresponds to this Identifier. This is used as cache for Type.tClass() and shouldn't be used outside of that context.
    • ipos

      private int ipos
      The index of INNERCLASS_PREFIX in the name, or -1 if none.
    • INNERCLASS_PREFIX

      public static final char INNERCLASS_PREFIX
      A space character, which precedes the first inner class name in a qualified name, and thus marks the qualification as involving inner classes, instead of merely packages.

      Ex: java.util.Vector. Enumerator.

      See Also:
    • ambigPrefix

      private static final String ambigPrefix
      A special prefix to add to ambiguous names.
      See Also:
  • Constructor Details

    • Identifier

      private Identifier(String name)
      Construct an identifier. Don't call this directly, use lookup instead.
      See Also:
      • invalid reference
        Identifier.lookup
  • Method Details

    • getType

      int getType()
      Get the type of the identifier.
    • setType

      void setType(int t)
      Set the type of the identifier.
    • lookup

      public static Identifier lookup(String s)
      Lookup an identifier.
    • lookup

      public static Identifier lookup(Identifier q, Identifier n)
      Lookup a qualified identifier.
    • lookupInner

      public static Identifier lookupInner(Identifier c, Identifier n)
      Lookup an inner identifier. (Note: n can be idNull.)
    • toString

      public String toString()
      Convert to a string.
      Overrides:
      toString in class Object
    • isQualified

      public boolean isQualified()
      Check if the name is qualified (ie: it contains a '.').
    • getQualifier

      public Identifier getQualifier()
      Return the qualifier. The null identifier is returned if the name was not qualified. The qualifier does not include any inner part of the name.
    • getName

      public Identifier getName()
      Return the unqualified name. In the case of an inner name, the unqualified name will itself contain components.
    • isInner

      public boolean isInner()
      Check if the name is inner (ie: it contains a ' ').
    • getFlatName

      public Identifier getFlatName()
      Return the class name, without its qualifier, and with any nesting flattened into a new qualfication structure. If the original identifier is inner, the result will be qualified, and can be further decomposed by means of getQualifier and getName.

      For example:

       Identifier id = Identifier.lookup("pkg.Foo. Bar");
       id.getName().name      =>  "Foo. Bar"
       id.getFlatName().name  =>  "Foo.Bar"
       
    • getTopName

      public Identifier getTopName()
    • getHead

      public Identifier getHead()
      Yet another way to slice qualified identifiers: The head of an identifier is its first qualifier component, and the tail is the rest of them.
    • getTail

      public Identifier getTail()
      See Also:
    • hasAmbigPrefix

      public boolean hasAmbigPrefix()
      Determine whether an Identifier has been marked as ambiguous.
    • addAmbigPrefix

      public Identifier addAmbigPrefix()
      Add ambigPrefix to `this' to make a new Identifier marked as ambiguous. It is important that this new Identifier not refer to an existing class.
    • removeAmbigPrefix

      public Identifier removeAmbigPrefix()
      Remove the ambigPrefix from `this' to get the original identifier.