title: Selecting and modifying `if` statement with ASM
body: <p>I want to update <code>if</code> statement in already existing class on particular line without changing the whole method.</p>
  
  <p>Here is the target code (names of classes, methods and some code changed because they're not relevant):</p>
  
  <pre><code>public class Target extends Something {
     public Target(){
          super();
          //some code...
     }
  
      public Result targetMethod(Data firstPar, Data secondPar){
          if(someStatement()) {
              return Result.FAIL;
          } else {
              if(firstPar.check()){ //here is the line I want to change
                   firstPar.doSomething()
              }
              secondPar.doSomething();
              return Result.SUCCESS;
          }
  
      }
  }
  </code></pre>
  
  <p>In this code I want to change <code>if(firstPar.check())</code> to something like this:</p>
  
  <pre><code>if(firstPar.check() &amp;&amp; !Utilities.someOtherCheck(firstPar, secondPar))
  </code></pre>
  
  <p>Here is the way I tried to solve this:</p>
  
  <pre><code>ClassNode node = new ClassNode();
  ClassReader reader = new ClassReader(bytes); //bytes - original target class
  reader.accept(node, 0);
  ClassWriter cw = new ClassWriter(0);
  node.accept(cw);
  MethodVisitor visitor = cw.visitMethod(ACC_PUBLIC, "targetMethod", "&lt;it's signature&gt;", null, null);
  visitor.visitCode();
  //No idea what to do next
  </code></pre>
  
  <p>Things I don't understand:</p>
  
  <ol>
  <li><p>How do I properly choose a line in MethodVisitor?</p></li>
  <li><p>How do I change only a half of the <code>if</code> statement? </p></li>
  <li><p>How do I get bytecode of the new class (which will be generated
  after we change target class)?</p></li>
  </ol>
  
  <p>It would be nice if you could provide some kind of example code.</p>
  
  <p>Thanks!</p>