From 82e918f2e4d778e8de26f76da73275fce226e366 Mon Sep 17 00:00:00 2001 From: chiba Date: Sat, 14 Jul 2007 08:53:57 +0000 Subject: [PATCH] changed CtMethod#copy() and updated related javadoc comments git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@396 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/ClassMap.java | 21 ++++++++++++++++++++- src/main/javassist/CtBehavior.java | 2 +- src/main/javassist/CtConstructor.java | 3 ++- src/main/javassist/CtMethod.java | 3 ++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/javassist/ClassMap.java b/src/main/javassist/ClassMap.java index 98e5cc9e..28f646f0 100644 --- a/src/main/javassist/ClassMap.java +++ b/src/main/javassist/ClassMap.java @@ -82,7 +82,7 @@ public class ClassMap extends java.util.HashMap { * oldname to newname. See * fix method. * - * @param oldname the original class name + * @param oldname the original class name. * @param newname the substituted class name. * @see #fix(String) */ @@ -96,6 +96,25 @@ public class ClassMap extends java.util.HashMap { super.put(oldname2, toJvmName(newname)); } + /** + * Is equivalent to put() except that + * the given mapping is not recorded into the hashtable + * if another mapping from oldname is + * already included. + * + * @param oldname the original class name. + * @param newname the substituted class name. + */ + public void putIfNone(String oldname, String newname) { + if (oldname == newname) + return; + + String oldname2 = toJvmName(oldname); + String s = (String)get(oldname2); + if (s == null) + super.put(oldname2, toJvmName(newname)); + } + protected final void put0(Object oldname, Object newname) { super.put(oldname, newname); } diff --git a/src/main/javassist/CtBehavior.java b/src/main/javassist/CtBehavior.java index 2be691f3..bcae803f 100644 --- a/src/main/javassist/CtBehavior.java +++ b/src/main/javassist/CtBehavior.java @@ -59,7 +59,7 @@ public abstract class CtBehavior extends CtMember { if (srcSuperName.equals(CtClass.javaLangObject)) patch = true; else - map.put(srcSuperName, destSuperName); + map.putIfNone(srcSuperName, destSuperName); } // a stack map table is copied from srcInfo. diff --git a/src/main/javassist/CtConstructor.java b/src/main/javassist/CtConstructor.java index 54c89669..e457eb2e 100644 --- a/src/main/javassist/CtConstructor.java +++ b/src/main/javassist/CtConstructor.java @@ -74,7 +74,8 @@ public final class CtConstructor extends CtBehavior { * with the name of the class and the superclass that * the created constructor is added to. * This is done whichever map is null or not. - * To prevent this replacement, call ClassMap.fix(). + * To prevent this replacement, call ClassMap.fix() + * or put() to explicitly specify replacement. * *

Note: if the .class notation (for example, * String.class) is included in an expression, the diff --git a/src/main/javassist/CtMethod.java b/src/main/javassist/CtMethod.java index 3ed6aa77..0c85783d 100644 --- a/src/main/javassist/CtMethod.java +++ b/src/main/javassist/CtMethod.java @@ -83,7 +83,8 @@ public final class CtMethod extends CtBehavior { * with the name of the class and the superclass that the * created method is added to. * This is done whichever map is null or not. - * To prevent this replacement, call ClassMap.fix(). + * To prevent this replacement, call ClassMap.fix() + * or put() to explicitly specify replacement. * *

Note: if the .class notation (for example, * String.class) is included in an expression, the -- 2.39.5