[jboss-cvs] javassist/src/main/javassist ...
Shigeru Chiba
chiba at belmont.prod.atl2.jboss.com
Wed Aug 30 12:25:25 EDT 2006
User: chiba
Date: 06/08/30 12:25:25
Modified: src/main/javassist CtBehavior.java CtConstructor.java
ClassMap.java
Log:
a nested ClassMap.
Revision Changes Path
1.32 +4 -7 javassist/src/main/javassist/CtBehavior.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CtBehavior.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtBehavior.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- CtBehavior.java 29 Aug 2006 08:39:32 -0000 1.31
+++ CtBehavior.java 30 Aug 2006 16:25:25 -0000 1.32
@@ -44,10 +44,9 @@
MethodInfo srcInfo = src.methodInfo;
CtClass srcClass = src.getDeclaringClass();
ConstPool cp = declaring.getClassFile2().getConstPool();
- if (map == null)
- map = new ClassMap();
- map.add(srcClass.getName(), declaring.getName());
+ map = new ClassMap(map);
+ map.put(srcClass.getName(), declaring.getName());
try {
boolean patch = false;
CtClass srcSuper = srcClass.getSuperclass();
@@ -60,7 +59,7 @@
if (srcSuperName.equals(CtClass.javaLangObject))
patch = true;
else
- map.add(srcSuperName, destSuperName);
+ map.put(srcSuperName, destSuperName);
}
methodInfo = new MethodInfo(cp, srcInfo.getName(), srcInfo, map);
@@ -356,9 +355,7 @@
{
destClass.checkModify();
- if (map == null)
- map = new ClassMap();
-
+ map = new ClassMap(map);
map.put(srcClass.getName(), destClass.getName());
try {
CodeAttribute cattr = srcInfo.getCodeAttribute();
1.16 +31 -1 javassist/src/main/javassist/CtConstructor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CtConstructor.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtConstructor.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- CtConstructor.java 11 Jan 2006 06:45:54 -0000 1.15
+++ CtConstructor.java 30 Aug 2006 16:25:25 -0000 1.16
@@ -288,8 +288,38 @@
public CtMethod toMethod(String name, CtClass declaring)
throws CannotCompileException
{
+ return toMethod(name, declaring, null);
+ }
+
+ /**
+ * Makes a copy of this constructor and converts it into a method.
+ * The signature of the mehtod is the same as the that of this constructor.
+ * The return type is <code>void</code>. The resulting method must be
+ * appended to the class specified by <code>declaring</code>.
+ * If this constructor is a static initializer, the resulting method takes
+ * no parameter.
+ *
+ * <p>An occurrence of another constructor call <code>this()</code>
+ * or a super constructor call <code>super()</code> is
+ * eliminated from the resulting method.
+ *
+ * <p>The immediate super class of the class declaring this constructor
+ * must be also a super class of the class declaring the resulting method.
+ * If the constructor accesses a field, the class declaring the resulting method
+ * must also declare a field with the same name and type.
+ *
+ * @param name the name of the resulting method.
+ * @param declaring the class declaring the resulting method.
+ * @param map the hash table associating original class names
+ * with substituted names. The original class names will be
+ * replaced while making a copy.
+ * <code>map</code> can be <code>null</code>.
+ */
+ public CtMethod toMethod(String name, CtClass declaring, ClassMap map)
+ throws CannotCompileException
+ {
CtMethod method = new CtMethod(null, declaring);
- method.copy(this, false, null);
+ method.copy(this, false, map);
if (isConstructor()) {
MethodInfo minfo = method.getMethodInfo2();
CodeAttribute ca = minfo.getCodeAttribute();
1.8 +15 -29 javassist/src/main/javassist/ClassMap.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ClassMap.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/ClassMap.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- ClassMap.java 29 Aug 2006 08:39:32 -0000 1.7
+++ ClassMap.java 30 Aug 2006 16:25:25 -0000 1.8
@@ -18,7 +18,7 @@
import javassist.bytecode.Descriptor;
/**
- * A hashtable associating class names with different names.
+ * A hash table associating class names with different names.
*
* <p>This hashtable is used for replacing class names in a class
* definition or a method body. Define a subclass of this class
@@ -45,6 +45,15 @@
* @see CtNewMethod#copy(CtMethod,String,CtClass,ClassMap)
*/
public class ClassMap extends java.util.HashMap {
+ private ClassMap parent;
+
+ /**
+ * Constructs a hash table.
+ */
+ public ClassMap() { parent = null; }
+
+ ClassMap(ClassMap map) { parent = map; }
+
/**
* Maps a class name to another name in this hashtable.
* The names are obtained with calling <code>Class.getName()</code>.
@@ -87,33 +96,6 @@
super.put(oldname2, toJvmName(newname));
}
- /**
- * Maps a class name to another name unless another mapping
- * has been already recorded.
- * This method translates the given class names into the
- * internal form used in the JVM before putting it in
- * the hashtable.
- *
- * <p>If <code>oldname</code> is equivalent to
- * <code>newname</code>, then this method does not
- * perform anything; it does not record the mapping from
- * <code>oldname</code> to <code>newname</code>. See
- * <code>fix</code> method.
- *
- * @param oldname the original class name
- * @param newname the substituted class name.
- * @see #fix(String)
- */
- public void add(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);
}
@@ -129,7 +111,11 @@
* @see #toJavaName(String)
*/
public Object get(Object jvmClassName) {
- return super.get(jvmClassName);
+ Object found = super.get(jvmClassName);
+ if (found == null && parent != null)
+ return parent.get(jvmClassName);
+ else
+ return found;
}
/**
More information about the jboss-cvs-commits
mailing list