summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/javassist/compiler/MemberCodeGen.java4
-rw-r--r--src/main/javassist/compiler/MemberResolver.java58
-rw-r--r--src/main/javassist/compiler/TypeChecker.java4
-rw-r--r--tutorial/tutorial2.html2
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) { .. }