PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/bsh/BSHVariableDeclarator.java

#
Java | 96 lines | 28 code | 10 blank | 58 comment | 6 complexity | 62f7639fb3f97a5a8cb5f1c8bf237bb4 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. /**
  35. name [ = initializer ]
  36. evaluate name and return optional initializer
  37. */
  38. class BSHVariableDeclarator extends SimpleNode
  39. {
  40. // The token.image text of the name... never changes.
  41. public String name;
  42. BSHVariableDeclarator(int id) { super(id); }
  43. /**
  44. Evaluate the optional initializer value.
  45. (The name was set at parse time.)
  46. A variable declarator can be evaluated with or without preceding
  47. type information. Currently the type info is only used by array
  48. initializers in the case where there is no explicitly declared type.
  49. @param typeNode is the BSHType node. Its info is passed through to any
  50. variable intializer children for the case where the array initializer
  51. does not declare the type explicitly. e.g.
  52. int [] a = { 1, 2 };
  53. typeNode may be null to indicate no type information available.
  54. */
  55. public Object eval(
  56. BSHType typeNode, CallStack callstack, Interpreter interpreter)
  57. throws EvalError
  58. {
  59. // null value means no value
  60. Object value = null;
  61. if ( jjtGetNumChildren() > 0 )
  62. {
  63. SimpleNode initializer = (SimpleNode)jjtGetChild(0);
  64. /*
  65. If we have type info and the child is an array initializer
  66. pass it along... Else use the default eval style.
  67. (This allows array initializer to handle the problem...
  68. allowing for future enhancements in loosening types there).
  69. */
  70. if ( (typeNode != null)
  71. && initializer instanceof BSHArrayInitializer
  72. )
  73. value = ((BSHArrayInitializer)initializer).eval(
  74. typeNode.getBaseType(), typeNode.getArrayDims(),
  75. callstack, interpreter);
  76. else
  77. value = initializer.eval( callstack, interpreter);
  78. }
  79. if ( value == Primitive.VOID )
  80. throw new EvalError("Void initializer.", this, callstack );
  81. return value;
  82. }
  83. public String toString() { return "BSHVariableDeclarator "+name; }
  84. }