Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 334480

Summary: [quick fix] create method incorrectly makes static method when called from inner class in static method
Product: [Eclipse Project] JDT Reporter: Micha Riser <eclipse>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.7   
Target Milestone: 3.7 M5   
Hardware: PC   
OS: Linux   
Whiteboard:

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.