4 Replies Latest reply on Sep 3, 2004 1:32 PM by Shigeru Chiba

    Please help with CtConstructor.insertAfter function

    maildt Newbie

      Hi,

      I tried to use CtConstructor.insertAfter() to insert
      a line as the last line of this constructor, but when I
      decompile the new code, it seems not genereating correct
      code.

      Here's the code:

      CtClass clas = ClassPool.getDefault().get("Options");

      CtConstructor[] cstrs = clas.getDeclaredConstructors();

      cstrs[0].insertAfter("{ m_propertyFile = \"my.properties\"; }");
      clas.writeFile();

      Here's the new added code piece:

      public Options(Configuration configuration)
      {
      _L2:
      return;
      m_propertyFile = "my.properties";
      super();

      // old code body start
      ...
      // old code body ends

      Object obj = null;
      m_propertyFile = "myejbgen.properties";
      System.out.println("ok");
      if(true) goto _L2; else goto _L1
      _L1:
      }


      Did I do something wrong here ?
      Any help is appreciated.

      Thanks
      brian