PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/bsh/commands/which.bsh

#
Unknown | 44 lines | 35 code | 9 blank | 0 comment | 0 complexity | 446162a9d84edc326fc3414f6272aa38 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. Use classpath mapping to determine the source of the specified class
  3. file. (Like the Unix which command for executables).
  4. <p/>
  5. This command maps the entire classpath and prints all of the occurrences
  6. of the class. If you just want to find the first occurrence in the
  7. classpath (the one that will be used by Java) you can also get it by
  8. printing the URL of the resource. e.g.:
  9. <p/>
  10. <pre>
  11. print( getResource("/com/foo/MyClass.class") );
  12. // Same as...
  13. // System.out.println(
  14. // getClass().getResourceAsStream("/com/foo/MyClass.class" ) );
  15. </pre>
  16. <p/>
  17. Note: This is all a lie! This command is broken and only reports the
  18. currently first occurence! To be fixed!
  19. <p/>
  20. @method which( classIdentifier | string | class )
  21. */
  22. bsh.help.which= "usage: which( classIdentifier | string | class )";
  23. import bsh.ClassIdentifier;
  24. which( clas )
  25. {
  26. // make the class into a name
  27. Class clas;
  28. if ( clas instanceof ClassIdentifier )
  29. clas = this.namespace.identifierToClass( clas );
  30. if ( clas instanceof Class )
  31. clas = clas.getName();
  32. String className = clas;
  33. cp = this.caller.namespace.getClassManager().getClassPath();
  34. print ( cp.getClassSource( className ) );
  35. }