In build 358, if you have a method like this

  private void m1() {
    final int var1 = m3();
    // do stuff 1
    // do stuff 2 using var1
  }

  private int m3() {
    return 42;
  }

and you want to extract the "do stuff 2 using var1" part IDEA generates the
following code by default:

  private void m1() {
    final int var1 = m3();
    // do stuff 1
    m2(var1);
  }


  private void m2(final int var1) {
    // do stuff 2 using var1
  }

If you uncheck var1 from the extract method dialog, it gives

  private void m1() {
    final int var1 = m3();
    // do stuff 1
    m2();
  }


  private void m2() {
    final int var1 = ...;
    // do stuff 2 using var1
  }

But var1 has been declared final -- it's a constant value that the method
should be able determine again for itself.  It would be nice if IDEA could
generate this instead:

  private void m1() {
    final int var1 = m3();
    // do stuff 1
    m2();
  }


  private void m2() {
    final int var1 = m3();
    // do stuff 2 using var1
  }

Of course that would only work if you could guarantee that repeated calls to
m3() would return the same value between calls.  For some things IDEA could
determine that automaticly (a static final field for example, or a constant
number as above), but for others it would require that the programmer tell
IDEA that it's legit to do so.

-Jim Moore

_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://www.intellij.com/mailman/listinfo/eap-features

Reply via email to