/interpreter/tags/at_build150307/src/edu/vub/at/objects/natives/grammar/AGMessageCreation.java

http://ambienttalk.googlecode.com/ · Java · 94 lines · 37 code · 13 blank · 44 comment · 0 complexity · 034397add6a75c2bf561b1b213662f43 MD5 · raw file

  1. /**
  2. * AmbientTalk/2 Project
  3. * AGMessageCreation.java created on 10-aug-2006 at 14:10:17
  4. * (c) Programming Technology Lab, 2006 - 2007
  5. * Authors: Tom Van Cutsem & Stijn Mostinckx
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use,
  11. * copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following
  14. * conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be
  17. * included in all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  21. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  25. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  26. * OTHER DEALINGS IN THE SOFTWARE.
  27. */
  28. package edu.vub.at.objects.natives.grammar;
  29. import edu.vub.at.eval.Evaluator;
  30. import edu.vub.at.exceptions.InterpreterException;
  31. import edu.vub.at.exceptions.XTypeMismatch;
  32. import edu.vub.at.objects.ATContext;
  33. import edu.vub.at.objects.ATObject;
  34. import edu.vub.at.objects.ATTable;
  35. import edu.vub.at.objects.grammar.ATMessageCreation;
  36. import edu.vub.at.objects.grammar.ATSymbol;
  37. import edu.vub.at.objects.natives.NATText;
  38. /**
  39. * @author tvc
  40. *
  41. * The common superclass of AGAsyncMessageCreation and AGMethodInvocationCreation.
  42. * This class serves as a common repository for both kinds of first-class message AG elements.
  43. */
  44. public abstract class AGMessageCreation extends AGExpression implements ATMessageCreation {
  45. protected final ATSymbol selector_;
  46. protected final ATTable arguments_;
  47. public AGMessageCreation(ATSymbol sel, ATTable args) {
  48. selector_ = sel;
  49. arguments_ = args;
  50. }
  51. public ATSymbol base_getSelector() { return selector_; }
  52. public ATTable base_getArguments() { return arguments_; }
  53. public boolean isMessageCreation() {
  54. return true;
  55. }
  56. public ATMessageCreation asMessageCreation() throws XTypeMismatch {
  57. return this;
  58. }
  59. /**
  60. * Quoting a message creation element returns a new quoted message creation element.
  61. */
  62. public ATObject meta_quote(ATContext ctx) throws InterpreterException {
  63. return this.newQuoted(selector_.meta_quote(ctx).asSymbol(),
  64. arguments_.meta_quote(ctx).asTable());
  65. }
  66. public NATText meta_print() throws InterpreterException {
  67. return NATText.atValue(this.getMessageToken() +
  68. selector_.meta_print().javaValue +
  69. Evaluator.printAsList(arguments_).javaValue);
  70. }
  71. /**
  72. * Subclasses must implement this method in order to return a new instance of themselves
  73. * parameterized with their quoted arguments.
  74. */
  75. protected abstract ATObject newQuoted(ATSymbol quotedSel, ATTable quotedArgs);
  76. /**
  77. * Subclasses must implement this method such that the correct messaging token
  78. * can be displayed when printing an AGMessageCreation element.
  79. */
  80. protected abstract String getMessageToken();
  81. }