[jboss-cvs] javassist/src/main/javassist ...

Shigeru Chiba chiba at is.titech.ac.jp
Sat Oct 20 13:01:47 EDT 2007


  User: chiba   
  Date: 07/10/20 13:01:47

  Modified:    src/main/javassist  CtField.java
  Log:
  for JASSIST-37 (again)
  
  Revision  Changes    Path
  1.24      +44 -0     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.23
  retrieving revision 1.24
  diff -u -b -r1.23 -r1.24
  --- CtField.java	20 Oct 2007 16:47:00 -0000	1.23
  +++ CtField.java	20 Oct 2007 17:01:47 -0000	1.24
  @@ -436,6 +436,14 @@
           }
   
           /**
  +         * 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 @@
           }
       }
   
  +    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;
   
  
  
  



More information about the jboss-cvs-commits mailing list