001: /*****************************************************************************
002: * *
003: * This file is part of the BeanShell Java Scripting distribution. *
004: * Documentation and updates may be found at http://www.beanshell.org/ *
005: * *
006: * Sun Public License Notice: *
007: * *
008: * The contents of this file are subject to the Sun Public License Version *
009: * 1.0 (the "License"); you may not use this file except in compliance with *
010: * the License. A copy of the License is available at http://www.sun.com *
011: * *
012: * The Original Code is BeanShell. The Initial Developer of the Original *
013: * Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright *
014: * (C) 2000. All Rights Reserved. *
015: * *
016: * GNU Public License Notice: *
017: * *
018: * Alternatively, the contents of this file may be used under the terms of *
019: * the GNU Lesser General Public License (the "LGPL"), in which case the *
020: * provisions of LGPL are applicable instead of those above. If you wish to *
021: * allow use of your version of this file only under the terms of the LGPL *
022: * and not to allow others to use your version of this file under the SPL, *
023: * indicate your decision by deleting the provisions above and replace *
024: * them with the notice and other provisions required by the LGPL. If you *
025: * do not delete the provisions above, a recipient may use your version of *
026: * this file under either the SPL or the LGPL. *
027: * *
028: * Patrick Niemeyer (pat@pat.net) *
029: * Author of Learning Java, O'Reilly & Associates *
030: * http://www.pat.net/~pat/ *
031: * *
032: *****************************************************************************/package org.gjt.sp.jedit.bsh;
033:
034: public class DelayedEvalBshMethod extends BshMethod {
035: String returnTypeDescriptor;
036: BSHReturnType returnTypeNode;
037: String[] paramTypeDescriptors;
038: BSHFormalParameters paramTypesNode;
039:
040: // used for the delayed evaluation...
041: transient CallStack callstack;
042: transient Interpreter interpreter;
043:
044: /**
045: This constructor is used in class generation. It supplies String type
046: descriptors for return and parameter class types and allows delay of
047: the evaluation of those types until they are requested. It does this
048: by holding BSHType nodes, as well as an evaluation callstack, and
049: interpreter which are called when the class types are requested.
050: */
051: /*
052: Note: technically I think we could get by passing in only the
053: current namespace or perhaps BshClassManager here instead of
054: CallStack and Interpreter. However let's just play it safe in case
055: of future changes - anywhere you eval a node you need these.
056: */
057: DelayedEvalBshMethod(String name, String returnTypeDescriptor,
058: BSHReturnType returnTypeNode, String[] paramNames,
059: String[] paramTypeDescriptors,
060: BSHFormalParameters paramTypesNode, BSHBlock methodBody,
061: NameSpace declaringNameSpace, Modifiers modifiers,
062: CallStack callstack, Interpreter interpreter) {
063: super (name, null/*returnType*/, paramNames,
064: null/*paramTypes*/, methodBody, declaringNameSpace,
065: modifiers);
066:
067: this .returnTypeDescriptor = returnTypeDescriptor;
068: this .returnTypeNode = returnTypeNode;
069: this .paramTypeDescriptors = paramTypeDescriptors;
070: this .paramTypesNode = paramTypesNode;
071: this .callstack = callstack;
072: this .interpreter = interpreter;
073: }
074:
075: public String getReturnTypeDescriptor() {
076: return returnTypeDescriptor;
077: }
078:
079: public Class getReturnType() {
080: if (returnTypeNode == null)
081: return null;
082:
083: // BSHType will cache the type for us
084: try {
085: return returnTypeNode
086: .evalReturnType(callstack, interpreter);
087: } catch (EvalError e) {
088: throw new InterpreterError("can't eval return type: " + e);
089: }
090: }
091:
092: public String[] getParamTypeDescriptors() {
093: return paramTypeDescriptors;
094: }
095:
096: public Class[] getParameterTypes() {
097: // BSHFormalParameters will cache the type for us
098: try {
099: return (Class[]) paramTypesNode
100: .eval(callstack, interpreter);
101: } catch (EvalError e) {
102: throw new InterpreterError("can't eval param types: " + e);
103: }
104: }
105: }
|