KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bsh > DelayedEvalBshMethod


1 /*****************************************************************************
2  * *
3  * This file is part of the BeanShell Java Scripting distribution. *
4  * Documentation and updates may be found at http://www.beanshell.org/ *
5  * *
6  * Sun Public License Notice: *
7  * *
8  * The contents of this file are subject to the Sun Public License Version *
9  * 1.0 (the "License"); you may not use this file except in compliance with *
10  * the License. A copy of the License is available at http://www.sun.com *
11  * *
12  * The Original Code is BeanShell. The Initial Developer of the Original *
13  * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright *
14  * (C) 2000. All Rights Reserved. *
15  * *
16  * GNU Public License Notice: *
17  * *
18  * Alternatively, the contents of this file may be used under the terms of *
19  * the GNU Lesser General Public License (the "LGPL"), in which case the *
20  * provisions of LGPL are applicable instead of those above. If you wish to *
21  * allow use of your version of this file only under the terms of the LGPL *
22  * and not to allow others to use your version of this file under the SPL, *
23  * indicate your decision by deleting the provisions above and replace *
24  * them with the notice and other provisions required by the LGPL. If you *
25  * do not delete the provisions above, a recipient may use your version of *
26  * this file under either the SPL or the LGPL. *
27  * *
28  * Patrick Niemeyer (pat@pat.net) *
29  * Author of Learning Java, O'Reilly & Associates *
30  * http://www.pat.net/~pat/ *
31  * *
32  *****************************************************************************/

33
34 package bsh;
35
36 public class DelayedEvalBshMethod extends BshMethod
37 {
38     String JavaDoc returnTypeDescriptor;
39     BSHReturnType returnTypeNode;
40     String JavaDoc [] paramTypeDescriptors;
41     BSHFormalParameters paramTypesNode;
42
43     // used for the delayed evaluation...
44
transient CallStack callstack;
45     transient Interpreter interpreter;
46
47     /**
48         This constructor is used in class generation. It supplies String type
49         descriptors for return and parameter class types and allows delay of
50         the evaluation of those types until they are requested. It does this
51         by holding BSHType nodes, as well as an evaluation callstack, and
52         interpreter which are called when the class types are requested.
53     */

54     /*
55         Note: technically I think we could get by passing in only the
56         current namespace or perhaps BshClassManager here instead of
57         CallStack and Interpreter. However let's just play it safe in case
58         of future changes - anywhere you eval a node you need these.
59     */

60     DelayedEvalBshMethod(
61         String JavaDoc name,
62         String JavaDoc returnTypeDescriptor, BSHReturnType returnTypeNode,
63         String JavaDoc [] paramNames,
64         String JavaDoc [] paramTypeDescriptors, BSHFormalParameters paramTypesNode,
65         BSHBlock methodBody,
66         NameSpace declaringNameSpace, Modifiers modifiers,
67         CallStack callstack, Interpreter interpreter
68     ) {
69         super( name, null/*returnType*/, paramNames, null/*paramTypes*/,
70             methodBody, declaringNameSpace, modifiers );
71
72         this.returnTypeDescriptor = returnTypeDescriptor;
73         this.returnTypeNode = returnTypeNode;
74         this.paramTypeDescriptors = paramTypeDescriptors;
75         this.paramTypesNode = paramTypesNode;
76         this.callstack = callstack;
77         this.interpreter = interpreter;
78     }
79
80     public String JavaDoc getReturnTypeDescriptor() { return returnTypeDescriptor; }
81
82     public Class JavaDoc getReturnType()
83     {
84         if ( returnTypeNode == null )
85             return null;
86
87         // BSHType will cache the type for us
88
try {
89             return returnTypeNode.evalReturnType( callstack, interpreter );
90         } catch ( EvalError e ) {
91             throw new InterpreterError("can't eval return type: "+e);
92         }
93     }
94
95     public String JavaDoc [] getParamTypeDescriptors() { return paramTypeDescriptors; }
96
97     public Class JavaDoc [] getParameterTypes()
98     {
99         // BSHFormalParameters will cache the type for us
100
try {
101             return (Class JavaDoc [])paramTypesNode.eval( callstack, interpreter );
102         } catch ( EvalError e ) {
103             throw new InterpreterError("can't eval param types: "+e);
104         }
105     }
106 }
107
Popular Tags