PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 106 lines | 48 code | 10 blank | 48 comment | 2 complexity | 3886c2e3638bfb0eb1b555eec32459b4 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package bsh;
  34. public class DelayedEvalBshMethod extends BshMethod
  35. {
  36. String returnTypeDescriptor;
  37. BSHReturnType returnTypeNode;
  38. String [] paramTypeDescriptors;
  39. BSHFormalParameters paramTypesNode;
  40. // used for the delayed evaluation...
  41. transient CallStack callstack;
  42. transient Interpreter interpreter;
  43. /**
  44. This constructor is used in class generation. It supplies String type
  45. descriptors for return and parameter class types and allows delay of
  46. the evaluation of those types until they are requested. It does this
  47. by holding BSHType nodes, as well as an evaluation callstack, and
  48. interpreter which are called when the class types are requested.
  49. */
  50. /*
  51. Note: technically I think we could get by passing in only the
  52. current namespace or perhaps BshClassManager here instead of
  53. CallStack and Interpreter. However let's just play it safe in case
  54. of future changes - anywhere you eval a node you need these.
  55. */
  56. DelayedEvalBshMethod(
  57. String name,
  58. String returnTypeDescriptor, BSHReturnType returnTypeNode,
  59. String [] paramNames,
  60. String [] paramTypeDescriptors, BSHFormalParameters paramTypesNode,
  61. BSHBlock methodBody,
  62. NameSpace declaringNameSpace, Modifiers modifiers,
  63. CallStack callstack, Interpreter interpreter
  64. ) {
  65. super( name, null/*returnType*/, paramNames, null/*paramTypes*/,
  66. methodBody, declaringNameSpace, modifiers );
  67. this.returnTypeDescriptor = returnTypeDescriptor;
  68. this.returnTypeNode = returnTypeNode;
  69. this.paramTypeDescriptors = paramTypeDescriptors;
  70. this.paramTypesNode = paramTypesNode;
  71. this.callstack = callstack;
  72. this.interpreter = interpreter;
  73. }
  74. public String getReturnTypeDescriptor() { return returnTypeDescriptor; }
  75. public Class getReturnType()
  76. {
  77. if ( returnTypeNode == null )
  78. return null;
  79. // BSHType will cache the type for us
  80. try {
  81. return returnTypeNode.evalReturnType( callstack, interpreter );
  82. } catch ( EvalError e ) {
  83. throw new InterpreterError("can't eval return type: "+e);
  84. }
  85. }
  86. public String [] getParamTypeDescriptors() { return paramTypeDescriptors; }
  87. public Class [] getParameterTypes()
  88. {
  89. // BSHFormalParameters will cache the type for us
  90. try {
  91. return (Class [])paramTypesNode.eval( callstack, interpreter );
  92. } catch ( EvalError e ) {
  93. throw new InterpreterError("can't eval param types: "+e);
  94. }
  95. }
  96. }