From 517f6712ff7b833ba4396df8c0ba0c8a32ca1e6d Mon Sep 17 00:00:00 2001 From: chiba Date: Sun, 12 Nov 2006 02:43:15 +0000 Subject: enabled a transformation from a public method call to a private method call by CodeConverter git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@333 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/CodeConverter.java | 4 ++-- src/main/javassist/convert/TransformCall.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/javassist/CodeConverter.java b/src/main/javassist/CodeConverter.java index d8a645ff..1c8cf2f6 100644 --- a/src/main/javassist/CodeConverter.java +++ b/src/main/javassist/CodeConverter.java @@ -228,8 +228,8 @@ public class CodeConverter { int mod1 = origMethod.getModifiers(); int mod2 = substMethod.getModifiers(); - if (Modifier.isPrivate(mod1) != Modifier.isPrivate(mod2) - || Modifier.isStatic(mod1) != Modifier.isStatic(mod2) + if (Modifier.isStatic(mod1) != Modifier.isStatic(mod2) + || (Modifier.isPrivate(mod1) && !Modifier.isPrivate(mod2)) || origMethod.getDeclaringClass().isInterface() != substMethod.getDeclaringClass().isInterface()) throw new CannotCompileException("invoke-type mismatch"); diff --git a/src/main/javassist/convert/TransformCall.java b/src/main/javassist/convert/TransformCall.java index 43508c2f..858b7430 100644 --- a/src/main/javassist/convert/TransformCall.java +++ b/src/main/javassist/convert/TransformCall.java @@ -17,11 +17,13 @@ package javassist.convert; import javassist.CtClass; import javassist.CtMethod; +import javassist.Modifier; import javassist.bytecode.*; public class TransformCall extends Transformer { protected String classname, methodname, methodDescriptor; protected String newClassname, newMethodname; + protected boolean newMethodIsPrivate; /* cache */ protected int newIndex; @@ -43,6 +45,7 @@ public class TransformCall extends Transformer { classname = newClassname = substMethod.getDeclaringClass().getName(); newMethodname = substMethod.getName(); constPool = null; + newMethodIsPrivate = Modifier.isPrivate(substMethod.getModifiers()); } public void initialize(ConstPool cp, CodeAttribute attr) { @@ -79,8 +82,12 @@ public class TransformCall extends Transformer { int ci = cp.addClassInfo(newClassname); if (c == INVOKEINTERFACE) newIndex = cp.addInterfaceMethodrefInfo(ci, nt); - else + else { + if (newMethodIsPrivate && c == INVOKEVIRTUAL) + iterator.writeByte(INVOKESPECIAL, pos); + newIndex = cp.addMethodrefInfo(ci, nt); + } constPool = cp; } -- cgit v1.2.3