PageRenderTime 48ms CodeModel.GetById 31ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at_build150307/src/edu/vub/at/exceptions/XSymbiosisFailure.java

http://ambienttalk.googlecode.com/
Java | 107 lines | 42 code | 11 blank | 54 comment | 4 complexity | b0a62f4584b8216f752f706263d41e6b MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * XSymbiosisFailure.java created on 13-nov-2006 at 14:35:22
  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.exceptions;
 29
 30import edu.vub.at.eval.Evaluator;
 31import edu.vub.at.objects.ATObject;
 32import edu.vub.at.objects.ATStripe;
 33import edu.vub.at.objects.coercion.NativeStripes;
 34import edu.vub.at.objects.mirrors.Reflection;
 35
 36import java.lang.reflect.Constructor;
 37import java.util.Iterator;
 38import java.util.LinkedList;
 39
 40/**
 41 * An instance of this class is raised whenever a symbiotic method invocation fails due to overloading
 42 * which could not be resolved given the actual arguments.
 43 * 
 44 * @author tvcutsem
 45 */
 46public class XSymbiosisFailure extends InterpreterException {
 47
 48	private static final long serialVersionUID = -4161446826939837849L;
 49
 50	private final String message_;
 51	
 52	/**
 53	 * Reports that an overloaded method could not be resolved to a unique implementation
 54	 * because there are multiple matches.
 55	 * @param symbiont the Java object upon which the overloaded symbiotic invocation failed.
 56	 * @param selector the name of the invoked overloaded method
 57	 * @param choices a linked list of all applicable java.lang.Method objects
 58	 * @param atArgs the actual arguments to the overloaded invocation
 59	 */
 60	public XSymbiosisFailure(Object symbiont, String selector, LinkedList choices, ATObject[] atArgs) throws InterpreterException {
 61		StringBuffer buff = new StringBuffer("Overloaded Java invocation has " + choices.size() + " matches:\n");
 62		buff.append(symbiont.toString() + "." + Reflection.downSelector(selector) + Evaluator.printElements(atArgs, "(",",",")").javaValue);
 63		for (Iterator iter = choices.iterator(); iter.hasNext();) {
 64			buff.append("\n" + iter.next().toString());
 65		}
 66		message_ = buff.toString();
 67	}
 68	
 69	/**
 70	 * Reports that an overloaded method could not be resolved to a unique implementation
 71	 * because there are no matches for any static types.
 72	 * @param symbiont the Java object upon which the overloaded symbiotic invocation failed.
 73	 * @param selector the name of the invoked overloaded method
 74	 * @param atArgs the actual arguments to the overloaded invocation
 75	 */
 76	public XSymbiosisFailure(Object symbiont, String selector, ATObject[] atArgs) throws InterpreterException {
 77		StringBuffer buff = new StringBuffer("Overloaded Java invocation has no matches:\n");
 78		buff.append(symbiont + "." + Reflection.downSelector(selector) + Evaluator.printElements(atArgs, "(",",",")").javaValue);
 79		message_ = buff.toString();
 80	}
 81	
 82	/**
 83	 * Reports that an overloaded constructor could not be resolved to a unique implementation.
 84	 * @param failedClass the Java class whose constructor could not be resolved.
 85	 * @param choices all applicable constructors (may contain null values, corresponding to non-applicable choices)
 86	 * @param numMatchingCtors the number of matching constructors (the number of non-null values in choices)
 87	 */
 88	public XSymbiosisFailure(Class failedClass, Constructor[] choices, ATObject[] atArgs, int numMatchingCtors) throws InterpreterException {
 89		StringBuffer buff = new StringBuffer("Overloaded Java constructor has " + numMatchingCtors + " matches:\n");
 90		buff.append(Evaluator.getSimpleName(failedClass) + ".new"+ Evaluator.printElements(atArgs, "(",",",")").javaValue);
 91		for (int i = 0; i < choices.length; i++) {
 92			if (choices[i] != null) {
 93				buff.append("\n" + choices[i].toString());
 94			}
 95		}
 96		message_ = buff.toString();
 97	}
 98	
 99	public String getMessage() {
100		return message_;
101	}
102	
103	public ATStripe getStripeType() {
104		return NativeStripes._SYMBIOSISFAILURE_;
105	}
106
107}