Filewatcher File Search
FTP Search
  
Directory (beta)
  
Content Search (beta)
   
pkg://jedit-4.2-0.pre14.1jpp.src.rpm:1841458/jedit42pre14source.tar.gz  info  downloads

jEdit/bsh/commands/addClassPath.bsh0100600000175000017500000000122207773210647016524 0ustar  slavaslava/**
	Add the specified directory or JAR file to the class path.
	e.g.
	<p>
	<pre>
    addClassPath( "/home/pat/java/classes" );
    addClassPath( "/home/pat/java/mystuff.jar" );
    addClassPath( new URL("http://myserver/~pat/somebeans.jar") );
	</pre>
	<p>
	See <a href="classpath.html">Class Path Management</a>

	@method void addClassPath( string | URL )
*/

bsh.help.addClassPath= "usage: addClassPath( string | URL )";

import java.net.URL;
import bsh.BshClassManager;

addClassPath( path ) {
	URL url;
	if ( path instanceof URL )
		url = path;
	else
		url = pathToFile( path ).toURL();

	this.caller.namespace.getClassManager().addClassPath( url );
}

jEdit/bsh/commands/which.bsh0100600000175000017500000000231407773210647015276 0ustar  slavaslava/**
	Use classpath mapping to determine the source of the specified class
	file.  (Like the Unix which command for executables).
	<p/>

    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.:
	<p/>

    <pre>
        print( getResource("/com/foo/MyClass.class") );
		// Same as...
        // System.out.println(
        //    getClass().getResourceAsStream("/com/foo/MyClass.class" ) );
    </pre>
	<p/>

	Note: This is all a lie! This command is broken and only reports the
	currently first occurence! To be fixed!
	<p/>

	@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 ) );
}

jEdit/bsh/commands/unset.bsh0100600000175000017500000000060307773210647015331 0ustar  slavaslava/**
	"Undefine" the variable specifed by 'name' (So that it tests == void).
	<p>
	<em>Note: there will be a better way to do this in the future.  This is 
	currently equivalent to doing namespace.setVariable(name, null);</em>
*/

bsh.help.unset = "usage: unset( name )";

void unset( String name ) 
{
	if ( arg == null ) // ???
		return;

	this.caller.namespace.unsetVariable( name );
}
jEdit/bsh/commands/thinBorder.bsh0100600000175000017500000000343107773210647016275 0ustar  slavaslava/** 
 * A one pixel wide bevel border.  This border works for buttons (with optional
 * rollover) and other components
 *
 * @author Daniel Leuck
 */
import javax.swing.border.*;

Insets INSETS = new Insets(1,1,1,1);

public thinBorder() { return thinBorder(null, null, false); }

public thinBorder(Color lightColor, Color darkColor) {
	return thinBorder(lightColor, darkColor, false);	
}

public thinBorder(Color lightColor, Color darkColor, boolean rollOver) {			
			
	/**
	 * Draw a 1 pixel border given a color for topLeft and bottomRight.	
	 */
	drawBorder(g, x, y, width, height, topLeft, bottomRight) {
		Color oldColor = g.color;
		
		g.color=topLeft;
		g.drawLine(x, y, x+width-1, y);
		g.drawLine(x, y, x, y+height-1);
		
		g.color=bottomRight;
		g.drawLine(x+width-1, y, x+width-1, y+height-1);
		g.drawLine(x, y+height-1, x+width-1, y+height-1);		
		
		g.color=oldColor;
	}
		
	public void paintBorder(c, g, x, y, width, height) {	
		Color bgColor = c.background;	
		Color dark = (darkColor==null) ? bgColor.darker().darker() :
				darkColor;
		Color light = (lightColor==null) ? bgColor.brighter() :
				lightColor;			
		
		if(c instanceof AbstractButton) {
			if(c.rolloverEnabled && !c.model.rollover && c.opaque)	{
				drawBorder(g, x, y, width, height, bgColor, bgColor);					
			} else {
				if(c.model.pressed)
					drawBorder(g, x, y, width, height, dark, light);
				else
					drawBorder(g, x, y, width, height, light, dark);
			}
		} else {
			drawBorder(g, x, y, width, height, light, dark);		
		}
	}

	/**
	 * Returns the insets of the border.
	 *
	 * @param c the component for which this border insets value applies
	 */
	public Insets getBorderInsets(Component c) { return INSETS; } 
	
	/**
	 * Always returns false
	 */
	public boolean isBorderOpaque() { return false; }
	
	return this;
}
jEdit/bsh/commands/sourceRelative.bsh0100600000175000017500000000117007773210647017167 0ustar  slavaslava/**
    Source a file relative to the callering script's directory.
	<p/>

    e.g. scripts A running in dir A sources script B in dir B.
	Script B can use this command to load additional scripts (data, etc.)
	relative to its own location (dir B) without having to explicitly know 
	its "home" directory (B).
	<p/>
	Note: this only works for files currently.

    @since bsh1.3
	@see source( file | URL );
*/
sourceRelative( String file )
{
    this.dir=dirname( getSourceFileInfo() );
    this.path=pathToFile( dir + File.separator + file ) .getAbsolutePath();
    return this.interpreter.source( path, this.caller.namespace );
}

jEdit/bsh/commands/source.bsh0100600000175000017500000000130107773210647015467 0ustar  slavaslava/**
	Read filename into the interpreter and evaluate it in the current
	namespace.  Like the Bourne Shell "." command.
	This command acts exactly like the eval() command but reads from a file 
	or URL source.
	@see eval() for more information.
	@throws bsh.EvalError or bsh.TargetError on errors in the sourced script.
*/

bsh.help.source = "usage: source( filename | URL )";

Object source( String filename ) {
	// source with filename preserves file name in error messages
	return this.interpreter.source( filename, this.caller.namespace );
}

Object source( URL url ) {
	return this.interpreter.eval( 
		new InputStreamReader(url.openStream()), this.caller.namespace,  
		"URL: "+url.toString()
	);
}

jEdit/bsh/commands/show.bsh0100600000175000017500000000046107773210647015155 0ustar  slavaslava/**
	Toggle on or off displaying the results of expressions (off by default).
	When show mode is on bsh will print() the value returned by each expression 
	you type on the command line.
*/

bsh.help.show = "usage: show()";

show() {
	if ( bsh.show == void )
		bsh.show = false;

	bsh.show = !bsh.show;
}
jEdit/bsh/commands/setStrictJava.bsh0100600000175000017500000000136307773210647016765 0ustar  slavaslava/**
	Enable or disable "Strict Java Mode".
	When strict Java mode is enabled BeanShell will:
	<p>

	<ol>
	<li>Require typed variable declarations, method arguments and return types.
	<li>Modify the scoping of variables to look for the variable
	declaration first in the parent namespace, as in a java method inside 
	a java class.  e.g. if you can write a method called incrementFoo() that 
	will do the expected thing without referring to "super.foo".
	</ul>
	<p/>

	See "Strict Java Mode" for more details.
	<p/>

	<em>Note: Currently most standard BeanShell commands will not work in 
	Strict Java mode simply because they have not been written with full
	types, etc.
*/

void setStrictJava( boolean val ) 
{
	this.interpreter.setStrictJava( val );
}

jEdit/bsh/commands/setNameSpace.bsh0100600000175000017500000000161107773210647016543 0ustar  slavaslava/**
	Set the namespace (context) of the current scope.
	<p/>

	The following example illustrates swapping the current namespace.
	<p/>

	<pre>
    fooState = object(); 
    barState = object(); 
    
    print(this.namespace);
    setNameSpace(fooState.namespace);
    print(this.namespace);
    a=5;
    setNameSpace(barState.namespace);
    print(this.namespace);
    a=6;
    
    setNameSpace(fooState.namespace);
    print(this.namespace);
    print(a);  // 5
    
    setNameSpace(barState.namespace);
    print(this.namespace);
    print(a); // 6
    </pre>
	<p/>

	You could use this to creates the effect of a static namespace for a
	method by explicitly setting the namespace upon entry.
	<p/>
*/

bsh.help.setNameSpace =
	"usage: setNameSpace( bsh.NameSpace )";

setNameSpace( ns ) 
{
	// Set the namespace at depth one (our caller) to the specified namespace.
	this.callstack.set( 1, ns );
}

jEdit/bsh/commands/setNameCompletion.bsh0100600000175000017500000000115207773210647017621 0ustar  slavaslava/**
	Allow users to turn off name completion.
	<p>
	Turn name completion in the GUI console on or off.
	Name competion is on by default.  Explicitly setting it to true however can
	be used to prompt bsh to read the classpath and provide immediate feedback.
	(Otherwise this may happen behind the scenes the first time name completion
	is attempted).  Setting it to false will disable name completion.
*/

bsh.help.setNameCompletion= "usage: setNameCompletion( boolean )";

/**
*/
void setNameCompletion( boolean bool ) 
{
	if ( bool == false )
		if ( bsh.console != void )
			bsh.console.setNameCompletion( null );
}

jEdit/bsh/commands/setFont.bsh0100600000175000017500000000121707773210647015617 0ustar  slavaslava/**
	Change the point size of the font on the specified component, to ptsize.
	This is just a convenience for playing with GUI components.
*/

bsh.help.setFont = "usage: setFont( Component comp, int size )";

Font setFont(Component comp, String family, int style, int size) {
		
    this.font = comp.getFont();
	
    this.family = (family==null) ? font.family : family;
    this.style = (style==-1) ? font.style : style;
	this.size = (size==-1) ? font.size : size;
	
    font = new Font(family, style, size);
    comp.setFont(font);
	comp.validate();
    return font;	
}

Font setFont(Component comp, int size) {
	return setFont(comp, null, -1, size);
}

jEdit/bsh/commands/setClassPath.bsh0100600000175000017500000000050107773210647016566 0ustar  slavaslava/**
	Change the classpath to the specified array of directories and/or archives.
	<p>
	See "Class Path Management" for details.

	@method void setClassPath( URL [] )
*/

bsh.help.setClassPath= "usage: setClassPath( URL [] )";

void setClassPath( urls ) {
	this.caller.namespace.getClassManager().setClassPath( urls );
}

jEdit/bsh/commands/setAccessibility.bsh0100600000175000017500000000027607773210647017504 0ustar  slavaslava/**
	Setting accessibility on enables to private and other non-public
	fields and method.
*/
import bsh.Capabilities;

setAccessibility( boolean b ) 
{
	Capabilities.setAccessibility(b);
}

jEdit/bsh/commands/server.bsh0100600000175000017500000000067107773210647015506 0ustar  slavaslava/**
	Create a remote BeanShell listener service attached to 
	the current interpreter, listening on the specified port.
*/
import bsh.util.Httpd;
import bsh.util.Sessiond;

bsh.help.server = "usage: server(int port)";

void server(int port ) {
	new Thread( new Httpd( port ) ).start();
	print("Httpd started on port: "+port);
	new Thread( new Sessiond( global.namespace, port+1 ) ).start();
	print("Sessiond started on port: "+ (port+1));
}
jEdit/bsh/commands/save.bsh0100600000175000017500000000151707773210647015136 0ustar  slavaslava/**
	Save a serializable Java object to filename. 
*/

bsh.help.save = "usage: save( object, filename )";

void save( Object obj, String filename ) 
{
	File file = pathToFile( filename );

	if ( !(obj instanceof Serializable) ) {
		print("Type "+obj.getClass()+" is not serializable");
		return;
	}

	// Detach bsh objects from the caller's namespace during serialization
	// NOTE: THIS IS NOT THREAD SAFE
	if ( obj instanceof bsh.This ) {
		super.parent = obj.namespace.getParent();
		obj.namespace.prune();
	}
	
	OutputStream out = new FileOutputStream( file );
	ObjectOutputStream oout = new ObjectOutputStream(out);
	oout.writeObject( obj );
	oout.close();

	// Reattach bsh objects to the caller's namespace after serialization
	// NOTE: THIS IS NOT THREAD SAFE
	if ( obj instanceof bsh.This ) 
		obj.namespace.setParent( super.parent );
}


jEdit/bsh/commands/run.bsh0100600000175000017500000000420007773210647014774 0ustar  slavaslava/**
	Run a command in its own in its own private global namespace, with its
	own class manager and interpeter context.  (kind of like unix "chroot" for 
	a namespace).
	The root bsh system object is extended (with the extend() command) and 
	made visible here, so that general system info (e.g. current working
	directory) is effectively inherited.  Because the root bsh object is 
	extended it is effectively read only / copy on write...  
	e.g. you can change directories in the child context, do imports, change
	the classpath, etc. and it will not affect the calling context.
	<p>

	run() is like source() except that it runs the command in a new, 
	subordinate and prune()'d namespace.  So it's like "running" a command 
	instead of "sourcing" it.  run() teturns the object context in which the 
	command was run.
	<p>

	Returns the object context so that you can gather results.
	<p>
	Parameter runArgument an argument passed to the child context under the
		name runArgument.  e.g. you might pass in the calling This context
		from which to draw variables, etc.
	<p>

	@return Returns the object context so that you can gather results.
	@param runArgument an argument passed to the child context under the
		name runArgument.  e.g. you might pass in the calling This context
		from which to draw variables, etc.
*/

bsh.help.run= "usage: Thread run( filename )";

run( String filename, Object runArgument ) 
{
	// Our local namespace is going to be the new root (global)
	// make local copies of the system stuff.
	//
	// Extend the root system object
	// this is problematic...  probably need more here...
	this.bsh=extend(global.bsh); 
	this.bsh.help=extend(bsh.help);

	// save the classpath before pruning
	this.cp = this.caller.namespace.getClassManager()
		.getClassPath().getUserClassPathComponents();

	// Cut us off... make us the root (global) namespace for this command
	// Prune() will also create a new class manager for us.
	this.namespace.prune();

	// Inherit user classpath 
	this.namespace.getClassManager().setClassPath( cp );

	this.interpreter.source( filename, this.namespace );
	return this;
}

run( String filename ) {
	run( filename, null );
}
jEdit/bsh/commands/rm.bsh0100600000175000017500000000054107773210647014612 0ustar  slavaslava/**
	Remove a file (like Unix rm).
*/

bsh.help.rm = "usage: cd( path )";

boolean rm( String pathname ) 
{
    this.file = pathToFile( pathname );

	if ( file == null )
		throw new java.io.FileNotFoundException("pathname");

    if ( file.isDirectory() ) {
        print( pathname + "is a directory" );
        return;
    }

	return file.delete();
}

jEdit/bsh/commands/reloadClasses.bsh0100600000175000017500000000213107773210647016755 0ustar  slavaslava/**
	Reload the specified class, package name, or all classes if no name is 
	given.  e.g.
	<p>

	<pre>
    reloadClasses();
    reloadClasses("mypackage.*");
    reloadClasses(".*")  // reload unpackaged classes
    reloadClasses("mypackage.MyClass") 
	</pre>
	<p>

	See "Class Path Management"

	@method void reloadClasses( [ package name ] )
*/

bsh.help.reloadClasses= 
	"usage: reloadClasses( String class | String package | String [] classes )";

import bsh.ClassPathException;

void reloadClasses( item ) 
{
	this.bcm = this.caller.namespace.getClassManager();

	try {
		if ( item instanceof String [] )
			bcm.reloadClasses( item );
		else {
			this.name = item;

			if ( name.endsWith(".*" ) ) {
				if ( name.equals(".*" ) )
					this.pack = "<unpackaged>";
				else
					this.pack = name.substring( 0, name.length()-2 );
				
				bcm.reloadPackage( pack );
			} else
				bcm.reloadClasses( new String[] { name } );
		}
	} catch ( ClassPathException e ) {
		error( e.getMessage() );
	}
}

/**
	Reload all classes
*/
void reloadClasses() 
{
	this.caller.namespace.getClassManager().reloadAllClasses();
}
jEdit/bsh/commands/pwd.bsh0100600000175000017500000000021207773210647014761 0ustar  slavaslava/**
	Print the BeanShell working directory.  This is the cwd obeyed by all the 
	unix-like bsh commands.
*/
pwd() {
	print( bsh.cwd );
}

jEdit/bsh/commands/printBanner.bsh0100600000175000017500000000154307773210647016461 0ustar  slavaslava/**
	Print the BeanShell banner (version and author line) - GUI or non GUI.

	@author Daniel Leuck
*/

import javax.swing.ImageIcon;
import java.awt.*;
import bsh.Interpreter;
import bsh.Capabilities;
import bsh.util.JConsole;

/*
	Note: any errors thrown in here will be caught by interpreter and
	ignored... printing the default message.
*/
printBanner() 
{
	if ( bsh.console != void 
		&& Capabilities.haveSwing() 
		&& (bsh.console instanceof JConsole) ) 
	{

	    this.jconsole = bsh.console;
	    jconsole.println( 
			new ImageIcon( getResource("/bsh/util/lib/small_bean_shell.gif")) );
	    jconsole.print(
			Interpreter.VERSION + " - by Pat Niemeyer (pat@pat.net)",
			new Font("SansSerif", Font.BOLD, 12), 
			new Color(20,100,20) );
	    jconsole.println();

	} else
		print( "BeanShell "
			+ Interpreter.VERSION +" - by Pat Niemeyer (pat@pat.net)");

}
jEdit/bsh/commands/print.bsh0100600000175000017500000000273407773210647015336 0ustar  slavaslava/**
	Print the string value of the argument, which may be of any type.
	If beanshell is running interactively, the output will always go to the 
	command line, otherwise it will go to System.out.
	<p>

	Most often the printed value of an object will simply be the Java 
	toString() of the object.  However if the argument is an array the contents 
	of the array will be (recursively) listed in a verbose way.
	<p>

	Note that you are always free to use System.out.println() 
	instead of print().
*/
bsh.help.print = "usage: print( value )";
import bsh.CollectionManager;
import bsh.StringUtil;
import bsh.Primitive;

void print( arg ) 
{
	if ( arg == null )
		arg = "null";
	
	if ( !(arg instanceof Primitive) 
		&& !(arg instanceof bsh.ClassIdentifier ) 
		&& arg.getClass().isArray() )
	{
        print( StringUtil.normalizeClassName(arg.getClass()) + ": {");
		for(int i=0; i<arg.length; i++)
			print( arg[i] + (i<arg.length?",":"") );
		print("}");
	}
	else
		this.interpreter.println(String.valueOf(arg));

/*
Do we want to iterate over iterable things?
Most of the them already know how to print themselves.

	this.cm = CollectionManager.getCollectionManager();
	if ( cm.isBshIterable( arg ) )
	{
		// could also just use a for(:) loop here... except for the commas
		this.iterator = cm.getBshIterator( arg );
        print( StringUtil.normalizeClassName(arg.getClass()) + ": {");
		while( iterator.hasNext() )
			print( iterator.next() + (iterator.hasNext()?",":"") );
		print("}");
	}
*/
}

jEdit/bsh/commands/pathToFile.bsh0100600000175000017500000000044107773210647016232 0ustar  slavaslava/**
	Create a File object corresponding to the specified file path name, taking
	into account the bsh current working directory (bsh.cwd)
*/

bsh.help.pathToFile = "usage: File pathToFile( String )";

File pathToFile( String filename ) {
	return this.interpreter.pathToFile( filename );
}
jEdit/bsh/commands/object.bsh0100600000175000017500000000043307773210647015442 0ustar  slavaslava/**
	Return an "empty" BeanShell object context which can be used to hold 
	data items.  e.g. 
	<p>
	<pre>
    myStuff = object();
    myStuff.foo = 42;
    myStuff.bar = "blah";
	</pre>

	@method This object()
*/

bsh.help.object = "usage: object()";

object() { 
	return this; 
}

jEdit/bsh/commands/mv.bsh0100600000175000017500000000034407773210647014617 0ustar  slavaslava/**
	Rename a file (like Unix mv).
*/

bsh.help.mv = "usage: mv( fromFile, toFile )";

mv( String fromFile, String toFile ) 
{
    this.from = pathToFile( fromFile );
    this.to = pathToFile( toFile );
	from.renameTo( to );
}

jEdit/bsh/commands/makeWorkspace.bsh0100600000175000017500000000626107773210647016775 0ustar  slavaslava/**
 * Creates a JConsole in a JInternalFrame and adds it to the desktop 
 *
 * @return this (the workspace scripted object for allowing access to the 
 *          frame, interpreter, etc.)
 *
 * @author Pat Niemeyer
 * @author Daniel Leuck (bug fixes)
 */

import javax.swing.*;
import bsh.Interpreter;
import bsh.BshClassManager;
import bsh.util.JConsole;
import bsh.util.NameCompletionTable;

makeWorkspace( String name ) 
{
	if ( bsh.system.desktop == void ) {
		print("No desktop...");
		return;
	}

	this.console = new JConsole();
	this.name="Bsh Workspace: "+name;

	this.interpreter = new Interpreter( console );

	// provide name completion for console, name source is global namespace
	// move this into JConsole?

	this.nct = new NameCompletionTable();
	nct.add( interpreter.getNameSpace() );
	try {
		this.bcm = this.caller.namespace.getClassManager();
		if ( bcm != null ) {
			classNamesSource = bcm.getClassPath();
			nct.add( classNamesSource );
		}
	} catch ( ClassPathException e ) {
		error("classpath exception in name compl:"+e);
	}
	console.setNameCompletion( nct );
	// end setup name completion

	// for convenience and backwards compatability
	interpreter.set( "bsh.desktop",  bsh.system.desktop );

	this.frame = bsh.system.desktop.makeInternalFrame( name );
	frame.frameIcon=bsh.system.icons.workspace;
	
	/*
		Notes: Careful not to print anything before returning sys io...
		console is now gone.
	*/
	internalFrameClosing( e ) {
		if ( haveSysIO )
			returnSysIO();
	}
	internalFrameActivated(ife) {}
	internalFrameDeactivated(ife) {}
	internalFrameClosed(ife) {}
	internalFrameOpened(ife) {}
	internalFrameIconified(ife) {}
	internalFrameDeiconified(ife) {}	
	
	frame.addInternalFrameListener(this);

	actionPerformed( e ) 
	{
		this.com = e.getActionCommand();
		if ( com.equals("Workspace Editor") )
			workspaceEditor( interpreter, name );
		else if ( com.equals("Capture System in/out/err") )
			captureSysIO();
		else if	( com.equals("Close") )	{
			frame.setClosed(true);
		}
	}

	this.menubar = new JMenuBar();
	this.menu=new JMenu("File");
	this.mi=new JMenuItem("Workspace Editor");
	mi.addActionListener(this);
	menu.add(mi);
	mi=new JMenuItem("Capture System in/out/err");
	mi.addActionListener(this);
	menu.add(mi);
	mi=new JMenuItem("Close");
	mi.addActionListener(this);
	menu.add(mi);
	menubar.add(menu);

	menu = fontMenu(console);
	menubar.add(menu);

	frame.setMenuBar(menubar);

	frame.getContentPane().add("Center", console);
	//frame.pack();
	this.thread = new Thread( interpreter );
	thread.start();

	frame.setBounds(5,5,600,300);
	// cascade windows?
	//off=bsh.system.desktop.windowCount*10;
	//frame.setLocation( off, off );
	//frame.validate();
	bsh.system.desktop.addInternalFrame( frame	);
	frame.toFront();
	frame.setSelected(true);

	this.haveSysIO=false;
	this.sysIn = System.in;
	this.sysOut = System.out;
	this.sysErr = System.err;

	captureSysIO() {
		super.haveSysIO = true; // old scoping rules
		System.setIn( console.getInputStream() );
		System.setOut( console.getOut() );
		System.setErr( console.getErr() );
	}

	returnSysIO() {
		super.haveSysIO = false; // old scoping rules
		System.setIn( sysIn );
		System.setOut( sysOut );
		System.setErr( sysErr );
	}

	return this;
}

jEdit/bsh/commands/load.bsh0100600000175000017500000000074007773210647015114 0ustar  slavaslava/**
	Load a serialized Java object from filename.  Returns the object.
*/

bsh.help.load = "usage: load(filename)";

Object load( String filename ) 
{
	this.file = pathToFile( filename );

	Object obj;
	FileInputStream in = new FileInputStream( file );
	ObjectInputStream oin = new ObjectInputStream(in);
	obj = oin.readObject();
	oin.close();

	// bind bsh objects into the caller's namespace
	if ( obj instanceof bsh.This )
		bind( obj, this.caller.namespace );

	return obj;
}
jEdit/bsh/commands/javap.bsh0100600000175000017500000000325707773210647015304 0ustar  slavaslava/**
	Print the public fields and methods of the specified class (output similar 
	to the JDK javap command).
	<p/>
	If the argument is a string it is considered to be a class name.  If the
	argument is an object, the class of the object is used.  If the arg is a
	class, the class is used.  If the argument is a class identifier, the class
	identified by the class identifier will be used. e.g.  If the argument is
	the empty string an error will be printed.
	<p/>
	<pre>
	// equivalent
	javap( java.util.Date ); // class identifier
	javap( java.util.Date.class ); // class
	javap( "java.util.Date" ); // String name of class
	javap( new java.util.Date() ); // instance of class
	</pre>

	@method void javap( String | Object | Class | ClassIdentifier )
*/

bsh.help.javap= "usage: javap( value )";

import bsh.ClassIdentifier;
import java.lang.reflect.Modifier;

javap( Object o ) 
{
	Class clas;
	if ( o instanceof ClassIdentifier )
		clas = this.caller.namespace.identifierToClass(o);
	else if ( o instanceof String )
	{
		if ( o.length() < 1 ) {
			error("javap: Empty class name.");
			return;
		}
		clas = this.caller.namespace.getClass((String)o);
	} else if ( o instanceof Class )
		clas = o;
	else 
		clas = o.getClass();
	
	print( "Class "+clas+" extends " +clas.getSuperclass() );

	methods=clas.getDeclaredMethods();
	//print("------------- Methods ----------------");
	for(int i=0; i<methods.length; i++) {
		m = methods[i];
		if ( Modifier.isPublic( m.getModifiers() ) )
			print( m );
	}

	//print("------------- Fields ----------------");
	fields=clas.getDeclaredFields();
	for(int i=0; i<fields.length; i++) {
		f = fields[i];
		if ( Modifier.isPublic( f.getModifiers() ) )
			print( f );
	}
}

jEdit/bsh/commands/importObject.bsh0100600000175000017500000000103707773210647016636 0ustar  slavaslava/**
    Import an instance object into this namespace
    (analogous to static class imports).
    You can import the methods and fields of a Java object instance into
    a BeanShell namespace.  e.g.

    <pre>
        Map map = new HashMap();
        importObject( map );
        put("foo", "bar");
        print( get("foo") ); // "bar"
    </pre>

    @method void importObject( Object object )
*/

bsh.help.importObject = "usage: importObject( Object )";

importObject( Object object ) 
{
	this.caller.namespace.importObject( object );
}

jEdit/bsh/commands/importCommands.bsh0100600000175000017500000000203307773210647017166 0ustar  slavaslava/**
	Import scripted or compiled BeanShell commands in the following package
	in the classpath.  You may use either "/" path or "." package notation.
	e.g. 
	<pre>
		// equivalent
		importCommands("/bsh/commands")
		importCommands("bsh.commands")
	<pre>

	When searching for a command each path will be checked for first, a file
	named 'command'.bsh and second a class file named 'command'.class.
	<p/>

	You may add to the BeanShell classpath using the addClassPath() or
	setClassPath() commands and then import them as usual.
	<pre>
		addClassPath("mycommands.jar");
		importCommands("/mypackage/commands");
	</pre>
	<p/>

	If a relative path style specifier is used then it is made into an absolute
	path by prepending "/".  Later imports take precedence over earlier ones.
	<p/>

	Imported commands are scoped just like imported clases.
	<p/>

	@method void importCommands( resource path | package name )
*/

bsh.help.importCommands = "usage: importCommands( string )";

importCommands( path ) 
{
	this.caller.namespace.importCommands( path );
}

jEdit/bsh/commands/getSourceFileInfo.bsh0100600000175000017500000000222407773210647017550 0ustar  slavaslava/**
	Return the name of the file or source from which the current interpreter
	is reading.  Note that if you use this within a method, the result will
	not be the file from which the method was sourced, but will be the file 
	that the caller of the method is reading.   Methods are sourced once but
	can be called many times... Each time the interpreter may be associated
	with a different file and it is that calling interpreter that you are
	asking for information.
	<p>

	Note: although it may seems like this command would always return the
	getSourceFileInfo.bsh file, it does not since it is being executed after
	sourcing by the caller's interpreter.
	If one wanted to know the file from which a bsh method was sourced one
	would have to either capture that info when the file was sourced (by
	saving the state of the getSourceFileInfo() in a variable outside of
	the method or more generally we could add the info to the BshMethod class
	so that bsh methods remember from what source they were created...
*/

bsh.help.getSourceFileInfo = "usage: getSourceFileInfo()";

import bsh.Interpreter;

getSourceFileInfo() {
	return this.interpreter.getSourceFileInfo();
}
jEdit/bsh/commands/getResource.bsh0100600000175000017500000000054107773210647016463 0ustar  slavaslava/**
	Get a resource from the BeanShell classpath.
	This method takes into account modification to the BeanShell class path via
	addClassPath() and setClassPath();
*/

bsh.help.getResource = "usage: getResource( String name )";

import bsh.Interpreter;

URL getResource( String path ) 
{
	return this.interpreter.getClassManager().getResource( path );
}
jEdit/bsh/commands/getClassPath.bsh0100600000175000017500000000050507773210647016556 0ustar  slavaslava/**
    Get the current classpath including all user path, extended path, and the
    bootstrap JAR file if possible.
*/

bsh.help.getClassPath= "usage: getClassPath()";
import bsh.BshClassManager;

URL [] getClassPath() {
	this.cp = this.caller.namespace.getClassManager().getClassPath();
	return cp.getPathComponents();
}

jEdit/bsh/commands/getClass.bsh0100600000175000017500000000120107773210647015733 0ustar  slavaslava/**
	Get a class through the current namespace utilizing the current imports,
	extended classloader, etc.
	<p>

	This is equivalent to the standard Class.forName() method for class loading,
	however it takes advantage of the BeanShell class manager so that added 
	classpath will be taken into account.  You can also use Class.forName(), 
	however if you have modified the classpath or reloaded classes from within 
	your script the modifications will only appear if you use the getClass() 
	command.
*/
bsh.help.getClass= "usage: getClass( String name )";

Class getClass( String name ) {
	return this.caller.namespace.getClass( name );
}

jEdit/bsh/commands/getBshPrompt.bsh0100600000175000017500000000102407773210647016607 0ustar  slavaslava/**
	Get the value to display for the bsh interactive prompt.
	This command checks for the variable bsh.prompt and uses it if set.
	else returns "bsh % "
	<p/>
	Remember that you can override bsh commands simply by defining the method
	in your namespace. e.g. the following method displays the current working
	directory in your prompt:
	<p/>
	<pre>
	String getBshPrompt() {
		return bsh.cwd + " % ";
	}
	</pre>
*/

String getBshPrompt() 
{
	if ( bsh != void && bsh.prompt != void )
		return bsh.prompt;
	else
		return "bsh % ";
}

jEdit/bsh/commands/frame.bsh0100600000175000017500000000267207773210647015275 0ustar  slavaslava/**
    Show component in a frame, centered and packed, handling disposal with
	the close button.
	<p>

	Display the component, centered and packed, in a Frame, JFrame, or 
	JInternalFrame.  Returns the frame.  If the GUI desktop is running then a 
	JInternaFrame will be used and automatically added to the desktop.  
	Otherwise if Swing is available a top level JFrame will be created.  
	Otherwise a plain AWT Frame will be created.

	@method Frame | JFrame | JInternalFrame frame( Component component )

*/
bsh.help.frame = "usage: frame( Component component )";
 
import java.awt.*;
import bsh.Capabilities;

frame( Component comp ) 
{
	// Ignore unhandled method invocations from listeners.
	invoke( method, args ) { }

    windowClosing( event ) {
        frame.dispose();
    }

	// if the desktop is there make an internal frame
	if ( bsh.system.desktop != void ) {
		this.frame = bsh.system.desktop.makeInternalFrame("frame");
		frame.setClosable(true);
		frame.getContentPane().add( comp, "Center" );
    	frame.pack();  // must pack before adding to desktop?
		bsh.system.desktop.addInternalFrame( frame );
	} else {
		// make an external JFrame or Frame
		if ( Capabilities.haveSwing() ) {
			this.frame = new javax.swing.JFrame();
			frame.getContentPane().add( comp, "Center" );
		} else {
			this.frame = new Frame();
			frame.add( comp, "Center" );
		}

		frame.addWindowListener(this);
    	frame.pack();
	}

    frame.show();
    return frame;
}

jEdit/bsh/commands/fontMenu.bsh0100600000175000017500000000363407773210647015775 0ustar  slavaslava/**
 * Creates a font menu for use with the workspace and workspace editors
 *
 * @return a font menu
 *
 * @author Daniel Leuck
 */
fontMenu(component) {
	if ( bsh.system.desktop == void ) {
		print("fontMenu() only works with the bsh desktop...");
		return;
	}
	
	JMenu fontMenu = new JMenu("Font");
	
	sizeListener() {
		actionPerformed(ae) {
			setFont(component, Integer.parseInt(ae.actionCommand));
		}
	
		return this;	
	}
	this.sizeListener=sizeListener();
	
	
	this.boldMenuItem = new JCheckBoxMenuItem("Bold");
	this.italicMenuItem = new JCheckBoxMenuItem("Italic");
	
	styleListener() {
		actionPerformed(ae) {
			setFont(component, null, ((boldMenuItem.selected) ? Font.BOLD : 0) |
				((italicMenuItem.selected) ? Font.ITALIC : 0), -1);
		}
	
		return this;	
	}
	this.styleListener=styleListener();
	
	familyListener() {
		actionPerformed(ae) {
			setFont(component, ae.actionCommand, -1, -1);
		}
	
		return this;	
	}
	this.familyListener=familyListener();	
	
	JMenu sizeMenu = new JMenu("Size");
	for(int i:new int[] {9,10,12,14,16,20,24})
		sizeMenu.add(new JMenuItem(""+i)).addActionListener(sizeListener);
	fontMenu.add(sizeMenu);
	
	JMenu styleMenu = new JMenu("Style");
	//styleMenu.add(new JMenuItem("Plain")).addActionListener(this);
	styleMenu.add(boldMenuItem).addActionListener(styleListener);
	styleMenu.add(italicMenuItem).addActionListener(styleListener);
	fontMenu.add(styleMenu);
	
	fontMenu.addSeparator();
	
	for(var s:new String[] {"SansSerif","Monospaced","Serif","LucidaSans"})
		fontMenu.add(this.mi=new JMenuItem(s)).addActionListener(familyListener);
	
	fontMenu.addSeparator();
	
	actionPerformed(ae) {
		String family = (String)JOptionPane.showInputDialog(component,
			"Select a font", "Fonts", JOptionPane.QUESTION_MESSAGE,
				null, bsh.system.fonts, component.font.family);
		setFont(component, family, -1, -1);
	}
	
	fontMenu.add(new JMenuItem("More...")).addActionListener(this);
	
	return fontMenu;
}
jEdit/bsh/commands/extend.bsh0100600000175000017500000000176407773210647015473 0ustar  slavaslava/**
	Return a new object that is a child of the specified object.
	<strong>
	Note: this command will likely change along with a better inheritance 
	mechanism for bsh in a future release.</strong>
	<p>

	extend() is like the object() command, which
	creates a new bsh scripted object, except that the namespace of
	the new object is a child of the parent object. 
	<p>

	For example:
	<p>

    <pre>
    foo=object();
    bar=extend(foo);

    is equivalent to:
      
    foo() { 
        bar() {
            return this; 
        }
    }

    foo=foo();
    bar=foo.bar();

    and also:
     
    oo=object();
    ar=object();
    ar.namespace.bind( foo.namespace );
    </pre>
	<p>

	The last example above is exactly what the extend() command does.
	In each case the bar object inherits variables from foo in the usual way.

	@method This extend( This object )
*/
bsh.help.extend= "usage: extend( This parent )";
extend( bsh.This parent ) 
{
	this.namespace.setParent( parent.namespace );
	return this; 
}

jEdit/bsh/commands/exit.bsh0100600000175000017500000000037707773210647015154 0ustar  slavaslava/**
	Conditionally exit the virtual machine.
	Call System.exit(0) unless bsh.system.shutdownOnExit == false.
*/

bsh.help.exit = "usage: exit()";

exit() {
	// shutdown Java VM unless flagged
	if ( bsh.system.shutdownOnExit != false )
		System.exit(0);
}
jEdit/bsh/commands/exec.bsh0100600000175000017500000000056507773210647015126 0ustar  slavaslava/**
	Start an external application using the Java Runtime exec() method.
	Display any output to the standard BeanShell output using print().
*/

bsh.help.exec = "usage: exec( String arg )";

exec( String arg ) 
{
	this.proc = Runtime.getRuntime().exec(arg);
	this.din = new DataInputStream( proc.getInputStream() );
	while( (line=din.readLine()) != null )
		print(line);
}
jEdit/bsh/commands/eval.bsh0100600000175000017500000000354207773210647015127 0ustar  slavaslava/**
	Evaluate the string in the current interpreter (see source()).
	Returns the result of the evaluation or null.
	<p>

	Evaluate a string as if it were written directly in the current scope, 
	with side effects in the current scope.
	<p>
	e.g.
    <code><pre>
    a=5;
    eval("b=a*2");
    print(b); // 10
    </pre></code>
	<p>

	eval() acts just like invoked text except that any exceptions generated
	by the code are captured in a bsh.EvalError.  This includes ParseException
	for syntactic errors and TargetError for exceptions thrown by the evaluated
	code.
	<p>
	e.g.
    <pre>
    try {
        eval("foo>>><>M>JK$LJLK$");
    } catch ( EvalError e ) {
        // ParseException caught here
    }

    try {
        eval("(Integer)true");  // illegal cast
    } catch ( EvalError e ) {
        // TargetException caught here
        print( e.getTarget() )  // prints ClassCastException
    }
    </pre>
	<p>
	
	If you want eval() to throw target exceptions directly, without wrapping
	them, you can simply redefine own eval like so:

    <pre>
    myEval( String expression ) {
        try {
            return eval( expression );
        } catch ( TargetError e ) {
            throw e.getTarget();
        }
    }
    </pre>
	<p/>

	Here is a cute example of how to use eval to implement a dynamic cast.  
	i.e. to cast a script to an arbitrary type by name at run-time where the
	type is not known when you are writing the script.  In this case the type
	is in the variable interfaceType.
	<pre>
    reference = eval( "("+interfaceType+")this" );
	</pre>

	<p>
	Returns the value of the expression.
	<p>
	Throws bsh.EvalError on error
	<p>
	@return the value of the expression.
	@throws bsh.EvalError on error
*/

bsh.help.eval = "usage: eval( String expression )";

Object eval( String expression ) {
    return this.interpreter.eval( expression, this.caller.namespace );
}

jEdit/bsh/commands/error.bsh0100600000175000017500000000034007773210647015322 0ustar  slavaslava/**
	Print the item as an error.  
	In the GUI console the text will show up in (something like) red, 
	else it will be printed to standard error.
*/

void error( item ) {
	this.interpreter.error( String.valueOf(item) );
}

jEdit/bsh/commands/editor.bsh0100600000175000017500000000177507773210647015474 0ustar  slavaslava/**
	Open a GUI editor from the command line or in the GUI desktop mode.
	When run from the command line the editor is a simple standalone
	frame.  When run inside the GUI desktop it is a workspace editor.
	See workspaceEditor()
*/

bsh.help.editor = "usage: editor()";
import java.awt.*;

editor() 
{
	if ( bsh.system.desktop != void ) {
		return workspaceEditor( this.interpreter );
	}

	this.ta = new TextArea(15,40);
	this.frame = new Frame("Editor");
	frame.add(ta, "Center");

	this.p = new Panel();
	this.b = new Button("Eval");
	b.addActionListener(this);
	p.add(b);
	b = new Button("Clear");
	b.addActionListener(this);
	p.add(b);
	b = new Button("Close");
	b.addActionListener(this);
	p.add(b);

	frame.add(p, "South");
	frame.pack();
	frame.show();

	actionPerformed(e) 
	{
		if ( e.getActionCommand().equals("Close") )
			frame.dispose();
		else if ( e.getActionCommand().equals("Clear") )
			ta.setText("");
		else
			this.interpreter.eval( ta.getText() );
	}

	print("Editor started...");
	return frame;
}

jEdit/bsh/commands/dirname.bsh0100600000175000017500000000150507773210647015614 0ustar  slavaslava/**
	Return directory portion of path based on the system default file separator.
	Note: you should probably use pathToFile() to localize the path relative
	to BeanShell's working directory and then file.getAbsolutePath() to get
	back to a system localized string.
	<p>
	
	Example: to change to the directory that contains the script we're 
	currently executing:

	<pre>
	// Change to the directory containing this script
	path=pathToFile( getSourceFileInfo() ).getAbsolutePath();
	cd( dirname( path ) );
	</pre>
*/

bsh.help.cd = "usage: dirname( path )";

String dirname( String pathname ) 
{
	String dirName = ".";
	// Normalize '/' to local file separator before work.
	int i = pathname.replace('/', File.separatorChar ).lastIndexOf( 
		File.separator );
    if ( i != -1 )
		dirName = pathname.substring(0, i);

	return dirName;
}

jEdit/bsh/commands/desktop.bsh0100600000175000017500000001200307773210647015641 0ustar  slavaslava/**
 * Start the BeanShell GUI desktop in a JFrame.  A starter workspace is created
 * and added to the desktop.
 *
 * @method void desktop()
 *
 * @author Pat Niemeyer
 * @author Daniel Leuck
 */
 
import javax.swing.*;
import javax.swing.border.*;
import bsh.util.JConsole;
import bsh.util.Util;
import bsh.Interpreter;
import java.awt.Component;
import bsh.Capabilities;

desktop() 
{
		
	// need a way to set things to void again
	if ( bsh.system.desktop != void ) {
		print("There is	already	a desktop running...");
		return;
	} else
		bsh.system.desktop = this;   // race condition (hah!)

	bsh.system.icons=object();
	
	bsh.system.icons.bean=
		new ImageIcon(getResource("/bsh/util/lib/icon.gif"));
	bsh.system.icons.workspace=
		new ImageIcon(getResource("/bsh/util/lib/workspace.gif"));	
	bsh.system.icons.script=
		new ImageIcon(getResource("/bsh/util/lib/script.gif"));
	bsh.system.icons.eye=
		new ImageIcon(getResource("/bsh/util/lib/eye.jpg"));		
		
	bsh.system.fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().
		getAvailableFontFamilyNames();		
		
	JPanel stage=new JPanel(new BorderLayout());
	JPanel taskBar=new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 1));
	taskBar.setBorder(new MatteBorder(1,0,0,0, taskBar.background.darker()));
	ButtonGroup taskBarButtonGroup = new ButtonGroup();
	
	// Ignore unhandled method invocations from listeners.
	invoke( method, args ) { }

	makeInternalFrame( String name ) 
	{
		// Closable by default
		this.frame = new JInternalFrame( name, true, true, true, true );
		frame.frameIcon=bsh.system.icons.bean;
		frame.visible=true;
		return frame;
	}

	this.frameMap=new Hashtable();
	taskBarButtonListener() {
		actionPerformed(ae) {
			this.iframe=frameMap.get(ae.source);
			if(iframe.icon)
				iframe.icon=false;
			if(iframe!=null && !iframe.selected)
				iframe.selected=true;
		}
		
		return this;
	}
	this.taskBarButtonListener=taskBarButtonListener();
	
	addInternalFrame( frame ) 
	{
		iframeListener=new InternalFrameListener() {
			
			internalFrameClosing(ife) {
				for(e:new Hashtable(frameMap).entrySet()) {
					if(e.value.equals(ife.source)) {
						taskBar.remove(e.key);
						taskBarButtonGroup.remove(e.key);
						frameMap.remove(e.key);
						taskBar.validate();
						taskBar.repaint();
					}
				}
			}
			
			internalFrameActivated(ife) {
				for(e:frameMap.entrySet()) if(e.value.equals(ife.source)) {
					if(!e.key.selected) e.key.selected=true;
				}
			}
			
			internalFrameDeactivated(ife) {}
			internalFrameClosed(ife) {}
			internalFrameOpened(ife) {}
			internalFrameIconified(ife) {}
			internalFrameDeiconified(ife) {}
		};
		
		bsh.system.desktop.pane.add( frame	);
		frame.addInternalFrameListener(iframeListener);
		JToggleButton button = new JToggleButton(frame.title, frame.frameIcon);
		taskBarButtonGroup.add(button);
		button.border=new CompoundBorder((Border)thinBorder(),
			new EmptyBorder(2,2,2,3));
		button.addActionListener(taskBarButtonListener);
		taskBar.add(button);
		taskBar.validate();
		
		frameMap.put(button,frame);
	}

	this.windowCount=0;

	mousePressed( e	) {
		popup.show( pane, e.getX(), e.getY() );
	}

	shutdown() {
		/*
		ret = JOptionPane.showInternalConfirmDialog( pane,
			"This workspace	has not	been saved. Do you really want to exit?" );
		if ( ret == JOptionPane.YES_OPTION )
				exit();
		*/
		frame.dispose();
		exit();
	}

	actionPerformed( e ) 
	{
		this.com = e.getActionCommand();
		if ( com.equals("New Bsh Workspace") )
			makeWorkspace( ""+ super.windowCount++);
		if ( com.equals("New Class Browser") )
			classBrowser();
		else if	( com.equals("Save Workspace") )
			JOptionPane.showInternalMessageDialog( pane, "Unimplemented" );
		else if	( com.equals("Exit") )
			shutdown();
	}

	this.pane=new JDesktopPane();

	this.popup=new JPopupMenu("Root Menu");
	this.mi=new JMenuItem("New Bsh Workspace");
	mi.addActionListener(this);
	popup.add( mi );
	mi=new JMenuItem("New Class Browser");
	mi.addActionListener(this);
	popup.add( mi );
	mi=new JMenuItem("Save Workspace");
	mi.addActionListener(this);
	popup.add( mi );
	mi=new JMenuItem("Exit");
	mi.addActionListener(this);
	popup.add( mi );

	pane.addMouseListener( this );

	this.frame=new JFrame("BeanShell Desktop 1.1");
	
	stage.add(pane);
	stage.add(taskBar, BorderLayout.SOUTH);
	
	frame.getContentPane().add(stage);

	windowClosing( e ) {
		bsh.system.desktop = null;
		shutdown();
	}

	frame.iconImage=bsh.system.icons.bean.image;
	frame.addWindowListener( this );

	/*
		If available, add a listener for classpath mapping
		I'm planning to implement a GUI progress indicator here

	if ( Capabilities.canGenerateInterfaces() ) 
	{
		import bsh.classpath.BshClassPath;
		classFeedbackListener = new BshClassPath.MappingFeedback() 
		{
			startClassMapping() { }
			classMapping( msg ) { }
			errorWhileMapping( msg ) { }
			endClassMapping() { }
		};
		BshClassPath.addMappingFeedback( classFeedbackListener );
	}
	*/

	// start one terminal
	workSpace=makeWorkspace( ""+windowCount++	);

	frame.setSize(800,600);
	frame.show();
	
	Util.endSplashScreen();
	
	frame.toFront();
	workSpace.frame.selected=true;
}
jEdit/bsh/commands/debug.bsh0100600000175000017500000000031607773210647015262 0ustar  slavaslava/**
	Toggle on and off debug mode. 
	Debug output is verbose and generally useful only for developers.
*/

bsh.help.debug = "usage: debug()";

debug() {
	this.interpreter.DEBUG = !this.interpreter.DEBUG;
}
jEdit/bsh/commands/cp.bsh0100600000175000017500000000073207773210647014600 0ustar  slavaslava/**
	Copy a file (like Unix cp).
*/

bsh.help.cp = "usage: cp( fromFile, toFile )";

cp( String fromFile, String toFile ) 
{
    this.from = pathToFile( fromFile );
    this.to = pathToFile( toFile );

	this.in = new BufferedInputStream( new FileInputStream( from ) );
	this.out = new BufferedOutputStream( new FileOutputStream( to ) );
	byte [] buff = new byte [ 32*1024 ];
	while ( (len = in.read( buff )) > 0 )
			out.write( buff, 0, len );
	in.close();
	out.close();
}

jEdit/bsh/commands/clear.bsh0100600000175000017500000000036207773210647015263 0ustar  slavaslava/**
	Clear all variables, methods, and imports from this namespace.
	If this namespace is the root, it will be reset to the default 
	imports.
	See NameSpace.clear();
	@see NameSpace.clear();
*/
clear() {
    this.caller.namespace.clear();
}
jEdit/bsh/commands/classBrowser.bsh0100600000175000017500000000207507773210647016651 0ustar  slavaslava/**
	Open the class browser.
*/
import bsh.util.ClassBrowser;

classBrowser() 
{
	this.inDesktop = ( bsh.system.desktop != void );

	this.browser = new ClassBrowser( this.interpreter.getClassManager() );
	browser.init();

	if ( inDesktop ) {
		this.frame = 
			bsh.system.desktop.makeInternalFrame("BeanShell Class Browser");
		frame.frameIcon = bsh.system.icons.eye;
		bsh.system.desktop.classbrowser = browser;
	} else {
		this.frame = new javax.swing.JFrame("BeanShell Class Browser");
		frame.iconImage=bsh.system.icons.eye.image;
	}
		
	// Ignore unhandled method invocations from listeners.
	invoke( name, args ) {
		if ( !name.startsWith("internalFrame") )
			throw new Error("method: "+name);
	}
	internalFrameClosing( e ) {
		// really need foo=void;...  
		bsh.system.desktop.classbrowser = null;
	}

	if ( inDesktop )
		frame.addInternalFrameListener(this);

	browser.setFrame( frame );
	frame.getContentPane().add("Center", browser);
	frame.pack();

	if ( inDesktop )
		bsh.system.desktop.addInternalFrame(frame);

	frame.show();
	frame.selected=true;

	return browser;
}

jEdit/bsh/commands/cd.bsh0100600000175000017500000000060407773210647014562 0ustar  slavaslava/**
	Change working directory for dir(), etc. commands (like Unix cd)
*/

bsh.help.cd = "usage: cd( path )";

/*
	Additions by Kevin Raulerson, http://www.spin.com.mx/~kevinr/
*/
void cd( String pathname ) 
{
    this.file = pathToFile( pathname );

	if ( file.exists() && file.isDirectory() )
		bsh.cwd = file.getCanonicalPath();
	else
        print( "No such directory: "+pathname);
}

jEdit/bsh/commands/cat.bsh0100600000175000017500000000130307773210647014740 0ustar  slavaslava/**
	Print the contents of filename, url, or stream (like Unix cat)
*/

bsh.help.cat = "usage: cat( filename )";

/**
	cat comment
*/
cat( String filename ) 
{
	this.file = pathToFile( filename );

	if ( !file.exists() || !file.canRead() ) {
		print( "Can't read " + file );
		return;
	}

	cat( new FileReader( file ) );
}

/**
	cat comment
*/
cat( URL url ) 
{
	cat( url.openStream() );
}

cat( InputStream ins ) 
{
	this.bin = new BufferedReader( new InputStreamReader( ins ) );
	cat( bin );
}

cat( Reader reader ) 
{
	try {
		this.bin = new BufferedReader( reader );
		while ( (this.line=bin.readLine() ) != null )
			print( line );
	} catch ( Exception e ) {
		print( "Error reading stream:"+ e);
	}
}
jEdit/bsh/commands/browseClass.bsh0100600000175000017500000000213307773210647016462 0ustar  slavaslava/**
	Open the class browser to view the specified class.  
	If the argument is a string it is considered to be a class name.  
	If the argument is an object, the class of the object is used.  
	If the arg is a class, the class is used.
	<p>

	Note: To browse the String class you can't supply a String.
	You'd have to do:  browseClass( String.class );
	<p>


	@method void browseClass( String | Object | Class )
*/
import bsh.ClassIdentifier;

browseClass( Object o ) 
{
	String classname;
	if ( o instanceof String)
		classname = o;
	else if ( o instanceof ClassIdentifier )
		classname = this.namespace.identifierToClass(o).getName();
	else if ( o instanceof Class )
		classname = o.getName();
	else 
		classname = o.getClass().getName();

	// really need a way to unset and more poweful testing...
	if ( bsh.system.desktop == void 
			|| bsh.system.desktop.classbrowser == void 
			|| bsh.system.desktop.classbrowser == null ) 
	{
		this.browser = classBrowser();
	} else {
		this.browser = bsh.system.desktop.classbrowser;
		bsh.system.desktop.classbrowser.toFront();
	}

	browser.driveToClass( classname );
}

jEdit/bsh/commands/bind.bsh0100600000175000017500000000032107773210647015104 0ustar  slavaslava/**
	Bind a bsh object into a particular namespace and interpreter
*/
import bsh.This;
import bsh.NameSpace;

bind( bsh.This ths, bsh.NameSpace namespace ) {
	This.bind( ths, namespace, this.interpreter );
}

jEdit/bsh/commands/bg.bsh0100600000175000017500000000075007773210647014566 0ustar  slavaslava/**
	Source a command in its own thread in the caller's namespace
	<p>

	This is like run() except that it runs the command in its own thread.  
	Returns the Thread object control.
	@method Thread bg( String filename )
*/

bsh.help.run= "usage: Thread bg( filename )";

Thread bg( String filename ) 
{
	this.callerNameSpace = this.caller.namespace;
	run() {
		this.interpreter.source( filename, callerNameSpace );
	}

	this.thread = new Thread( this );
	thread.start();
	return thread;
}
jEdit/bsh/commands/workspaceEditor.bsh0100600000175000017500000000612407773210647017344 0ustar  slavaslava
/**
 * Make a new workspaceEditor associated with a workspace and place it on the
 * desktop.
 *
 * @method workspaceEditor( bsh.Interpreter parent, String name )
 *
 * @author Pat Niemeyer
 * @author Daniel Leuck
 */
 
import java.awt.Insets;
import bsh.Interpreter;

workspaceEditor(Interpreter parent, String name ) 
{
	
	if ( bsh.system.desktop == void ) {
		print("This only works with the bsh desktop...");
		return;
	}

	this.textarea = new JTextArea(15,40);
	textarea.setLineWrap(true);
	textarea.setWrapStyleWord(true);
	textarea.setTabSize(4);
	textarea.setMargin( new Insets(5,5,5,5) );
	textarea.font=new Font("Monospaced", 0, 12);

	// probably should overload desktop makeInternalFrame
	this.frame = 
		new JInternalFrame("Editor for: "+name, true, true, true, true );
	frame.frameIcon=bsh.system.icons.script;
	frame.getContentPane().add( new JScrollPane(textarea), "Center");
	frame.setVisible( true );

	open() 
	{
		this.chooser = new JFileChooser();
		chooser.setCurrentDirectory( pathToFile(bsh.cwd) );
		this.returnVal = chooser.showOpenDialog( bsh.system.desktop.pane );
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			this.file = chooser.getSelectedFile();
			this.reader=new FileReader( file );
			this.ca=new char [file.length()];
			reader.read(ca);
			textarea.setText( new String(ca) );
		}
	}

	save() 
	{
		this.chooser = new JFileChooser();
		chooser.setCurrentDirectory( pathToFile(bsh.cwd) );
		this.returnVal = chooser.showSaveDialog( bsh.system.desktop.pane );
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			this.file = chooser.getSelectedFile();
			this.writer=new FileWriter( file );
			writer.write( textarea.getText().toCharArray() );
			writer.close();
		}
	}

	run() 
	{
		this.interpreter = makeWorkspace( "Run Output: " +name);
		// should make this new namespace... look at run() command
    	interpreter.eval( textarea.getText() );
		print("done run...");
	}

	actionPerformed(e) 
	{
		this.com = e.getActionCommand();
		if ( com.equals("Close") )
			frame.setClosed(true);
		else if ( com.equals("New") )
			textarea.setText("");
		else if ( com.equals("Open") )
			open();
		else if ( com.equals("Save") )
			save();
		else if ( com.equals("Eval in Workspace") )
			// eval in parent global namespace
    		parent.eval( textarea.getText() );
		else if ( com.equals("Run in new Workspace") )
			run();
	}

	this.menubar = new JMenuBar();
	this.menu = new JMenu("File");
	this.mi = new JMenuItem("New");
	mi.addActionListener(this);
	menu.add(mi);
	mi = new JMenuItem("Open");
	mi.addActionListener(this);
	menu.add(mi);
	mi = new JMenuItem("Save");
	mi.addActionListener(this);
	menu.add(mi);
	mi = new JMenuItem("Close");
	mi.addActionListener(this);
	menu.add(mi);
	menubar.add(menu);

	menu = new JMenu("Evaluate");
	mi = new JMenuItem("Eval in Workspace");
	mi.addActionListener(this);
	menu.add(mi);
	mi = new JMenuItem("Run in new Workspace");
	mi.addActionListener(this);
	menu.add(mi);
	menubar.add(menu);

	menu = fontMenu( textarea );
	menubar.add(menu);

	frame.setMenuBar( menubar );

	frame.pack();
	bsh.system.desktop.addInternalFrame( frame );
	frame.selected=true;
	return frame;
}
jEdit/bsh/commands/dir.java0100600000175000017500000000461707773210651015122 0ustar  slavaslava/**
	Display the contents of the current working directory.  
	The format is similar to the Unix ls -l
	<em>This is an example of a bsh command written in Java for speed.</em>
	
	@method void dir( [ String dirname ] )
*/
package bsh.commands;

import java.io.*;
import bsh.*;
import java.util.Date;
import java.util.Vector;
import java.util.GregorianCalendar;
import java.util.Calendar;

public class dir 
{
	static final String [] months = { "Jan", "Feb", "Mar", "Apr", 
		"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

	public static String usage() {
		return "usage: dir( String dir )\n       dir()";
	}

	/**
		Implement dir() command.
	*/
	public static void invoke( Interpreter env, CallStack callstack ) 
	{
		String dir = ".";
		invoke( env, callstack, dir );
	}

	/**
		Implement dir( String directory ) command.
	*/
	public static void invoke( 
		Interpreter env, CallStack callstack, String dir ) 
	{
		File file;
		try {
			file =  env.pathToFile( dir );
		} catch (IOException e ) {
			env.println("error reading path: "+e);
			return;
		}

		if ( !file.exists() || !file.canRead() ) {
			env.println( "Can't read " + file );
			return;
		}
		if ( !file.isDirectory() )  {
			env.println("'"+dir+"' is not a directory");
		}

		String [] files = file.list();
		files = StringUtil.bubbleSort(files);

		for( int i=0; i< files.length; i++ ) {
			File f = new File( dir + File.separator + files[i] );
			StringBuffer sb = new StringBuffer();
			sb.append( f.canRead() ? "r": "-" );
			sb.append( f.canWrite() ? "w": "-" );
			sb.append( "_" );
			sb.append( " ");

			Date d = new Date(f.lastModified());
			GregorianCalendar c = new GregorianCalendar();
			c.setTime(d);
			int day	= c.get(Calendar.DAY_OF_MONTH);
			sb.append( months[ c.get(Calendar.MONTH) ] + " " + day );
			if ( day < 10 ) 
				sb.append(" ");

			sb.append(" ");

			// hack to get fixed length 'length' field
			int fieldlen = 8;
			StringBuffer len = new StringBuffer();
			for(int j=0; j<fieldlen; j++)
				len.append(" ");
			len.insert(0, f.length());
			len.setLength(fieldlen);
			// hack to move the spaces to the front
			int si = len.toString().indexOf(" ");
			if ( si != -1 ) {
				String pad = len.toString().substring(si);
				len.setLength(si);
				len.insert(0, pad);
			}
			
			sb.append( len.toString() );

			sb.append( " " + f.getName() );
			if ( f.isDirectory() ) 
				sb.append("/");

			env.println( sb.toString() );
		}
	}
}

jEdit/bsh/BSHAllocationExpression.java0100600000175000017500000002727507773206043017252 0ustar  slavaslava/*****************************************************************************
 *                                                                           *
 *  This file is part of the BeanShell Java Scripting distribution.          *
 *  Documentation and updates may be found at http://www.beanshell.org/      *
 *                                                                           *
 *  Sun Public License Notice:                                               *
 *                                                                           *
 *  The contents of this file are subject to the Sun Public License Version  *
 *  1.0 (the "License"); you may not use this file except in compliance with *
 *  the License. A copy of the License is available at http://www.sun.com    * 
 *                                                                           *
 *  The Original Code is BeanShell. The Initial Developer of the Original    *
 *  Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright     *
 *  (C) 2000.  All Rights Reserved.                                          *
 *                                                                           *
 *  GNU Public License Notice:                                               *
 *                                                                           *
 *  Alternatively, the contents of this file may be used under the terms of  *
 *  the GNU Lesser General Public License (the "LGPL"), in which case the    *
 *  provisions of LGPL are applicable instead of those above. If you wish to *
 *  allow use of your version of this file only under the  terms of the LGPL *
 *  and not to allow others to use your version of this file under the SPL,  *
 *  indicate your decision by deleting the provisions above and replace      *
 *  them with the notice and other provisions required by the LGPL.  If you  *
 *  do not delete the provisions above, a recipient may use your version of  *
 *  this file under either the SPL or the LGPL.                              *
 *                                                                           *
 *  Patrick Niemeyer (pat@pat.net)                                           *
 *  Author of Learning Java, O'Reilly & Associates                           *
 *  http://www.pat.net/~pat/                                                 *
 *                                                                           *
 *****************************************************************************/


package bsh;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;

/**
	New object, new array, or inner class style allocation with body.
*/
class BSHAllocationExpression extends SimpleNode
{
    BSHAllocationExpression(int id) { super(id); }
	private static int innerClassCount = 0;
	
    public Object eval( CallStack callstack, Interpreter interpreter) 
		throws EvalError
    {
        // type is either a class name or a primitive type
        SimpleNode type = (SimpleNode)jjtGetChild(0);

        // args is either constructor arguments or array dimensions
        SimpleNode args = (SimpleNode)jjtGetChild(1);

        if ( type instanceof BSHAmbiguousName )
        {
            BSHAmbiguousName name = (BSHAmbiguousName)type;

            if (args instanceof BSHArguments)
                return objectAllocation(name, (BSHArguments)args, 
					callstack, interpreter );
            else
                return objectArrayAllocation(name, (BSHArrayDimensions)args, 
					callstack, interpreter );
        }
        else
            return primitiveArrayAllocation((BSHPrimitiveType)type,
                (BSHArrayDimensions)args, callstack, interpreter );
    }

    private Object objectAllocation(
		BSHAmbiguousName nameNode, BSHArguments argumentsNode, 
		CallStack callstack, Interpreter interpreter 
	) 
		throws EvalError
    {
		NameSpace namespace = callstack.top();

        Object[] args = argumentsNode.getArguments( callstack, interpreter );
        if ( args == null)
            throw new EvalError( "Null args in new.", this, callstack );

		// Look for scripted class object
        Object obj = nameNode.toObject( 
			callstack, interpreter, false/* force class*/ );

		// Try regular class

        obj = nameNode.toObject( 
			callstack, interpreter, true/*force class*/ );

        Class type = null;
		if ( obj instanceof ClassIdentifier )
        	type = ((ClassIdentifier)obj).getTargetClass();
		else
			throw new EvalError( 
				"Unknown class: "+nameNode.text, this, callstack );

		// Is an inner class style object allocation
		boolean hasBody = jjtGetNumChildren() > 2;

		if ( hasBody ) 
		{
        	BSHBlock body = (BSHBlock)jjtGetChild(2);
			if ( type.isInterface() )
				return constructWithInterfaceBody( 
					type, args, body, callstack, interpreter );
			else
				return constructWithClassBody( 
					type, args, body, callstack, interpreter );
		} else
			return constructObject( type, args, callstack );
    }

	private Object constructObject( 
		Class type, Object[] args, CallStack callstack ) 
		throws EvalError
	{
		Object obj;
        try {
            obj = Reflect.constructObject( type, args );
        } catch ( ReflectError e) {
            throw new EvalError(
				"Constructor error: " + e.getMessage(), this, callstack );
        } catch(InvocationTargetException e) {
			// No need to wrap this debug
			Interpreter.debug("The constructor threw an exception:\n\t" +
				e.getTargetException());
            throw new TargetError(
				"Object constructor", e.getTargetException(), 
				this, callstack, true);
        }

		String className = type.getName();
		// Is it an inner class?
		if ( className.indexOf("$") == -1 )
			return obj;

		// Temporary hack to support inner classes 
		// If the obj is a non-static inner class then import the context...
		// This is not a sufficient emulation of inner classes.
		// Replace this later...

		// work through to class 'this'
		This ths = callstack.top().getThis( null );
		NameSpace instanceNameSpace = 
			Name.getClassNameSpace( ths.getNameSpace() );
		
		// Change the parent (which was the class static) to the class instance
		// We really need to check if we're a static inner class here first...
		// but for some reason Java won't show the static modifier on our
		// fake inner classes...  could generate a flag field.
		if ( instanceNameSpace != null 
			&& className.startsWith( instanceNameSpace.getName() +"$") 
		)
		{
			try {
				ClassGenerator.getClassGenerator().setInstanceNameSpaceParent(
					obj, className, instanceNameSpace );
			} catch ( UtilEvalError e ) {
				throw e.toEvalError( this, callstack );
			}
		}

		return obj;
	}

	private Object constructWithClassBody( 
		Class type, Object[] args, BSHBlock block,
		CallStack callstack, Interpreter interpreter ) 
		throws EvalError
	{
		String name = callstack.top().getName() + "$" + (++innerClassCount);
		Modifiers modifiers = new Modifiers();
		modifiers.addModifier( Modifiers.CLASS, "public" );
		Class clas;
		try {
			clas = ClassGenerator.getClassGenerator() .generateClass( 
				name, modifiers, null/*interfaces*/, type/*superClass*/, 
				block, false/*isInterface*/, callstack, interpreter );
		} catch ( UtilEvalError e ) {
			throw e.toEvalError( this, callstack );
		}
		try {
			return Reflect.constructObject( clas, args );
		} catch ( Exception e ) {
			if ( e instanceof InvocationTargetException )
				e = (Exception)((InvocationTargetException)e)
					.getTargetException();
			throw new EvalError(
				"Error constructing inner class instance: "+e, this, callstack
			);
		}
	}

	private Object constructWithInterfaceBody( 
		Class type, Object[] args, BSHBlock body,
		CallStack callstack, Interpreter interpreter ) 
		throws EvalError
	{
		NameSpace namespace = callstack.top();
		NameSpace local = new NameSpace(namespace, "AnonymousBlock");
		callstack.push(local);
		body.eval( callstack, interpreter, true/*overrideNamespace*/ );
		callstack.pop();
		// statical import fields from the interface so that code inside
		// can refer to the fields directly (e.g. HEIGHT)
		local.importStatic( type );
		try {
			return local.getThis(interpreter).getInterface( type );
		} catch ( UtilEvalError e ) {
			throw e.toEvalError( this, callstack );
		}
	}

    private Object objectArrayAllocation(
		BSHAmbiguousName nameNode, BSHArrayDimensions dimensionsNode, 
		CallStack callstack, Interpreter interpreter 
	) 
		throws EvalError
    {
		NameSpace namespace = callstack.top();
        Class type = nameNode.toClass( callstack, interpreter );
        if ( type == null )
            throw new EvalError( "Class " + nameNode.getName(namespace) 
				+ " not found.", this, callstack );

		return arrayAllocation( dimensionsNode, type, callstack, interpreter );
    }

    private Object primitiveArrayAllocation(
		BSHPrimitiveType typeNode, BSHArrayDimensions dimensionsNode, 
		CallStack callstack, Interpreter interpreter 
	) 
		throws EvalError
    {
        Class type = typeNode.getType();

		return arrayAllocation( dimensionsNode, type, callstack, interpreter );
    }

	private Object arrayAllocation( 
		BSHArrayDimensions dimensionsNode, Class type, 
		CallStack callstack, Interpreter interpreter )
		throws EvalError
	{
		/*
			dimensionsNode can return either a fully intialized array or VOID.
			when VOID the prescribed array dimensions (defined and undefined)
			are contained in the node.
		*/
        Object result = dimensionsNode.eval( type, callstack, interpreter );
        if ( result != Primitive.VOID )
            return result;
		else
			return arrayNewInstance( type, dimensionsNode, callstack );
	}

	/**
		Create an array of the dimensions specified in dimensionsNode.
		dimensionsNode may contain a number of "undefined" as well as "defined"
		dimensions.
		<p>

		Background: in Java arrays are implemented in arrays-of-arrays style
		where, for example, a two dimensional array is a an array of arrays of
		some base type.  Each dimension-type has a Java class type associated 
		with it... so if foo = new int[5][5] then the type of foo is 
		int [][] and the type of foo[0] is int[], etc.  Arrays may also be 
		specified with undefined trailing dimensions - meaning that the lower 
		order arrays are not allocated as objects. e.g.  
		if foo = new int [5][]; then foo[0] == null //true; and can later be 
		assigned with the appropriate type, e.g. foo[0] = new int[5];
		(See Learning Java, O'Reilly & Associates more background).
		<p>

		To create an array with undefined trailing dimensions using the
		reflection API we must use an array type to represent the lower order
		(undefined) dimensions as the "base" type for the array creation... 
		Java will then create the correct type by adding the dimensions of the 
		base type to specified allocated dimensions yielding an array of
		dimensionality base + specified with the base dimensons unallocated.  
		To create the "base" array type we simply create a prototype, zero 
		length in each dimension, array and use it to get its class 
		(Actually, I think there is a way we could do it with Class.forName() 
		but I don't trust this).   The code is simpler than the explanation...
		see below.
	*/
	private Object arrayNewInstance( 
		Class type, BSHArrayDimensions dimensionsNode, CallStack callstack )
		throws EvalError
	{
		if ( dimensionsNode.numUndefinedDims > 0 )
		{
            Object proto = Array.newInstance( 
				type, new int [dimensionsNode.numUndefinedDims] ); // zeros
			type = proto.getClass();
		}

        try {
            return Array.newInstance( 
				type, dimensionsNode.definedDimensions);
        } catch( NegativeArraySizeException e1 ) {
			throw new TargetError( e1, this, callstack );
        } catch( Exception e ) {
            throw new EvalError("Can't construct primitive array: " +
                e.getMessage(), this, callstack);
        }
	}
}
jEdit/bsh/Variable.java0100600000175000017500000000460107773206043014261 0ustar  slavaslavapackage bsh;

public class Variable implements java.io.Serializable 
{
	static final int DECLARATION=0, ASSIGNMENT=1;
	/** A null type means an untyped variable */
	String name;
	Class type = null;
	String typeDescriptor;
	Object value;
	Modifiers modifiers;
	LHS lhs;

	Variable( String name, Class type, LHS lhs ) 
	{
		this.name = name;
		this.lhs = lhs;
		this.type = type;
	}
	
	Variable( String name, Object value, Modifiers modifiers )
		throws UtilEvalError
	{
		this( name, (Class)null/*type*/, value, modifiers );
	}

	/**
		This constructor is used in class generation.
	*/
	Variable( 
		String name, String typeDescriptor, Object value, Modifiers modifiers 
	)
		throws UtilEvalError
	{
		this( name, (Class)null/*type*/, value, modifiers );
		this.typeDescriptor = typeDescriptor;
	}

	/**
		@param value may be null if this 
	*/
	Variable( String name, Class type, Object value, Modifiers modifiers )
		throws UtilEvalError
	{

		this.name=name;
		this.type =	type;
		this.modifiers = modifiers;
		setValue( value, DECLARATION );
	}

	/**
		Set the value of the typed variable.
		@param value should be an object or wrapped bsh Primitive type.
		if value is null the appropriate default value will be set for the
		type: e.g. false for boolean, zero for integer types.
	*/
	public void setValue( Object value, int context ) 
		throws UtilEvalError
	{

		// check this.value
		if ( hasModifier("final") && this.value != null )
			throw new UtilEvalError ("Final variable, can't re-assign.");

		if ( value == null )
			value = Primitive.getDefaultValue( type );

		if ( lhs != null )
		{
			lhs.assign( value, false/*strictjava*/ );
			return;
		}

		if ( type != null )
			value = Types.castObject( value, type, 
				context == DECLARATION ? Types.CAST : Types.ASSIGNMENT
			);

		this.value= value;
	}

	Object getValue() 
		throws UtilEvalError
	{ 
		if ( lhs != null )
			return lhs.getValue();

		return value; 
	}

	/** A type of null means loosely typed variable */
	public Class getType() { return type;	}

	public String getTypeDescriptor() { return typeDescriptor; }

	public Modifiers getModifiers() { return modifiers; }

	public String getName() { return name; }

	public boolean hasModifier( String name ) {
		return modifiers != null && modifiers.hasModifier(name);
	}

	public String toString() { 
		return "Variable: "+super.toString()+" "+name+", type:"+type
			+", value:"+value +", lhs = "+lhs;
	}
}
jEdit/bsh/UtilTargetError.java0100600000175000017500000000645707773206043015645 0ustar  slavaslava/*****************************************************************************
 *                                                                           *
 *  This file is part of the BeanShell Java Scripting distribution.          *
 *  Documentation and updates may be found at http://www.beanshell.org/      *
 *                                                                           *
 *  Sun Public License Notice:                                               *
 *                                                                           *
 *  The contents of this file are subject to the Sun Public License Version  *
 *  1.0 (the "License"); you may not use this file except in compliance with *
 *  the License. A copy of the License is available at http://www.sun.com    * 
 *                                                                           *
 *  The Original Code is BeanShell. The Initial Developer of the Original    *
 *  Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright     *
 *  (C) 2000.  All Rights Reserved.                                          *
 *                                                                           *
 *  GNU Public License Notice:                                               *
 *                                                                           *
 *  Alternatively, the contents of this file may be used under the terms of  *
 *  the GNU Lesser General Public License (the "LGPL"), in which case the    *
 *  provisions of LGPL are applicable instead of those above. If you wish to *
 *  allow use of your version of this file only under the  terms of the LGPL *
 *  and not to allow others to use your version of this file under the SPL,  *
 *  indicate your decision by deleting the provisions above and replace      *
 *  them with the notice and other provisions required by the LGPL.  If you  *
 *  do not delete the provisions above, a recipient may use your version of  *
 *  this file under either the SPL or the LGPL.                              *
 *                                                                           *
 *  Patrick Niemeyer (pat@pat.net)                                           *
 *  Author of Learning Java, O'Reilly & Associates                           *
 *  http://www.pat.net/~pat/                                                 *
 *                                                                           *
 *****************************************************************************/


package bsh;

/**
	UtilTargetError is an error corresponding to a TargetError but thrown by a 
	utility or other class that does not have the caller context (Node) 
	available to it.  See UtilEvalError for an explanation of the difference
	between UtilEvalError and EvalError.
	<p>

	@see UtilEvalError
*/
public class UtilTargetError extends UtilEvalError
{
	public Throwable t;

	public UtilTargetError( String message, Throwable t ) {
		super( message );
		this.t = t;
	}

	public UtilTargetError( Throwable t ) {
		this( null, t );
	}

	/**
		Override toEvalError to throw TargetError type.
	*/
	public EvalError toEvalError( 
		String msg, SimpleNode node, CallStack callstack  ) 
	{
		if ( msg == null )
			msg = getMessage();
		else
			msg = msg + ": " + getMessage();

		return new TargetError( msg, t, node, callstack, false );
	}
}

jEdit/bsh/UtilEvalError.java0100600000175000017500000001023407773206043015272 0ustar  slavaslava/*****************************************************************************
 *                                                                           *
 *  This file is part of the BeanShell Java Scripting distribution.          *
 *  Documentation and updates may be found at http://www.beanshell.org/      *
 *                                                                           *
 *  Sun Public License Notice:                                               *
 *                                                                           *
 *  The contents of this file are subject to the Sun Public License Version  *
 *  1.0 (the "License"); you may not use this file except in compliance with *
 *  the License. A copy of the License is available at http://www.sun.com    * 
 *                                                                           *
 *  The Original Code is BeanShell. The Initial Developer of the Original    *
 *  Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright     *
 *  (C) 2000.  All Rights Reserved.                                          *
 *                                                                           *
 *  GNU Public License Notice:                                               *
 *                                                                           *
 *  Alternatively, the contents of this file may be used under the terms of  *
 *  the GNU Lesser General Public License (the "LGPL"), in which case the    *
 *  provisions of LGPL are applicable instead of those above. If you wish to *
 *  allow use of your version of this file only under the  terms of the LGPL *
 *  and not to allow others to use your version of this file under the SPL,  *
 *  indicate your decision by deleting the provisions above and replace      *
 *  them with the notice and other provisions required by the LGPL.  If you  *
 *  do not delete the provisions above, a recipient may use your version of  *
 *  this file under either the SPL or the LGPL.                              *
 *                                                                           *
 *  Patrick Niemeyer (pat@pat.net)                                           *
 *  Author of Learning Java, O'Reilly & Associates                           *
 *  http://www.pat.net/~pat/                                                 *
 *                                                                           *
 *****************************************************************************/


package bsh;

/**
	UtilEvalError is an error corresponding to an EvalError but thrown by a 
	utility or other class that does not have the caller context (Node) 
	available to it.  A normal EvalError must supply the caller Node in order 
	for error messages to be pinned to the correct line and location in the 
	script.  UtilEvalError is a checked exception that is *not* a subtype of 
	EvalError, but instead must be caught and rethrown as an EvalError by 
	the a nearest location with context.  The method toEvalError( Node ) 
	should be used to throw the EvalError, supplying the node.
	<p>

	To summarize: Utilities throw UtilEvalError.  ASTs throw EvalError.
	ASTs catch UtilEvalError and rethrow it as EvalError using 
	toEvalError( Node ).  
	<p>

	Philosophically, EvalError and UtilEvalError corrospond to 
	RuntimeException.  However they are constrained in this way in order to 
	add the context for error reporting.

	@see UtilTargetError
*/
public class UtilEvalError extends Exception 
{
	protected UtilEvalError() {
	}

	public UtilEvalError( String s ) {
		super(s);
	}

	/**
		Re-throw as an eval error, prefixing msg to the message and specifying
		the node.  If a node already exists the addNode is ignored.
		@see #setNode( bsh.SimpleNode )
		<p>
		@param msg may be null for no additional message.
	*/
	public EvalError toEvalError( 
		String msg, SimpleNode node, CallStack callstack  ) 
	{
		if ( Interpreter.DEBUG )
			printStackTrace();

		if ( msg == null )
			msg = "";
		else
			msg = msg + ": ";
		return new EvalError( msg+getMessage(), node, callstack );
	}

	public EvalError toEvalError ( SimpleNode node, CallStack callstack ) 
	{
		return toEvalError( null, node, callstack );
	}

}

jEdit/bsh/Types.java0100600000175000017500000003542507773206043013650 0ustar  slavaslava/*****************************************************************************
 *                                                                           *
 *  This file is part of the BeanShell Java Scripting distribution.          *
 *  Documentation and updates may be found at http://www.beanshell.org/      *
 *                                                                           *
 *  Sun Public License Notice:                                               *
 *                                                                           *
 *  The contents of this file are subject to the Sun Public License Version  *
 *  1.0 (the "License"); you may not use this file except in compliance with *
 *  the License. A copy of the License is available at http://www.sun.com    * 
 *                                                                           *
 *  The Original Code is BeanShell. The Initial Developer of the Original    *
 *  Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright     *
 *  (C) 2000.  All Rights Reserved.                                          *
 *                                                                           *
 *  GNU Public License Notice:                                               *
 *                                                                           *
 *  Alternatively, the contents of this file may be used under the terms of  *
 *  the GNU Lesser General Public License (the "LGPL"), in which case the    *
 *  provisions of LGPL are applicable instead of those above. If you wish to *
 *  allow use of your version of this file only under the  terms of the LGPL *
 *  and not to allow others to use your version of this file under the SPL,  *
 *  indicate your decision by deleting the provisions above and replace      *
 *  them with the notice and other provisions required by the LGPL.  If you  *
 *  do not delete the provisions above, a recipient may use your version of  *
 *  this file under either the SPL or the LGPL.                              *
 *                                                                           *
 *  Patrick Niemeyer (pat@pat.net)                                           *
 *  Author of Learning Java, O'Reilly & Associates                           *
 *  http://www.pat.net/~pat/                                                 *
 *                                                                           *
 *****************************************************************************/

package bsh;

/**
	Static routines supporing type comparison and conversion in BeanShell.
*/
class Types 
{
	static final int CAST=0, ASSIGNMENT=1;
	/**
		Special value that indicates by identity that the result of a cast
		operation was a valid cast.  This is used by castObject() and
		castPrimitive() in the checkOnly mode of operation.  This value is a 
		Primitive type so that it can be returned by castPrimitive.
	*/
	static Primitive VALID_CAST = new Primitive(1);
	static Primitive INVALID_CAST = new Primitive(-1);
	/**
		Get the Java types of the arguments.
	*/
    public static Class[] getTypes( Object[] args )
    {
        if ( args == null )
            return new Class[0];

        Class[] types = new Class[ args.length ];

        for( int i=0; i<args.length; i++ )
        {
			if ( args[i] == null )
				types[i] = null;
            else 
			if ( args[i] instanceof Primitive )
                types[i] = ((Primitive)args[i]).getType();
            else
                types[i] = args[i].getClass();
        }

        return types;
    }

	/**
		Arguments are assignable as defined by Types.getAssignableForm()
		which takes into account special bsh conversions such as XThis and
		primitive wrapper promotion.
		@deprecated fix this! need to stop catching exception
	*/
	static boolean argsAssignable( Class [] parameters, Object [] args )
	{
		Class [] argTypes = getTypes( args );
		return isSignatureAssignable( argTypes, parameters );
	}

	/**
		Is the 'from' signatur