From: chiba Date: Tue, 13 Jun 2006 02:33:13 +0000 (+0000) Subject: modified to generate a better comiple error message. X-Git-Tag: rel_3_17_1_ga~349 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=19a7ea2a8507a766a4d4414b05552f07b935de2a;p=javassist.git modified to generate a better comiple error message. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@282 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/compiler/MemberResolver.java b/src/main/javassist/compiler/MemberResolver.java index 2a359bbb..4fcf0a76 100644 --- a/src/main/javassist/compiler/MemberResolver.java +++ b/src/main/javassist/compiler/MemberResolver.java @@ -323,15 +323,28 @@ public class MemberResolver implements TokenId { { String cname = ""; CtClass clazz; - switch (type) { - case CLASS : + if (type == CLASS) { clazz = lookupClassByJvmName(classname); if (dim > 0) cname = clazz.getName(); else return clazz; + } + else + cname = getTypeName(type); - break; + while (dim-- > 0) + cname += "[]"; + + return lookupClass(cname, false); + } + + /* + * type cannot be CLASS + */ + static String getTypeName(int type) throws CompileError { + String cname = ""; + switch (type) { case BOOLEAN : cname = "boolean"; break; @@ -363,10 +376,7 @@ public class MemberResolver implements TokenId { fatal(); } - while (dim-- > 0) - cname += "[]"; - - return lookupClass(cname, false); + return cname; } /** diff --git a/src/main/javassist/compiler/TypeChecker.java b/src/main/javassist/compiler/TypeChecker.java index 4e240881..67e8cef4 100644 --- a/src/main/javassist/compiler/TypeChecker.java +++ b/src/main/javassist/compiler/TypeChecker.java @@ -15,8 +15,6 @@ package javassist.compiler; -import java.util.Arrays; - import javassist.CtClass; import javassist.CtField; import javassist.ClassPool; @@ -48,6 +46,56 @@ public class TypeChecker extends Visitor implements Opcode, TokenId { thisMethod = null; } + /* + * Converts an array of tuples of exprType, arrayDim, and className + * into a String object. + */ + protected static String argTypesToString(int[] types, int[] dims, + String[] cnames) { + StringBuffer sbuf = new StringBuffer(); + sbuf.append('('); + int n = types.length; + if (n > 0) { + int i = 0; + while (true) { + typeToString(sbuf, types[i], dims[i], cnames[i]); + if (++i < n) + sbuf.append(','); + else + break; + } + } + + sbuf.append(')'); + return sbuf.toString(); + } + + /* + * Converts a tuple of exprType, arrayDim, and className + * into a String object. + */ + protected static StringBuffer typeToString(StringBuffer sbuf, + int type, int dim, String cname) { + String s; + if (type == CLASS) + s = MemberResolver.jvmToJavaName(cname); + else if (type == NULL) + s = "Object"; + else + try { + s = MemberResolver.getTypeName(type); + } + catch (CompileError e) { + s = "?"; + } + + sbuf.append(s); + while (dim-- > 0) + sbuf.append("[]"); + + return sbuf; + } + /** * Records the currently compiled method. */ @@ -657,12 +705,14 @@ public class TypeChecker extends Visitor implements Opcode, TokenId { = resolver.lookupMethod(targetClass, thisClass, thisMethod, mname, types, dims, cnames); if (found == null) { + String clazz = targetClass.getName(); + String signature = argTypesToString(types, dims, cnames); String msg; if (mname.equals(MethodInfo.nameInit)) - msg = "constructor not found"; + msg = "cannot find constructor " + clazz + signature; else - msg = "Method " + mname + Arrays.asList(cnames)+ " not found in " - + targetClass.getName(); + msg = mname + signature + " not found in " + clazz; + throw new CompileError(msg); }