PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/bsh/commands/javap.bsh

#
Unknown | 62 lines | 54 code | 8 blank | 0 comment | 0 complexity | cb8ec40d069d7684cfb4873148f71360 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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 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.methods=clas.getDeclaredMethods();
  41. //print("------------- Methods ----------------");
  42. for(int i=0; i<methods.length; i++) {
  43. this.m = methods[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. }