Package com.ibm.wala.util.strings
Class Atom
- java.lang.Object
-
- com.ibm.wala.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.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AtomarrayDescriptorFromElementDescriptor()Return array descriptor corresponding to "this" array-element descriptor.static Atomconcat(byte c, ImmutableByteArray b)static Atomconcat(Atom ma, Atom mb)booleancontains(byte b)booleanequals(Object obj)static AtomfindOrCreate(byte[] bytes)static AtomfindOrCreate(byte[] utf8, int off, int len)create an Atom from utf8[off] of length lenstatic AtomfindOrCreate(ImmutableByteArray b)static AtomfindOrCreate(ImmutableByteArray b, int start, int length)static AtomfindOrCreateAsciiAtom(String str)Find or create an atom.static AtomfindOrCreateUnicodeAtom(String str)Find or create an atom.static AtomfindOrCreateUtf8Atom(byte[] utf8)Find or create an atom.bytegetVal(int i)byte[]getValArray()return an array of bytes representing the utf8 characters in thisinthashCode()booleanisArrayDescriptor()Is "this" atom an array descriptor?static booleanisArrayDescriptor(ImmutableByteArray b)booleanisClassDescriptor()Is "this" atom a class descriptor?booleanisMethodDescriptor()Is "this" atom a method descriptor?booleanisReservedMemberName()Is "this" atom a reserved member name? Note: Sun has reserved all member names starting with '<' for future use.Atomleft(int count)New Atom containing first count bytesintlength()intparseForArrayDimensionality()Parse "this" array descriptor to obtain number of dimensions in corresponding array type.AtomparseForArrayElementDescriptor()Parse "this" array descriptor to obtain descriptor for array's element type.AtomparseForInnermostArrayElementDescriptor()Return the innermost element type reference for an arrayAtomright(int count)New Atom containing last count bytesintrIndex(byte b)booleanstartsWith(Atom start)StringtoString()Return printable representation of "this" atom.StringtoUnicodeString()Return printable representation of "this" atom.
-
-
-
Method Detail
-
findOrCreateUnicodeAtom
public static 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
public static Atom findOrCreateUtf8Atom(byte[] utf8)
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, IllegalArgumentException
create an Atom from utf8[off] of length len- Throws:
IllegalArgumentException- if utf8.length <= off
-
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 String toString()
Return printable representation of "this" atom. Does not correctly handle UTF8 translation.
-
toUnicodeString
public final String toUnicodeString() throws UTFDataFormatException
Return printable representation of "this" atom.- Throws:
UTFDataFormatException
-
left
public final Atom left(int count)
New Atom containing first count bytes
-
right
public final Atom right(int count)
New Atom containing last count bytes
-
startsWith
public final boolean startsWith(Atom start)
-
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, onlyand 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 IllegalArgumentExceptionIs "this" atom a method descriptor?- Throws:
IllegalArgumentException
-
length
public final int length()
-
parseForArrayElementDescriptor
public final Atom parseForArrayElementDescriptor() throws 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:
IllegalArgumentException
-
parseForArrayDimensionality
public final int parseForArrayDimensionality() throws IllegalArgumentExceptionParse "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 arrayIllegalArgumentException
-
parseForInnermostArrayElementDescriptor
public final Atom parseForInnermostArrayElementDescriptor() throws IllegalArgumentException
Return the innermost element type reference for an array- Throws:
IllegalStateException- if this Atom does not represent an array descriptorIllegalArgumentException
-
hashCode
public int hashCode()
- Overrides:
hashCodein classObject- See Also:
Object.hashCode()
-
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
public boolean contains(byte b)
- Returns:
- true iff this atom contains the specified byte
-
rIndex
public int rIndex(byte b)
-
concat
public static Atom concat(byte c, ImmutableByteArray b)
-
isArrayDescriptor
public static boolean isArrayDescriptor(ImmutableByteArray b)
-
-