home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2007 June
/
PCWorld_2007-06_cd.bin
/
multimedia
/
ppsee
/
PPSeeSetup.exe
/
lib
/
bsh-commands-2.0b4.jar
/
bsh
/
commands
/
javap.bsh
< prev
next >
Wrap
Text File
|
2005-05-23
|
2KB
|
63 lines
/**
Print the public fields and methods of the specified class (output similar
to the JDK javap command).
<p/>
If the argument is a string it is considered to be a class name. If the
argument is an object, the class of the object is used. If the arg is a
class, the class is used. If the argument is a class identifier, the class
identified by the class identifier will be used. e.g. If the argument is
the empty string an error will be printed.
<p/>
<pre>
// equivalent
javap( java.util.Date ); // class identifier
javap( java.util.Date.class ); // class
javap( "java.util.Date" ); // String name of class
javap( new java.util.Date() ); // instance of class
</pre>
@method void javap( String | Object | Class | ClassIdentifier )
*/
bsh.help.javap= "usage: javap( value )";
import bsh.ClassIdentifier;
import java.lang.reflect.Modifier;
javap( Object o )
{
Class clas;
if ( o instanceof ClassIdentifier )
clas = this.caller.namespace.identifierToClass(o);
else if ( o instanceof String )
{
if ( o.length() < 1 ) {
error("javap: Empty class name.");
return;
}
clas = this.caller.namespace.getClass((String)o);
} else if ( o instanceof Class )
clas = o;
else
clas = o.getClass();
print( "Class "+clas+" extends " +clas.getSuperclass() );
this.dmethods=clas.getDeclaredMethods();
//print("------------- Methods ----------------");
for(int i=0; i<dmethods.length; i++) {
this.m = dmethods[i];
if ( Modifier.isPublic( m.getModifiers() ) )
print( m );
}
//print("------------- Fields ----------------");
this.fields=clas.getDeclaredFields();
for(int i=0; i<fields.length; i++) {
this.f = fields[i];
if ( Modifier.isPublic( f.getModifiers() ) )
print( f );
}
}