PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
28package edu.vub.at.objects.natives.grammar;
29
30import edu.vub.at.eval.Evaluator;
31import edu.vub.at.exceptions.InterpreterException;
32import edu.vub.at.exceptions.XTypeMismatch;
33import edu.vub.at.objects.ATContext;
34import edu.vub.at.objects.ATObject;
35import edu.vub.at.objects.ATTable;
36import edu.vub.at.objects.grammar.ATMessageCreation;
37import edu.vub.at.objects.grammar.ATSymbol;
38import edu.vub.at.objects.natives.NATText;
39
40/**
41 * @author tvc
42 *
43 * The common superclass of AGAsyncMessageCreation and AGMethodInvocationCreation.
44 * This class serves as a common repository for both kinds of first-class message AG elements.
45 */
46public abstract class AGMessageCreation extends AGExpression implements ATMessageCreation {
47
48	protected final ATSymbol selector_;
49	protected final ATTable arguments_;
50	
51	public AGMessageCreation(ATSymbol sel, ATTable args) {
52		selector_ = sel;
53		arguments_ = args;
54	}
55	
56	public ATSymbol base_getSelector() { return selector_; }
57
58	public ATTable base_getArguments() { return arguments_; }
59
60	public boolean isMessageCreation() {
61   	    return true;
62    }
63	
64	public ATMessageCreation asMessageCreation() throws XTypeMismatch {
65		return this;
66	}
67	
68	/**
69	 * Quoting a message creation element returns a new quoted message creation element.
70	 */
71	public ATObject meta_quote(ATContext ctx) throws InterpreterException {
72		return this.newQuoted(selector_.meta_quote(ctx).asSymbol(),
73				             arguments_.meta_quote(ctx).asTable());
74	}
75	
76	public NATText meta_print() throws InterpreterException {
77		return NATText.atValue(this.getMessageToken() +
78				               selector_.meta_print().javaValue +
79				               Evaluator.printAsList(arguments_).javaValue);
80	}
81	
82	/**
83	 * Subclasses must implement this method in order to return a new instance of themselves
84	 * parameterized with their quoted arguments.
85	 */
86	protected abstract ATObject newQuoted(ATSymbol quotedSel, ATTable quotedArgs);
87	
88	/**
89	 * Subclasses must implement this method such that the correct messaging token
90	 * can be displayed when printing an AGMessageCreation element.
91	 */
92	protected abstract String getMessageToken();
93	
94}