|
Jode 1.90-CVS Build Aug 6, 2004 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jode.bytecode.BinaryInfo
net.sf.jode.bytecode.ClassInfo
Represents a class or interface. It can't be used for primitive or array types. Every class/interface is associated with a class path, which is used to load the class and its dependent classes.
ClassPath
. This
class path is used to find the class and its dependent classes,
e.g. the super class. Even if you want to create a class info from
the scratch you have to associate it with a class path, in which
the dependent classes are searched.
For every class path and every class name there exists at most one
class info object with this class name. The only exception is when
you overwrite a loaded class, e.g. by calling setName().
ClassPath.getClassInfo(java.lang.String)
.
Multiple calls of this method with the same class name result in
the same object. The resulting ClassInfo is initially empty and
you now have three different means to fill it with informations:
You can load
the class from its classpath (from which
it was created), you can guess
the information
(useful if the class can't be loaded), or you build it from scratch
by setting its contents with the various setSomething
methods.
setSomething
methods.
setName(java.lang.String)
method.
getClassName()
also works for package scope classes,
setClassName() must only be called on inner classes and will not
change the bytecode name.java.util.Map$Entry
is
Entry
. If you change its ClassName to
Yrtne
and save it, it will still be in a file called
Map$Entry.class
, but a debugger would call it
java.util.Map.Yrtne
. Note that you should also save
Map
, because it also has a reference to the
ClassName.
Modifier
.
java.lang.Object
has a super
class. The super class is created in the same classpath as the
current class. Interfaces always have
java.lang.Object
as their super class.
FieldInfo
objects.
MethodInfo
objects.
java.util.Map$Entry
. There are four different
types of classes:
getOuterClass()
returns null
and
isMethodScoped()
returns false
.
getOuterClass()
returns not null
.
The bytecode name (getName()
) of an inner class is
in normally of the form Package.Outer$Inner
. However,
ClassInfo also supports differently named classes, as long as the
InnerClass attribute is present. The method
getClassName()
returns the name of the inner class
(Inner
in the above example).
You can get all inner classes of a class with the
method getClasses()
.
isMethodScoped()
returns true
and
getClassName()
returns not null
. In
that case getOuterClass()
returns null
,
too.getName()
) of a method scoped class is
normally of the form Package.Outer$Number$Inner
. However,
ClassInfo also supports differently named classes, as long as the
InnerClass attribute is present. isMethodScoped()
returns true
and
getClassName()
returns null
. In that
case getOuterClass()
returns null
,
too.getName()
) of a method scoped class
is normally of the form Package.Outer$Number
.
However, ClassInfo also supports differently named classes, as
long as the InnerClass attribute is present. String
objects (type
signatures); this is convenient since java bytecode does the same.
On the other hand a class type should be represented as
ClassInfo
object. There is a method in TypeSignature
to convert between them, which needs a class path. This is a
bit difficult to use.
Field Summary | |
static int |
ALL
This constant can be used as parameter to load. |
static int |
ALMOSTALL
This constant can be used as parameter to load. |
static int |
DECLARATIONS
This constant can be used as parameter to load. |
static int |
HIERARCHY
This constant can be used as parameter to load. |
static int |
NODEBUG
This constant can be used as parameter to load. |
static int |
NONE
This constant can be used as parameter to drop. |
static int |
OUTERCLASS
This constant can be used as parameter to load. |
static int |
PUBLICDECLARATIONS
This constant can be used as parameter to load. |
Fields inherited from class net.sf.jode.bytecode.BinaryInfo |
ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE |
Method Summary | |
int |
compareTo(java.lang.Object other)
Compares two ClassInfo objects for name order. |
void |
drop(int keep)
This is the counter part to load and guess. |
static boolean |
exists(java.lang.String name)
Deprecated. |
FieldInfo |
findField(java.lang.String name,
java.lang.String typeSig)
Searches for a field with given name and type signature. |
MethodInfo |
findMethod(java.lang.String name,
java.lang.String typeSig)
Searches for a method with given name and type signature. |
static ClassInfo |
forName(java.lang.String name)
Deprecated. |
protected int |
getAttributeCount()
Count the attributes needed by the class. |
ClassInfo[] |
getClasses()
Gets the inner classes declared in this class. |
static java.util.Enumeration |
getClassesAndPackages(java.lang.String packageName)
Deprecated. |
java.lang.String |
getClassName()
Returns the java class name of a class, without package or outer classes. |
ClassPath |
getClassPath()
Returns the classpath in which this class was created. |
FieldInfo[] |
getFields()
Gets the fields (class and member variables) of this class. |
ClassInfo[] |
getInterfaces()
Returns the ClassInfo object for the super class. |
MethodInfo[] |
getMethods()
Gets the methods of this class. |
int |
getModifiers()
Gets the modifiers of this class, e.g. public or abstract. |
java.lang.String |
getName()
Returns the full qualified name of this class. |
ClassInfo |
getOuterClass()
Returns the outer class of this class if it is an inner class. |
long |
getSerialVersionUID()
Gets the serial version UID of this class. |
java.lang.String |
getSignature()
Gets the type signature including template information of the class. |
java.lang.String |
getSourceFile()
|
ClassInfo |
getSuperclass()
Returns the ClassInfo object for the super class. |
void |
guess(int howMuch)
Guess the contents of a class. |
boolean |
implementedBy(ClassInfo clazz)
Checks if this interface is implemented by clazz. |
boolean |
isDeprecated()
Checks whether this class was declared as deprecated. |
boolean |
isGuessed()
Tells whether the information in this class was guessed by a call to guess(int) . |
boolean |
isInterface()
Checks whether this class info represents an interface. |
boolean |
isMethodScoped()
Tells whether the class was declared inside a method. |
static boolean |
isPackage(java.lang.String name)
Deprecated. |
void |
load(int howMuch)
Loads the contents of a class from its class path. |
void |
read(java.io.DataInputStream input,
int howMuch)
Reads a class file from a data input stream. |
protected void |
readAttribute(java.lang.String name,
int length,
ConstantPool cp,
java.io.DataInputStream input,
int howMuch)
Reads in an attributes of this class. |
void |
setClasses(ClassInfo[] ic)
|
static void |
setClassPath(ClassPath path)
Deprecated. |
static void |
setClassPath(java.lang.String path)
Deprecated. |
void |
setDeprecated(boolean flag)
|
void |
setFields(FieldInfo[] fi)
|
void |
setInterfaces(ClassInfo[] newIfaces)
|
void |
setMethods(MethodInfo[] mi)
|
void |
setMethodScoped(boolean ms)
|
void |
setModifiers(int newModifiers)
|
void |
setName(java.lang.String newName)
Sets the name of this class info. |
void |
setOuterClass(ClassInfo oc)
|
void |
setSourceFile(java.lang.String newSource)
|
void |
setSuperclass(ClassInfo newSuper)
|
boolean |
superClassOf(ClassInfo child)
Checks if this class is a super class of child. |
java.lang.String |
toString()
Returns a string representation of the class. |
void |
write(java.io.DataOutputStream out)
Writes a class to the given DataOutputStream. |
protected void |
writeAttributes(GrowableConstantPool gcp,
java.io.DataOutputStream output)
Write the attributes needed by the class, namely SourceFile and InnerClasses attributes. |
Methods inherited from class net.sf.jode.bytecode.BinaryInfo |
addAttribute, findAttribute, getAttributes, getAttributeSize, prepareAttributes, removeAllAttributes, removeAttribute |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int NONE
load(int)
,
Constant Field Valuespublic static final int OUTERCLASS
load(int)
,
Constant Field Valuespublic static final int HIERARCHY
load(int)
,
Constant Field Valuespublic static final int PUBLICDECLARATIONS
load(int)
,
Constant Field Valuespublic static final int DECLARATIONS
load(int)
,
Constant Field Valuespublic static final int NODEBUG
load(int)
,
Constant Field Valuespublic static final int ALMOSTALL
load(int)
,
Constant Field Valuespublic static final int ALL
load(int)
,
Constant Field ValuesMethod Detail |
public static void setClassPath(java.lang.String path)
public static void setClassPath(ClassPath path)
public static boolean exists(java.lang.String name)
public static boolean isPackage(java.lang.String name)
public static java.util.Enumeration getClassesAndPackages(java.lang.String packageName)
public static ClassInfo forName(java.lang.String name)
public ClassPath getClassPath()
protected void readAttribute(java.lang.String name, int length, ConstantPool cp, java.io.DataInputStream input, int howMuch) throws java.io.IOException
BinaryInfo
readAttribute
in class BinaryInfo
name
- the attribute name.length
- the length of the attribute.cp
- the constant pool of the class.input
- a data input stream where you can read the attribute
from. It will protect you to read more over the attribute boundary.howMuch
- the constant that was given to the load(int)
function when loading this class.
java.io.IOException
public void read(java.io.DataInputStream input, int howMuch) throws java.io.IOException
load
a class from its classpath instead. This may
be useful for special kinds of input streams, that ClassPath
doesn't handle.
input
- The input stream, containing the class in standard
bytecode format.howMuch
- The amount of information that should be read in, one
of HIERARCHY, PUBLICDECLARATIONS, DECLARATIONS or ALL.
ClassFormatException
- if the file doesn't denote a valid
class.
java.io.IOException
- if input throws an exception.
java.lang.IllegalStateException
- if this ClassInfo was modified.load(int)
protected int getAttributeCount()
getAttributeCount
in class BinaryInfo
protected void writeAttributes(GrowableConstantPool gcp, java.io.DataOutputStream output) throws java.io.IOException
writeAttributes
in class BinaryInfo
gcp
- The growable constant pool, which is not
growable anymore (see above).output
- the data output stream. You must write exactly
as many bytes to it as you have told with the BinaryInfo.getAttributeSize()
method.
java.io.IOException
public void write(java.io.DataOutputStream out) throws java.io.IOException
out
- the output stream.
java.io.IOException
- if out throws io exception.
java.lang.IllegalStateException
- if not enough information is set.public void load(int howMuch) throws java.io.IOException
howMuch
- The amount of information that should be loaded
at least, one of OUTERCLASS
, HIERARCHY
, PUBLICDECLARATIONS
, DECLARATIONS
, NODEBUG
,
ALMOSTALL
or ALL
. Note that more information
than requested can be loaded if this is convenient.
ClassFormatException
- if the file doesn't denote a
valid class.
java.io.FileNotFoundException
- if class wasn't found in classpath.
java.io.IOException
- if an io exception occured while reading
the class.
java.lang.SecurityException
- if a security manager prohibits loading
the class.
java.lang.IllegalStateException
- if this ClassInfo was modified by
calling one of the setSomething methods.public void guess(int howMuch)
howMuch
- The amount of information that should be read,
e.g. HIERARCHY
.OUTERCLASS
,
HIERARCHY
,
PUBLICDECLARATIONS
,
DECLARATIONS
,
ALMOSTALL
,
ALL
public void drop(int keep)
drop
in class BinaryInfo
keep
- tells how much info we should keep, can be
NONE
or anything that load
accepts.load(int)
public java.lang.String getName()
public boolean isGuessed()
guess(int)
.
public java.lang.String getClassName()
class
keyword (provided it was compiled from
java).
This need OUTERCLASS information loaded to work properly.
java.lang.IllegalStateException
- if OUTERCLASS information wasn't
loaded yet.public ClassInfo getSuperclass()
java.lang.IllegalStateException
- if HIERARCHY information wasn't
loaded yet.public ClassInfo[] getInterfaces()
java.lang.IllegalStateException
- if HIERARCHY information wasn't
loaded yet.public java.lang.String getSignature()
TypeSignature
public int getModifiers()
HIERARCHY
is
loaded.
Class.getModifiers()
,
ACC_* fields in BinaryInfo
public boolean isInterface()
HIERARCHY
is
loaded.
public boolean isDeprecated()
public FieldInfo findField(java.lang.String name, java.lang.String typeSig)
name
- the name of the field.typeSig
- the type signature
of the
field.
public MethodInfo findMethod(java.lang.String name, java.lang.String typeSig)
name
- the name of the method.typeSig
- the type signature
of the
method.
public MethodInfo[] getMethods()
public FieldInfo[] getFields()
public ClassInfo getOuterClass()
java.lang.IllegalStateException
- if OUTERCLASS information
wasn't loaded yet.public boolean isMethodScoped()
java.lang.IllegalStateException
- if OUTERCLASS information
wasn't loaded yet.public ClassInfo[] getClasses()
java.lang.IllegalStateException
- if PUBLICDECLARATIONS information
wasn't loaded yet.public java.lang.String getSourceFile()
public void setName(java.lang.String newName)
public void setSuperclass(ClassInfo newSuper)
public void setInterfaces(ClassInfo[] newIfaces)
public void setModifiers(int newModifiers)
public void setDeprecated(boolean flag)
public void setMethods(MethodInfo[] mi)
public void setFields(FieldInfo[] fi)
public void setOuterClass(ClassInfo oc)
public void setMethodScoped(boolean ms)
public void setClasses(ClassInfo[] ic)
public void setSourceFile(java.lang.String newSource)
public long getSerialVersionUID() throws java.security.NoSuchAlgorithmException
java.lang.IllegalStateException
- if DECLARATIONS aren't loaded.
java.security.NoSuchAlgorithmException
- if SHA-1 message digest is not
supported (needed for calculation of UID.public int compareTo(java.lang.Object other)
compareTo
in interface java.lang.Comparable
java.lang.ClassCastException
- if other is not a ClassInfo.public boolean superClassOf(ClassInfo child) throws java.io.IOException
child
- the class that should be a child class of us.
java.io.IOException
- if hierarchy of child could not be loaded.public boolean implementedBy(ClassInfo clazz) throws java.io.IOException
clazz
- the class to be checked.
java.io.IOException
- if hierarchy of clazz could not be loaded.public java.lang.String toString()
|
Jode 1.90-CVS Build Aug 6, 2004 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |