[jboss-cvs] javassist/src/main/javassist ...
Shigeru Chiba
chiba at is.titech.ac.jp
Sat Oct 20 12:47:00 EDT 2007
User: chiba
Date: 07/10/20 12:47:00
Modified: src/main/javassist CtClassType.java CtField.java
CtClass.java
Log:
for JASSIST-37
Revision Changes Path
1.62 +1 -0 javassist/src/main/javassist/CtClassType.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CtClassType.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtClassType.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -b -r1.61 -r1.62
--- CtClassType.java 12 Jul 2007 09:52:24 -0000 1.61
+++ CtClassType.java 20 Oct 2007 16:47:00 -0000 1.62
@@ -1146,6 +1146,7 @@
init = f.getInit();
if (init != null) {
+ init.check(f.getSignature());
int mod = f.getModifiers();
if (Modifier.isStatic(mod) && Modifier.isFinal(mod))
try {
1.23 +20 -19 javassist/src/main/javassist/CtField.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CtField.java
===================================================================
RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtField.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- CtField.java 8 Jun 2007 13:32:10 -0000 1.22
+++ CtField.java 20 Oct 2007 16:47:00 -0000 1.23
@@ -413,13 +413,21 @@
public static abstract class Initializer {
/**
* Makes an initializer that assigns a constant integer value.
- * The field must be integer type.
+ * The field must be integer, short, char, or byte type.
*/
public static Initializer constant(int i) {
return new IntInitializer(i);
}
/**
+ * Makes an initializer that assigns a constant boolean value.
+ * The field must be boolean type.
+ */
+ public static Initializer constant(boolean b) {
+ return new IntInitializer(b ? 1 : 0);
+ }
+
+ /**
* Makes an initializer that assigns a constant long value.
* The field must be long type.
*/
@@ -751,7 +759,7 @@
// Check whether this initializer is valid for the field type.
// If it is invaild, this method throws an exception.
- void check(CtClass type) throws CannotCompileException {}
+ void check(String desc) throws CannotCompileException {}
// produce codes for initialization
abstract int compile(CtClass type, String name, Bytecode code,
@@ -1100,8 +1108,9 @@
IntInitializer(int v) { value = v; }
- void check(CtClass type) throws CannotCompileException {
- if (type != CtClass.intType)
+ void check(String desc) throws CannotCompileException {
+ char c = desc.charAt(0);
+ if (c != 'I' && c != 'S' && c != 'B' && c != 'C' && c != 'Z')
throw new CannotCompileException("type mismatch");
}
@@ -1124,10 +1133,7 @@
}
int getConstantValue(ConstPool cp, CtClass type) {
- if (type == CtClass.intType)
return cp.addIntegerInfo(value);
- else
- return 0;
}
}
@@ -1136,8 +1142,8 @@
LongInitializer(long v) { value = v; }
- void check(CtClass type) throws CannotCompileException {
- if (type != CtClass.longType)
+ void check(String desc) throws CannotCompileException {
+ if (!desc.equals("J"))
throw new CannotCompileException("type mismatch");
}
@@ -1172,8 +1178,8 @@
DoubleInitializer(double v) { value = v; }
- void check(CtClass type) throws CannotCompileException {
- if (type != CtClass.doubleType)
+ void check(String desc) throws CannotCompileException {
+ if (!desc.equals("D"))
throw new CannotCompileException("type mismatch");
}
@@ -1208,11 +1214,6 @@
StringInitializer(String v) { value = v; }
- void check(CtClass type) throws CannotCompileException {
- if (!type.getName().equals(javaLangString))
- throw new CannotCompileException("type mismatch");
- }
-
int compile(CtClass type, String name, Bytecode code,
CtClass[] parameters, Javac drv)
throws CannotCompileException
@@ -1278,8 +1279,8 @@
MultiArrayInitializer(CtClass t, int[] d) { type = t; dim = d; }
- void check(CtClass type) throws CannotCompileException {
- if (!type.isArray())
+ void check(String desc) throws CannotCompileException {
+ if (desc.charAt(0) != '[')
throw new CannotCompileException("type mismatch");
}
1.94 +5 -0 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.93
retrieving revision 1.94
diff -u -b -r1.93 -r1.94
--- CtClass.java 30 Sep 2007 15:33:10 -0000 1.93
+++ CtClass.java 20 Oct 2007 16:47:00 -0000 1.94
@@ -898,6 +898,11 @@
* <p>Here, the type of variable <code>cc</code> is <code>CtClass</code>.
* The type of <code>f</code> is <code>CtField</code>.
*
+ * <p>Note: do not change the modifier of the field
+ * (in particular, do not add or remove <code>static</code>
+ * to/from the modifier)
+ * after it is added to the class by <code>addField()</code>.
+ *
* @param init an expression for the initial value.
*
* @see javassist.CtField.Initializer#byExpr(String)
More information about the jboss-cvs-commits
mailing list