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