Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 152004 - [extract method] should declare method static if extracted from anonymous in static method
Summary: [extract method] should declare method static if extracted from anonymous in ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Benjamin Muskalla CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-27 10:28 EDT by Markus Keller CLA
Modified: 2009-08-04 06:42 EDT (History)
2 users (show)

See Also:


Attachments
patch+testcases (7.38 KB, patch)
2009-07-28 16:35 EDT, Benjamin Muskalla CLA
markus.kell.r: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2006-07-27 10:28:53 EDT
I20060725-0800

public class Try {
    public static void main(String[] args) {
        new Runnable() {
            public void run() {
                //extract method on "xx", extract to class Try
                System.out.println("xx");
            }
        };
    }
}

The extracted method is nonstatic, which results in a compile error.
Comment 1 Benjamin Muskalla CLA 2009-07-28 16:35:54 EDT
Created attachment 142821 [details]
patch+testcases

This fixes bugs related to adding static modifiers where neccesarry. In addition it looses the restriction that you cannot extract code from an inner static class to an outer class (see test 1053)
Comment 2 Markus Keller CLA 2009-08-03 13:42:31 EDT
Thanks, released to HEAD.

It's interesting that you test the enclosingBodyDeclaration != null in the while loop, but after the loop you unconditionally access the same variable ;-) I added an instanceof check for added safety.

A problem I saw was that the 'static' modifier in the preview of the dialog was not updated when the user changed the destination. Fixed in ExtractMethodInputPage.
Comment 3 Benjamin Muskalla CLA 2009-08-03 14:53:48 EDT
(In reply to comment #2)
> Thanks, released to HEAD.
> 
> It's interesting that you test the enclosingBodyDeclaration != null in the while
> loop, but after the loop you unconditionally access the same variable ;-) I
> added an instanceof check for added safety.
Four eyes see more then two ;-) I just wonder, this should be flagged by the compiler in my eyes.

> 
> A problem I saw was that the 'static' modifier in the preview of the dialog was
> not updated when the user changed the destination. Fixed in
> ExtractMethodInputPage.
Oh, missed that one. Thanks. I had in mind that I introduced that update but that was for another patch which is not yet attached to any bug ;)
Comment 4 Raksha Vasisht CLA 2009-08-04 04:40:42 EDT
Verified for 3.6 M1 using I20090803-1800