bsh.commands.which.bsh Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bsh Show documentation
Show all versions of bsh Show documentation
BeanShell is a small, free, embeddable Java source interpreter with object scripting language features,
written in Java. BeanShell dynamically executes standard Java syntax and extends it with common scripting
conveniences such as loose types, commands, and method closures like those in Perl and JavaScript.
The newest version!
/**
Use classpath mapping to determine the source of the specified class
file. (Like the Unix which command for executables).
This command maps the entire classpath and prints all of the occurrences
of the class. If you just want to find the first occurrence in the
classpath (the one that will be used by Java) you can also get it by
printing the URL of the resource. e.g.:
print( getResource("/com/foo/MyClass.class") );
// Same as...
// System.out.println(
// getClass().getResourceAsStream("/com/foo/MyClass.class" ) );
Note: This is all a lie! This command is broken and only reports the
currently first occurence! To be fixed!
@method which( classIdentifier | string | class )
*/
bsh.help.which= "usage: which( classIdentifier | string | class )";
import bsh.ClassIdentifier;
which( clas )
{
// make the class into a name
Class clas;
if ( clas instanceof ClassIdentifier )
clas = this.namespace.identifierToClass( clas );
if ( clas instanceof Class )
clas = clas.getName();
String className = clas;
cp = this.caller.namespace.getClassManager().getClassPath();
print ( cp.getClassSource( className ) );
}