Browse Source

fixed a bug reported as JIRA Javassist-12


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@200 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
chiba 18 years ago
parent
commit
138cb0ca97

+ 2
- 2
src/main/javassist/compiler/MemberCodeGen.java View 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;

+ 37
- 21
src/main/javassist/compiler/MemberResolver.java View 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;

+ 2
- 2
src/main/javassist/compiler/TypeChecker.java View 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))

+ 1
- 1
tutorial/tutorial2.html View 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) { .. }

Loading…
Cancel
Save