diff options
Diffstat (limited to 'src/main/javassist/compiler/MemberCodeGen.java')
-rw-r--r-- | src/main/javassist/compiler/MemberCodeGen.java | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java index c35765ef..e8c5ba3b 100644 --- a/src/main/javassist/compiler/MemberCodeGen.java +++ b/src/main/javassist/compiler/MemberCodeGen.java @@ -308,7 +308,12 @@ public class MemberCodeGen extends CodeGen { throw new CompileError("bad method"); } - // atMethodCallCore() is also called by doit() in NewExpr.ProceedForNew + /* + * atMethodCallCore() is also called by doit() in NewExpr.ProceedForNew + * + * @param targetClass the class at which method lookup starts. + * @param found not null if the method look has been already done. + */ public void atMethodCallCore(CtClass targetClass, String mname, ASTList args, boolean isStatic, boolean isSpecial, int aload0pos, MemberResolver.Method found) @@ -358,8 +363,10 @@ public class MemberCodeGen extends CodeGen { } else if ((acc & AccessFlag.PRIVATE) != 0) { isSpecial = true; - if (declClass != targetClass) - throw new CompileError("Method " + mname + "is private"); + String orgName = mname; + mname = getAccessiblePrivate(mname, declClass); + if (mname == null) + throw new CompileError("Method " + orgName + " is private"); } boolean popTarget = false; @@ -392,6 +399,28 @@ public class MemberCodeGen extends CodeGen { setReturnType(desc, isStatic, popTarget); } + protected String getAccessiblePrivate(String methodName, + CtClass declClass) { + if (declClass == thisClass) + return methodName; + else if (isEnclosing(declClass, thisClass)) + return null; + else + return null; // cannot access this private method. + } + + private boolean isEnclosing(CtClass outer, CtClass inner) { + try { + while (inner != null) { + inner = inner.getDeclaringClass(); + if (inner == outer) + return true; + } + } + catch (NotFoundException e) {} + return false; + } + public int getMethodArgsLength(ASTList args) { return ASTList.length(args); } |