Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334480 - [quick fix] create method incorrectly makes static method when called from inner class in static method
Summary: [quick fix] create method incorrectly makes static method when called from in...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.7 M5   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-16 09:30 EST by Micha Riser CLA
Modified: 2011-01-17 09:56 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Micha Riser CLA 2011-01-16 09:30:22 EST
Build Identifier: M20100909-0800

Consider Following Java class 'Foo'

public class Foo {

  public static void bar(final Foo f) {
    new Object() {
      
      void foo() {
        
        f.foobar(); // invoke quick fix here
        
      }
      
    };
  }
  
}

When you execute the quick fix "Create method 'foobar()' in type 'Foo'", eclipse makes a static method in Foo:

  protected static void foobar() {
    // TODO Auto-generated method stub
    
  }
  
A non-static method would be correct as we are invoking foobar explicitly on an instance of Foo. So the correct method in Foo would be

  protected void foobar() {
    // TODO Auto-generated method stub
    
  }

Note: If bar is non-static, the correct method is already made by the quick fix.

Reproducible: Always

Steps to Reproduce:
1. Create class Foo as given in the description
2. Invoke the create method quick fix
Comment 1 Markus Keller CLA 2011-01-17 09:56:31 EST
Fixed in HEAD of NewMethodCorrectionProposal and UnresolvedMethodsQuickFixTest.