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 SameTypeSignatureException} is thrown when two or more overload handlers 22 * have the same type signature. 23 * 24 * <p>Compared are the arguments' types of two overload handlers. This is mostly done 25 * using the {@link OverloadHandler#isMoreExplicit} method. 26 * 27 * @author Simon Wacker 28 */ 29 class org.as2lib.env.overload.SameTypeSignatureException extends OverloadException { 30 31 /** Exception printed as string */ 32 private var asString:String; 33 34 /** Arguments used by overloading */ 35 private var overloadArguments:Array; 36 37 /** Handlers that where available by the unknown overloadHandler */ 38 private var overloadHandlers:Array; 39 40 /** The object on which the overload should have taken place. */ 41 private var overloadTarget; 42 43 /** The method that performs the overloading. */ 44 private var overloadedMethod:Function; 45 46 /** 47 * Constructs a new {@code SameTypeSignatureException} instance. 48 * 49 * @param message the message of the exception 50 * @param thrower the object whose method threw the exception 51 * @param args the arguments of the method that threw the exception 52 * @param overloadTarget the target object the method should be invoked on / on 53 * which the overload is performed 54 * @param overloadedMethod the method that is overloaded 55 * @param overloadArguments the real arguments used to perform the overloading 56 * @param overloadHandlers an array containing {@code OverloadHandler} instances 57 * that have the same type signature 58 */ 59 public function SameTypeSignatureException(message:String, thrower, args:Array, overloadTarget, overloadedMethod:Function, overloadArguments:Array, overloadHandlers:Array) { 60 super (message, thrower, args); 61 this.overloadTarget = overloadTarget; 62 this.overloadedMethod = overloadedMethod; 63 this.overloadArguments = overloadArguments; 64 this.overloadHandlers = overloadHandlers; 65 } 66 67 /** 68 * Returns a well formatted informative string representation of this exception. 69 * 70 * @return the string representation of this exception 71 */ 72 private function doToString(Void):String { 73 // The resulting string gets constructed lazily and gets stored once it has been generated. 74 // It would take unnecessary much time to generate the string representation if you'd catch 75 // it and it would never get displayed. 76 if (!asString) { 77 asString = message; 78 var info:Array = ReflectUtil.getTypeAndMethodInfo(overloadTarget, overloadedMethod); 79 asString += "\n Overloaded Method: "; 80 asString += info[0] == null ? "[unknown]" : (info[0] ? "static " : ""); 81 asString += info[1] == null ? "[unknown]" : info[1]; 82 asString += "." + (info[2] == null ? "[unknown]" : info[2]); 83 asString += "\n Used Arguments[" + overloadArguments.length + "]: "; 84 for (var i:Number = 0; i < overloadArguments.length; i++) { 85 if (i != 0) { 86 asString += ", "; 87 } 88 asString += overloadArguments[i]; 89 } 90 asString += "\n Used Handlers: "; 91 for(var i:Number = 0; i < overloadHandlers.length; i++) { 92 asString += "\n "+overloadHandlers[i].toString(); 93 } 94 } 95 return asString; 96 } 97 98 }