]> source.dussan.org Git - javassist.git/commitdiff
modified to generate a better comiple error message.
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 13 Jun 2006 02:33:13 +0000 (02:33 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 13 Jun 2006 02:33:13 +0000 (02:33 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@282 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/compiler/MemberResolver.java
src/main/javassist/compiler/TypeChecker.java

index 2a359bbbf25ba872d267da8538d97ec3479fd5ca..4fcf0a76ec9a5d551a0098767e7cbc08a0980444 100644 (file)
@@ -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;
     }
 
     /**
index 4e2408815a80ba8e5541c046a9c7f6b4ee4ff8fc..67e8cef4d5d2e7e09900b1921c09097dafba02f7 100644 (file)
@@ -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);
         }