1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.env.overload.OverloadException; 18 import org.as2lib.env.reflect.ReflectUtil; 19 20 /** 21 * {@code UnknownOverloadHandlerException} will be thrown if no appropriate overload 22 * handler for a list of real arguments could be found. 23 * 24 * <p>Whether an overload handler matches a given list of real arguments is determined 25 * by the {@link OverloadHandler#matches} method. 26 * 27 * @author Simon Wacker 28 * @author Martin Heidegger 29 */ 30 class org.as2lib.env.overload.UnknownOverloadHandlerException extends OverloadException { 31 32 /** Exception printed as string */ 33 private var asString:String; 34 35 /** Arguments used by overloading */ 36 private var overloadArguments:Array; 37 38 /** Handlers that where available by the unknown overloadHandler */ 39 private var overloadHandlers:Array; 40 41 /** The object on which the overload should have taken place. */ 42 private var overloadTarget; 43 44 /** The method that performs the overloading. */ 45 private var overloadedMethod:Function; 46 47 /** 48 * Constructs a new {@code UnknownOverloadHandlerException} instance. 49 * 50 * @param message the message of the exception 51 * @param thrower the object whose method threw the exception 52 * @param args the arguments of the method that threw the exception 53 * @param overloadTarget the target object the method should be invoked on / on 54 * which the overload is performed 55 * @param overloadedMethod the method that is overloaded 56 * @param overloadArguments the real arguments used to perform the overloading 57 * @param overloadHandlers an array containing all {@code OverloadHandler} instances 58 * that do not match the overload arguments 59 */ 60 public function UnknownOverloadHandlerException(message:String, thrower, args:Array, overloadTarget, overloadedMethod:Function, overloadArguments:Array, overloadHandlers:Array) { 61 super (message, thrower, args); 62 this.overloadTarget = overloadTarget; 63 this.overloadedMethod = overloadedMethod; 64 this.overloadArguments = overloadArguments; 65 this.overloadHandlers = overloadHandlers; 66 } 67 68 /** 69 * Returns a well formatted informative string representation of this exception. 70 * 71 * @return the string representation of this exception 72 */ 73 private function doToString(Void):String { 74 // The resulting string gets constructed lazily and gets stored once it has been generated. 75 // It would take unnecessary much time to generate the string representation if you'd catch 76 // it and it would never get displayed. 77 if (!asString) { 78 asString = message; 79 var info:Array = ReflectUtil.getTypeAndMethodInfo(overloadTarget, overloadedMethod); 80 asString += "\n Overloaded Method: "; 81 asString += info[0] == null ? "[unknown]" : (info[0] ? "static " : ""); 82 asString += info[1] == null ? "[unknown]" : info[1]; 83 asString += "." + (info[2] == null ? "[unknown]" : info[2]); 84 asString += "\n Used Arguments["+overloadArguments.length+"]: "; 85 for (var i:Number = 0; i < overloadArguments.length; i++) { 86 if (i != 0) { 87 asString += ", "; 88 } 89 asString += overloadArguments[i]; 90 } 91 asString += "\n Used Handlers: "; 92 for(var i:Number = 0; i < overloadHandlers.length; i++) { 93 asString += "\n "+overloadHandlers[i].toString(); 94 } 95 } 96 return asString; 97 } 98 99 }