PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Unknown | 43 lines | 38 code | 5 blank | 0 comment | 0 complexity | 01c2bd8d11ee8a0b9cd159aa97d0eaa3 MD5 | raw file
 1/**
 2	Return a BeanShell 'this' reference to the enclosing scope 
 3	(method scope) of the specified name.
 4	e.g. 
 5	<p>
 6    <pre>
 7    foo() {
 8        x=1;
 9        bar() {
10            x=2;
11            gee() {
12                x=3;
13                print( x ); // 3
14                print( super.x ); // 2
15                print( super("foo").x ); // 1
16            }
17        }
18    }
19    </pre>
20	<p>
21
22	This is an experimental command that is not intended to be of general use.
23	<p>
24
25	@method This super( String scopename )
26*/
27bsh.help.super = "usage: super( methodname )";
28
29// The implementation of this command is very fragile
30
31super( String scope ) 
32{
33	this.n=this.caller.namespace;
34	while ( n != global ) {
35		if ( n.namespace.getName().equals( "Method NameSpace: "+ scope ) )
36			return n;
37		else
38			n=n.super;
39	}
40	if ( n == global)
41		throw new EvalError("Enclosing scope not found: "+scope);
42}
43