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: class BSHFormalParameters extends SimpleNode {
035: private String[] paramNames;
036: /**
037: For loose type parameters the paramTypes are null.
038: */
039: // unsafe caching of types
040: Class[] paramTypes;
041: int numArgs;
042: String[] typeDescriptors;
043:
044: BSHFormalParameters(int id) {
045: super (id);
046: }
047:
048: void insureParsed() {
049: if (paramNames != null)
050: return;
051:
052: this .numArgs = jjtGetNumChildren();
053: String[] paramNames = new String[numArgs];
054:
055: for (int i = 0; i < numArgs; i++) {
056: BSHFormalParameter param = (BSHFormalParameter) jjtGetChild(i);
057: paramNames[i] = param.name;
058: }
059:
060: this .paramNames = paramNames;
061: }
062:
063: public String[] getParamNames() {
064: insureParsed();
065: return paramNames;
066: }
067:
068: public String[] getTypeDescriptors(CallStack callstack,
069: Interpreter interpreter, String defaultPackage) {
070: if (typeDescriptors != null)
071: return typeDescriptors;
072:
073: insureParsed();
074: String[] typeDesc = new String[numArgs];
075:
076: for (int i = 0; i < numArgs; i++) {
077: BSHFormalParameter param = (BSHFormalParameter) jjtGetChild(i);
078: typeDesc[i] = param.getTypeDescriptor(callstack,
079: interpreter, defaultPackage);
080: }
081:
082: this .typeDescriptors = typeDesc;
083: return typeDesc;
084: }
085:
086: /**
087: Evaluate the types.
088: Note that type resolution does not require the interpreter instance.
089: */
090: public Object eval(CallStack callstack, Interpreter interpreter)
091: throws EvalError {
092: if (paramTypes != null)
093: return paramTypes;
094:
095: insureParsed();
096: Class[] paramTypes = new Class[numArgs];
097:
098: for (int i = 0; i < numArgs; i++) {
099: BSHFormalParameter param = (BSHFormalParameter) jjtGetChild(i);
100: paramTypes[i] = (Class) param.eval(callstack, interpreter);
101: }
102:
103: this.paramTypes = paramTypes;
104:
105: return paramTypes;
106: }
107: }
|