PageRenderTime 93ms CodeModel.GetById 82ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/bsh/BSHFormalParameters.java

#
Java | 115 lines | 57 code | 18 blank | 40 comment | 9 complexity | e4bc2d98d7523d63eede718945f946a9 MD5 | raw file
  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
 34package bsh;
 35
 36class BSHFormalParameters extends SimpleNode
 37{
 38	private String [] paramNames;
 39	/**
 40		For loose type parameters the paramTypes are null.
 41	*/
 42	// unsafe caching of types
 43	Class [] paramTypes;
 44	int numArgs;
 45	String [] typeDescriptors;
 46
 47	BSHFormalParameters(int id) { super(id); }
 48
 49	void insureParsed() 
 50	{
 51		if ( paramNames != null )
 52			return;
 53
 54		this.numArgs = jjtGetNumChildren();
 55		String [] paramNames = new String[numArgs];
 56
 57		for(int i=0; i<numArgs; i++)
 58		{
 59			BSHFormalParameter param = (BSHFormalParameter)jjtGetChild(i);
 60			paramNames[i] = param.name;
 61		}
 62
 63		this.paramNames = paramNames;
 64	}
 65
 66	public String [] getParamNames() { 
 67		insureParsed();
 68		return paramNames;
 69	}
 70
 71	public String [] getTypeDescriptors( 
 72		CallStack callstack, Interpreter interpreter, String defaultPackage )
 73	{
 74		if ( typeDescriptors != null )
 75			return typeDescriptors;
 76
 77		insureParsed();
 78		String [] typeDesc = new String[numArgs];
 79
 80		for(int i=0; i<numArgs; i++)
 81		{
 82			BSHFormalParameter param = (BSHFormalParameter)jjtGetChild(i);
 83			typeDesc[i] = param.getTypeDescriptor( 
 84				callstack, interpreter, defaultPackage );
 85		}
 86
 87		this.typeDescriptors = typeDesc;
 88		return typeDesc;
 89	}
 90
 91	/**
 92		Evaluate the types.  
 93		Note that type resolution does not require the interpreter instance.
 94	*/
 95	public Object eval( CallStack callstack, Interpreter interpreter )  
 96		throws EvalError
 97	{
 98		if ( paramTypes != null )
 99			return paramTypes;
100
101		insureParsed();
102		Class [] paramTypes = new Class[numArgs];
103
104		for(int i=0; i<numArgs; i++)
105		{
106			BSHFormalParameter param = (BSHFormalParameter)jjtGetChild(i);
107			paramTypes[i] = (Class)param.eval( callstack, interpreter );
108		}
109
110		this.paramTypes = paramTypes;
111
112		return paramTypes;
113	}
114}
115