com.ibm.wala.util
Class Atom

java.lang.Object
  extended by com.ibm.wala.util.Atom

public final class Atom
extends java.lang.Object

An utf8-encoded byte string. Atom's are interned (canonicalized) so they may be compared for equality using the "==" operator. Atoms are used to represent names, descriptors, and string literals appearing in a class's constant pool.


Method Summary
 Atom arrayDescriptorFromElementDescriptor()
          Return array descriptor corresponding to "this" array-element descriptor.
static Atom concat(byte c, ImmutableByteArray b)
           
 boolean contains(byte b)
           
 boolean equals(java.lang.Object obj)
           
static Atom findOrCreate(byte[] bytes)
           
static Atom findOrCreate(byte[] utf8, int off, int len)
           
static Atom findOrCreate(ImmutableByteArray b)
           
static Atom findOrCreate(ImmutableByteArray b, int start, int length)
           
static Atom findOrCreateAsciiAtom(java.lang.String str)
          Find or create an atom.
static Atom findOrCreateUnicodeAtom(java.lang.String str)
          Find or create an atom.
static Atom findOrCreateUtf8Atom(byte[] utf8)
          Find or create an atom.
 byte getVal(int i)
           
 int hashCode()
           
 boolean isArrayDescriptor()
          Is "this" atom an array descriptor?
static boolean isArrayDescriptor(ImmutableByteArray b)
           
 boolean isClassDescriptor()
          Is "this" atom a class descriptor?
 boolean isMethodDescriptor()
          Is "this" atom a method descriptor?
 boolean isReservedMemberName()
          Is "this" atom a reserved member name? Note: Sun has reserved all member names starting with '<' for future use.
 int length()
           
 int parseForArrayDimensionality()
          Parse "this" array descriptor to obtain number of dimensions in corresponding array type.
 Atom parseForArrayElementDescriptor()
          Parse "this" array descriptor to obtain descriptor for array's element type.
 Atom parseForInnermostArrayElementDescriptor()
          Return the innermost element type reference for an array
 java.lang.String toString()
          Return printable representation of "this" atom.
 java.lang.String toUnicodeString()
          Return printable representation of "this" atom.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

findOrCreateUnicodeAtom

public static Atom findOrCreateUnicodeAtom(java.lang.String str)
Find or create an atom.

Parameters:
str - atom value, as string literal whose characters are unicode
Returns:
atom

findOrCreateAsciiAtom

public static Atom findOrCreateAsciiAtom(java.lang.String str)
Find or create an atom.

Parameters:
str - atom value, as string literal whose characters are from ascii subset of unicode (not including null)
Returns:
atom
Throws:
java.lang.IllegalArgumentException - if str is null

findOrCreateUtf8Atom

public static Atom findOrCreateUtf8Atom(byte[] utf8)
Find or create an atom.

Parameters:
utf8 - atom value, as utf8 encoded bytes
Returns:
atom
Throws:
java.lang.IllegalArgumentException - if utf8 is null

findOrCreate

public static Atom findOrCreate(byte[] utf8,
                                int off,
                                int len)
                         throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

findOrCreate

public static Atom findOrCreate(byte[] bytes)

findOrCreate

public static Atom findOrCreate(ImmutableByteArray b)

findOrCreate

public static Atom findOrCreate(ImmutableByteArray b,
                                int start,
                                int length)

toString

public final java.lang.String toString()
Return printable representation of "this" atom. Does not correctly handle UTF8 translation.

Overrides:
toString in class java.lang.Object

toUnicodeString

public final java.lang.String toUnicodeString()
                                       throws java.io.UTFDataFormatException
Return printable representation of "this" atom.

Throws:
java.io.UTFDataFormatException

arrayDescriptorFromElementDescriptor

public final Atom arrayDescriptorFromElementDescriptor()
Return array descriptor corresponding to "this" array-element descriptor. this: array-element descriptor - something like "I" or "Ljava/lang/Object;"

Returns:
array descriptor - something like "[I" or "[Ljava/lang/Object;"

isReservedMemberName

public final boolean isReservedMemberName()
Is "this" atom a reserved member name? Note: Sun has reserved all member names starting with '<' for future use. At present, only and are used.


isClassDescriptor

public final boolean isClassDescriptor()
Is "this" atom a class descriptor?


isArrayDescriptor

public final boolean isArrayDescriptor()
Is "this" atom an array descriptor?


isMethodDescriptor

public final boolean isMethodDescriptor()
                                 throws java.lang.IllegalArgumentException
Is "this" atom a method descriptor?

Throws:
java.lang.IllegalArgumentException

length

public final int length()

parseForArrayElementDescriptor

public final Atom parseForArrayElementDescriptor()
                                          throws java.lang.IllegalArgumentException
Parse "this" array descriptor to obtain descriptor for array's element type. this: array descriptor - something like "[I"

Returns:
array element descriptor - something like "I"
Throws:
java.lang.IllegalArgumentException

parseForArrayDimensionality

public final int parseForArrayDimensionality()
                                      throws java.lang.IllegalArgumentException
Parse "this" array descriptor to obtain number of dimensions in corresponding array type. this: descriptor - something like "[Ljava/lang/String;" or "[[I"

Returns:
dimensionality - something like "1" or "2"
Throws:
java.lang.IllegalArgumentException

parseForInnermostArrayElementDescriptor

public final Atom parseForInnermostArrayElementDescriptor()
                                                   throws java.lang.IllegalArgumentException
Return the innermost element type reference for an array

Throws:
java.lang.IllegalArgumentException

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getVal

public byte getVal(int i)
            throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

contains

public boolean contains(byte b)
Returns:
true iff this atom contains the specified byte

concat

public static Atom concat(byte c,
                          ImmutableByteArray b)

isArrayDescriptor

public static boolean isArrayDescriptor(ImmutableByteArray b)