[jboss-cvs] javassist/src/main/javassist ...
Shigeru Chiba
chiba at is.titech.ac.jp
Thu May 1 06:47:59 EDT 2008
User: chiba
Date: 08/05/01 06:47:59
Modified: src/main/javassist CtClass.java CtBehavior.java
Log:
fixed JASSIST-47 and 60.
Revision Changes Path
1.97 +17 -1 javassist/src/main/javassist/CtClass.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CtClass.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtClass.java,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -b -r1.96 -r1.97
--- CtClass.java 9 Mar 2008 13:07:12 -0000 1.96
+++ CtClass.java 1 May 2008 10:47:59 -0000 1.97
@@ -1216,6 +1216,8 @@
* object in the current directory.
* Once this method is called, further modifications are not
* possible any more.
+ *
+ * @see #debugWriteFile()
*/
public void writeFile()
throws NotFoundException, IOException, CannotCompileException
@@ -1230,6 +1232,7 @@
* possible any more.
*
* @param directoryName it must end without a directory separator.
+ * @see #debugWriteFile(String)
*/
public void writeFile(String directoryName)
throws CannotCompileException, IOException
@@ -1263,9 +1266,22 @@
* This method would be useful for debugging.
*/
public void debugWriteFile() {
+ debugWriteFile(".");
+ }
+
+ /**
+ * Writes a class file as <code>writeFile()</code> does although this
+ * method does not prune or freeze the class after writing the class
+ * file. Note that, once <code>writeFile()</code> or <code>toBytecode()</code>
+ * is called, it cannot be called again since the class is pruned and frozen.
+ * This method would be useful for debugging.
+ *
+ * @param directoryName it must end without a directory separator.
+ */
+ public void debugWriteFile(String directoryName) {
try {
boolean p = stopPruning(true);
- writeFile();
+ writeFile(directoryName);
defrost();
stopPruning(p);
}
1.40 +68 -0 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.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- CtBehavior.java 4 Jan 2008 16:20:25 -0000 1.39
+++ CtBehavior.java 1 May 2008 10:47:59 -0000 1.40
@@ -520,6 +520,74 @@
}
/**
+ * Inserts a new parameter, which becomes the first parameter.
+ */
+ public void insertParameter(CtClass type)
+ throws CannotCompileException
+ {
+ declaringClass.checkModify();
+ String desc = methodInfo.getDescriptor();
+ String desc2 = Descriptor.insertParameter(type, desc);
+ try {
+ addParameter2(Modifier.isStatic(getModifiers()) ? 0 : 1, type, desc);
+ }
+ catch (BadBytecode e) {
+ throw new CannotCompileException(e);
+ }
+
+ methodInfo.setDescriptor(desc2);
+ }
+
+ /**
+ * Appends a new parameter, which becomes the last parameter.
+ */
+ public void addParameter(CtClass type)
+ throws CannotCompileException
+ {
+ declaringClass.checkModify();
+ String desc = methodInfo.getDescriptor();
+ String desc2 = Descriptor.appendParameter(type, desc);
+ int offset = Modifier.isStatic(getModifiers()) ? 0 : 1;
+ try {
+ addParameter2(offset + Descriptor.paramSize(desc), type, desc);
+ }
+ catch (BadBytecode e) {
+ throw new CannotCompileException(e);
+ }
+
+ methodInfo.setDescriptor(desc2);
+ }
+
+ private void addParameter2(int where, CtClass type, String desc)
+ throws BadBytecode
+ {
+ CodeAttribute ca = methodInfo.getCodeAttribute();
+ if (ca != null) {
+ int size = 1;
+ char typeDesc = 'L';
+ int classInfo = 0;
+ if (type.isPrimitive()) {
+ CtPrimitiveType cpt = (CtPrimitiveType)type;
+ size = cpt.getDataSize();
+ typeDesc = cpt.getDescriptor();
+ }
+ else
+ classInfo = methodInfo.getConstPool().addClassInfo(type);
+
+ ca.insertLocalVar(where, size);
+ LocalVariableAttribute va
+ = (LocalVariableAttribute)
+ ca.getAttribute(LocalVariableAttribute.tag);
+ if (va != null)
+ va.shiftIndex(where, size);
+
+ StackMapTable smt = (StackMapTable)ca.getAttribute(StackMapTable.tag);
+ if (smt != null)
+ smt.insertLocal(where, StackMapTable.typeTagOf(typeDesc), classInfo);
+ }
+ }
+
+ /**
* Modifies the method/constructor body.
*
* @param converter specifies how to modify.
More information about the jboss-cvs-commits
mailing list