diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-08-26 18:10:13 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-08-26 18:10:13 +0000 |
commit | 138cb0ca97dde654454bd1f90f35a5ad2380fbc1 (patch) | |
tree | 0f213ae54c6c02cb3105288863ef5523b661096b | |
parent | 57f386402fe50fd195c3469fc008727f1b66980c (diff) | |
download | javassist-138cb0ca97dde654454bd1f90f35a5ad2380fbc1.tar.gz javassist-138cb0ca97dde654454bd1f90f35a5ad2380fbc1.zip |
fixed a bug reported as JIRA Javassist-12
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@200 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | src/main/javassist/compiler/MemberCodeGen.java | 4 | ||||
-rw-r--r-- | src/main/javassist/compiler/MemberResolver.java | 58 | ||||
-rw-r--r-- | src/main/javassist/compiler/TypeChecker.java | 4 | ||||
-rw-r--r-- | tutorial/tutorial2.html | 2 |
4 files changed, 42 insertions, 26 deletions
diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java index ae586d68..aa644bb6 100644 --- a/src/main/javassist/compiler/MemberCodeGen.java +++ b/src/main/javassist/compiler/MemberCodeGen.java @@ -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; diff --git a/src/main/javassist/compiler/MemberResolver.java b/src/main/javassist/compiler/MemberResolver.java index f931c9de..44ab8077 100644 --- a/src/main/javassist/compiler/MemberResolver.java +++ b/src/main/javassist/compiler/MemberResolver.java @@ -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; diff --git a/src/main/javassist/compiler/TypeChecker.java b/src/main/javassist/compiler/TypeChecker.java index 56417922..452edaa7 100644 --- a/src/main/javassist/compiler/TypeChecker.java +++ b/src/main/javassist/compiler/TypeChecker.java @@ -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)) diff --git a/tutorial/tutorial2.html b/tutorial/tutorial2.html index 31df6720..50ee8ec0 100644 --- a/tutorial/tutorial2.html +++ b/tutorial/tutorial2.html @@ -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) { .. } |