True. I can add more of these cases. I will make the guess that extract
method is using the core code of "inline local variable" to remove the
variables it creates by default to maintain value semantic on the
parameters. 
In your case for example IntelliJ cannot inline result1 so extract
method leave your code with an extract temp. 

It complains that "the variable result1 was never used before
modification". What does this mean? Could some IntelliJ people enlighten
us?

I have enhancement request on inline variables.
1) We should have the same option than inline method: all invocations
and remove variable or just the selected one. That way I still can use
the tool on the usage the tool can handle and modify manually the ones
that it cannot handle. 

2) Inline local variable should take into account the scope of the
inlined variable and the scope of each of its assigned value. 

2.1) return variable

private int tk( int i_result , int i_byte0 )
  {
      i_result   = 37 * i_result + (int)i_byte0 ;
      return i_result;
             ^^^^^^^^
  }

I should be able to inline that usage of i_result because there are no
usage after the return. It goes out of scope;

Same thing in

2.2) usage of reassigned variables
    public int testParent ()
    {
        int result = 17;
        int result1 = result;                   <<- useless code
        result1   = 37 * result1 + (int)__byte0 ;
                         ^^^1^^^
        result = result1;
                 ^^^2^^^
        return result  ;
    }

There is no reason not to be able to inline ^^^1^^^. You can see that
the value of result1 is not used anywhere before the second assignment
next line. So it is safe to make it into
    public int testParent ()
    {
        int result = 17;
        int result1;                 
        result1   = 37 * result + (int)__byte0 ;
        result = result1;
                 ^^^2^^^
        return result  ;
    }

Then Inline variable doesn't work on ^^^2^^^

2.3) unused initialization removal
It should also be smart enough to inline declaration and first
assignment if there are no usage in between like in this case result1.
    public int testParent ()
    {
        int result = 17;
        int result1 = 37 * result + (int)__byte0 ;
        ^^^^^^^^^^^
        result = result1;
        return result  ;
    }

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
On Behalf Of Alain Ravet
Sent: Thursday, March 14, 2002 3:32 PM
To: [EMAIL PROTECTED]
Subject: [Eap-list] extract method + inline method adds useless code


After extracting a method, I changed my mind and inlined it back.
The inlining should have cancelled the extraction, but it introduce 1
useless temp variable (see stage 3 below).


stage 1 :

    public int testParent ()
    {
        int result = 17;
        result   = 37 * result + (int)__byte0 ;  <<- extract method
        return result  ;
    }


extract method to :

stage 2
    public int testParent ()
    {
        int result = 17;
        result = tk( result , __byte0 ); <<- inline method
        return result  ;
    }

    private int tk( int i_result , final byte i_byte0 )
    {
        i_result   = 37 * i_result + (int)i_byte0 ;
        return i_result;
    }



inline method to :
stage 3

    public int testParent ()
    {
        int result = 17;
        int result1 = result;                   <<- useless code
        result1   = 37 * result1 + (int)__byte0 ;
        result = result1;
        return result  ;
    }
 
should have been same as stage 1 :

    public int testParent ()
    {
        int result = 17;
        result   = 37 * result + (int)__byte0 ;  <<- extract method
        return result  ;
    }


Alain Ravet

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


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

Reply via email to