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.

Author:
Arthur van Hoff
  • Field Details

    • 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:
  • Method Details

    • 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.