]> source.dussan.org Git - javassist.git/commitdiff
fixed a bug reported as JIRA Javassist-12
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 26 Aug 2005 18:10:13 +0000 (18:10 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Fri, 26 Aug 2005 18:10:13 +0000 (18:10 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@200 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/compiler/MemberCodeGen.java
src/main/javassist/compiler/MemberResolver.java
src/main/javassist/compiler/TypeChecker.java
tutorial/tutorial2.html

index ae586d685ed25032e6f41c7d591ed52957b61ebe..aa644bb62b997b9a27cf69ca08a39dfe2adee831 100644 (file)
@@ -489,8 +489,8 @@ public class MemberCodeGen extends CodeGen {
         int count = bytecode.getStackDepth() - stack + 1;
 
         if (found == null)
-            found = resolver.lookupMethod(targetClass, thisMethod, mname,
-                                          types, dims, cnames, false);
+            found = resolver.lookupMethod(targetClass, thisClass, thisMethod,
+                                          mname, types, dims, cnames);
 
         if (found == null) {
             String msg;
index f931c9de40b0cc0e86e9c5624a7cd004b7f7d6e5..44ab8077cf3f54fb948ab217d8d3a11373bdbfc3 100644 (file)
@@ -70,26 +70,39 @@ public class MemberResolver implements TokenId {
         }
     }
 
-    public Method lookupMethod(CtClass clazz, MethodInfo current,
-                               String methodName,
-                               int[] argTypes, int[] argDims,
-                               String[] argClassNames, boolean onlyExact)
+    public Method lookupMethod(CtClass clazz, CtClass currentClass, MethodInfo current,
+                                String methodName,
+                                int[] argTypes, int[] argDims,
+                                String[] argClassNames)
         throws CompileError
     {
         Method maybe = null;
-
         // to enable the creation of a recursively called method
-        if (current != null)
+        if (current != null && clazz == currentClass)
             if (current.getName().equals(methodName)) {
                 int res = compareSignature(current.getDescriptor(),
                                            argTypes, argDims, argClassNames);
                 Method r = new Method(clazz, current);
                 if (res == YES)
                     return r;
-                else if (res == MAYBE && maybe == null)
+                else if (res == MAYBE)
                     maybe = r;
             }
 
+        Method m = lookupMethod(clazz, methodName, argTypes, argDims,
+                                argClassNames, maybe != null);
+        if (m != null)
+            return m;
+        else
+            return maybe;
+    }
+
+    private Method lookupMethod(CtClass clazz, String methodName,
+                               int[] argTypes, int[] argDims,
+                               String[] argClassNames, boolean onlyExact)
+        throws CompileError
+    {
+        Method maybe = null;
         List list = clazz.getClassFile2().getMethods();
         int n = list.size();
         for (int i = 0; i < n; ++i) {
@@ -97,20 +110,26 @@ public class MemberResolver implements TokenId {
             if (minfo.getName().equals(methodName)) {
                 int res = compareSignature(minfo.getDescriptor(),
                                            argTypes, argDims, argClassNames);
-                Method r = new Method(clazz, minfo);
-                if (res == YES)
-                    return r;
-                else if (res == MAYBE && maybe == null)
-                    maybe = r;
+                if (res != NO) {
+                    Method r = new Method(clazz, minfo);
+                    if (res == YES)
+                        return r;
+                    else if (maybe == null)
+                        maybe = r;
+                }
             }
         }
 
+        if (onlyExact)
+            maybe = null;
+        else
+            onlyExact = maybe != null;
+
         try {
             CtClass pclazz = clazz.getSuperclass();
             if (pclazz != null) {
-                Method r = lookupMethod(pclazz, null, methodName, argTypes,
-                                        argDims, argClassNames,
-                                        (onlyExact || maybe != null));
+                Method r = lookupMethod(pclazz, methodName, argTypes,
+                                        argDims, argClassNames, onlyExact);
                 if (r != null)
                     return r;
             }
@@ -123,19 +142,16 @@ public class MemberResolver implements TokenId {
                 CtClass[] ifs = clazz.getInterfaces();
                 int size = ifs.length;
                 for (int i = 0; i < size; ++i) {
-                    Method r = lookupMethod(ifs[i], null, methodName,
+                    Method r = lookupMethod(ifs[i], methodName,
                                             argTypes, argDims, argClassNames,
-                                            (onlyExact || maybe != null));
+                                            onlyExact);
                     if (r != null)
                         return r;
                 }
             }
             catch (NotFoundException e) {}
 
-        if (onlyExact)
-            return null;
-        else
-            return maybe;
+        return maybe;
     }
 
     private static final int YES = 2;
index 5641792288f1518f14df947edb0e281bbf670eba..452edaa7eb8ffc79a848a4ddf5d2a685be847ccc 100644 (file)
@@ -652,8 +652,8 @@ public class TypeChecker extends Visitor implements Opcode, TokenId {
         atMethodArgs(args, types, dims, cnames);
 
         MemberResolver.Method found
-            = resolver.lookupMethod(targetClass, thisMethod, mname,
-                                    types, dims, cnames, false);
+            = resolver.lookupMethod(targetClass, thisClass, thisMethod,
+                                    mname, types, dims, cnames);
         if (found == null) {
             String msg;
             if (mname.equals(MethodInfo.nameInit))
index 31df672057b9114b1b64ce7fac9a35e41e246d56..50ee8ec030d31723e554e8c9a4e122ce3b8d0429 100644 (file)
@@ -1586,7 +1586,7 @@ have the same name but take different parameter lists.
 <ul><pre>
 class A {} 
 class B extends A {} 
-class C extends C {} 
+class C extends B {} 
 
 class X { 
     void foo(A a) { .. }