Class Atom

java.lang.Object
com.ibm.wala.core.util.strings.Atom
All Implemented Interfaces:
Serializable

public final class Atom extends Object implements Serializable
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.

Some of Atom's methods are deprecated. They are not used within WALA itself except by correctness tests, and we do not believe they are used anywhere outside of WALA. If you do use them outside of WALA, please let the WALA maintainers know so that we don't remove them in the future.

See Also:
  • Method Details

    • findOrCreateUnicodeAtom

      public static @NonNull Atom findOrCreateUnicodeAtom(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(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:
      IllegalArgumentException - if str is null
    • findOrCreateUtf8Atom

      @Deprecated(since="1.9.0") public static Atom findOrCreateUtf8Atom(byte[] utf8)
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Find or create an atom.
      Parameters:
      utf8 - atom value, as utf8 encoded bytes
      Returns:
      atom
      Throws:
      IllegalArgumentException - if utf8 is null
    • findOrCreate

      public static Atom findOrCreate(byte[] utf8, int off, int len) throws IllegalArgumentException, IllegalArgumentException
      create an Atom from utf8[off] of length len
      Throws:
      IllegalArgumentException - if utf8.length <= off
    • findOrCreate

      public static @NonNull Atom findOrCreate(byte[] bytes)
    • findOrCreate

      public static Atom findOrCreate(ImmutableByteArray b)
    • findOrCreate

      @Deprecated(since="1.9.0") public static Atom findOrCreate(ImmutableByteArray b, int start, int length)
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Find or create an atom from b[start] of length length.
      Parameters:
      b - the immutable byte array
      start - the offset of the first byte
      length - the number of bytes
      Returns:
      atom
    • toString

      public String toString()
      Return printable representation of "this" atom. Does not correctly handle UTF8 translation.
      Overrides:
      toString in class Object
    • toUnicodeString

      public String toUnicodeString() throws UTFDataFormatException
      Return printable representation of "this" atom.
      Throws:
      UTFDataFormatException
    • left

      @Deprecated(since="1.9.0") public Atom left(int count)
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      New Atom containing first count bytes.
    • right

      public Atom right(int count)
      New Atom containing last count bytes
    • startsWith

      public boolean startsWith(Atom start)
    • arrayDescriptorFromElementDescriptor

      @Deprecated(since="1.9.0") public Atom arrayDescriptorFromElementDescriptor()
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      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

      @Deprecated(since="1.9.0") public boolean isReservedMemberName()
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Is "this" atom a reserved member name? Note: Sun has reserved all member names starting with '<' for future use. At present, only <init> and <clinit> are used.
    • isClassDescriptor

      @Deprecated(since="1.9.0") public boolean isClassDescriptor()
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Is "this" atom a class descriptor?
    • isArrayDescriptor

      @Deprecated(since="1.9.0") public boolean isArrayDescriptor()
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Is "this" atom an array descriptor?
    • isMethodDescriptor

      @Deprecated(since="1.9.0") public boolean isMethodDescriptor() throws IllegalArgumentException
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Is "this" atom a method descriptor?
      Throws:
      IllegalArgumentException
    • length

      public int length()
    • parseForArrayElementDescriptor

      @Deprecated(since="1.9.0") public Atom parseForArrayElementDescriptor() throws IllegalArgumentException
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      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:
      IllegalArgumentException
    • parseForArrayDimensionality

      @Deprecated(since="1.9.0") public int parseForArrayDimensionality() throws IllegalArgumentException
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      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:
      IllegalStateException - if this Atom does not represent an array
      IllegalArgumentException
    • parseForInnermostArrayElementDescriptor

      @Deprecated(since="1.9.0") public Atom parseForInnermostArrayElementDescriptor() throws IllegalArgumentException
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Return the innermost element type reference for an array
      Throws:
      IllegalStateException - if this Atom does not represent an array descriptor
      IllegalArgumentException
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      These are canonical
      Overrides:
      equals in class Object
    • getValArray

      public byte[] getValArray()
      return an array of bytes representing the utf8 characters in this
    • getVal

      public byte getVal(int i) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • contains

      @Deprecated(since="1.9.0") public boolean contains(byte b)
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Returns:
      true iff this atom contains the specified byte
    • rIndex

      public int rIndex(byte b)
    • concat

      @Deprecated(since="1.9.0") public static Atom concat(byte c, ImmutableByteArray b)
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Concatenate a byte with an immutable byte array to form an atom.
      Parameters:
      c - the leading byte
      b - the following bytes
      Returns:
      atom
    • concat

      public static Atom concat(Atom ma, Atom mb)
    • isArrayDescriptor

      @Deprecated(since="1.9.0") public static boolean isArrayDescriptor(ImmutableByteArray b)
      Deprecated.
      This method is used only by WALA's own unit tests. It may be removed in a future release.
      Is the given immutable byte array an array descriptor?
      Parameters:
      b - the immutable byte array
      Returns:
      true iff the first byte is '['