summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2007-10-20 17:01:47 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2007-10-20 17:01:47 +0000
commit04bb09167da844dc49516342063a3e642afab7ab (patch)
tree4989c4a3eb7db6badd1f9ae1bc240bb2df929f60
parent1d637574afe2089c8a9c0dfa52ea825721da5ce2 (diff)
downloadjavassist-04bb09167da844dc49516342063a3e642afab7ab.tar.gz
javassist-04bb09167da844dc49516342063a3e642afab7ab.zip
for JASSIST-37 (again)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@412 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r--src/main/javassist/CtField.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/javassist/CtField.java b/src/main/javassist/CtField.java
index efc6b94b..6903daf2 100644
--- a/src/main/javassist/CtField.java
+++ b/src/main/javassist/CtField.java
@@ -436,6 +436,14 @@ public class CtField extends CtMember {
}
/**
+ * Makes an initializer that assigns a constant float value.
+ * The field must be float type.
+ */
+ public static Initializer constant(float l) {
+ return new FloatInitializer(l);
+ }
+
+ /**
* Makes an initializer that assigns a constant double value.
* The field must be double type.
*/
@@ -1173,6 +1181,42 @@ public class CtField extends CtMember {
}
}
+ static class FloatInitializer extends Initializer {
+ float value;
+
+ FloatInitializer(float v) { value = v; }
+
+ void check(String desc) throws CannotCompileException {
+ if (!desc.equals("F"))
+ throw new CannotCompileException("type mismatch");
+ }
+
+ int compile(CtClass type, String name, Bytecode code,
+ CtClass[] parameters, Javac drv)
+ throws CannotCompileException
+ {
+ code.addAload(0);
+ code.addFconst(value);
+ code.addPutfield(Bytecode.THIS, name, Descriptor.of(type));
+ return 3; // stack size
+ }
+
+ int compileIfStatic(CtClass type, String name, Bytecode code,
+ Javac drv) throws CannotCompileException
+ {
+ code.addFconst(value);
+ code.addPutstatic(Bytecode.THIS, name, Descriptor.of(type));
+ return 2; // stack size
+ }
+
+ int getConstantValue(ConstPool cp, CtClass type) {
+ if (type == CtClass.floatType)
+ return cp.addFloatInfo(value);
+ else
+ return 0;
+ }
+ }
+
static class DoubleInitializer extends Initializer {
double value;