home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Shareware / Comunicatii / advwebrank / awr.msi / disk1.cab / bsh_1.2b6.jar / bsh / commands / javap.bsh < prev    next >
Encoding:
Text File  |  2002-05-24  |  1.1 KB  |  47 lines

  1. /**
  2.     Print the public fields and methods of the specified class (output similar 
  3.     to the JDK javap command).
  4.     <p>
  5.     If the argument is a
  6.     string it is considered to be a class name.  If the argument is an object,
  7.     the class of the object is used.  If the arg is a class, the class is used.
  8.  
  9.     @method void javap( String | Object | Class )
  10. */
  11.  
  12. bsh.help.javap= "usage: javap( value )";
  13.  
  14. import bsh.Name;
  15. javap( Object o ) 
  16. {
  17.     import java.lang.reflect.Modifier;
  18.  
  19.     if ( o instanceof Name.ClassIdentifier )
  20.         clas = this.namespace.identifierToClass(o);
  21.     if ( o instanceof String)
  22.         clas = this.namespace.getClass((String)o);
  23.     else if ( o instanceof Class )
  24.         clas = o;
  25.     else 
  26.         clas = o.getClass();
  27.     
  28.     print( "Class "+clas+" extends " +clas.getSuperclass() );
  29.  
  30.     methods=clas.getDeclaredMethods();
  31.     //print("------------- Methods ----------------");
  32.     for(int i=0; i<methods.length; i++) {
  33.         m = methods[i];
  34.         if ( Modifier.isPublic( m.getModifiers() ) )
  35.             print( m );
  36.     }
  37.  
  38.     //print("------------- Fields ----------------");
  39.     fields=clas.getDeclaredFields();
  40.     for(int i=0; i<fields.length; i++) {
  41.         f = fields[i];
  42.         if ( Modifier.isPublic( f.getModifiers() ) )
  43.             print( f );
  44.     }
  45. }
  46.  
  47.