PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

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