/jEdit/tags/jedit-4-3-1/org/gjt/sp/jedit/bsh/commands/javap.bsh

# · Unknown · 62 lines · 54 code · 8 blank · 0 comment · 0 complexity · ce1710a4094235617e3ae6df6f43830e MD5 · raw file

  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 string it is considered to be a class name. If the
  6. argument is an object, the class of the object is used. If the arg is a
  7. class, the class is used. If the argument is a class identifier, the class
  8. identified by the class identifier will be used. e.g. If the argument is
  9. the empty string an error will be printed.
  10. <p/>
  11. <pre>
  12. // equivalent
  13. javap( java.util.Date ); // class identifier
  14. javap( java.util.Date.class ); // class
  15. javap( "java.util.Date" ); // String name of class
  16. javap( new java.util.Date() ); // instance of class
  17. </pre>
  18. @method void javap( String | Object | Class | ClassIdentifier )
  19. */
  20. bsh.help.javap= "usage: javap( value )";
  21. import org.gjt.sp.jedit.bsh.ClassIdentifier;
  22. import java.lang.reflect.Modifier;
  23. javap( Object o )
  24. {
  25. Class clas;
  26. if ( o instanceof ClassIdentifier )
  27. clas = this.caller.namespace.identifierToClass(o);
  28. else if ( o instanceof String )
  29. {
  30. if ( o.length() < 1 ) {
  31. error("javap: Empty class name.");
  32. return;
  33. }
  34. clas = this.caller.namespace.getClass((String)o);
  35. } else if ( o instanceof Class )
  36. clas = o;
  37. else
  38. clas = o.getClass();
  39. print( "Class "+clas+" extends " +clas.getSuperclass() );
  40. this.dmethods=clas.getDeclaredMethods();
  41. //print("------------- Methods ----------------");
  42. for(int i=0; i<dmethods.length; i++) {
  43. this.m = dmethods[i];
  44. if ( Modifier.isPublic( m.getModifiers() ) )
  45. print( m );
  46. }
  47. //print("------------- Fields ----------------");
  48. this.fields=clas.getDeclaredFields();
  49. for(int i=0; i<fields.length; i++) {
  50. this.f = fields[i];
  51. if ( Modifier.isPublic( f.getModifiers() ) )
  52. print( f );
  53. }
  54. }