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

Bug 413967

Summary: [extract method] Compilation error on extracting to outer type
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: nikolaymetchev
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
Starting point none

Description Noopur Gupta CLA 2013-07-30 04:17:47 EDT
In the given example, perform Refactor > Extract Method after selecting "foo();". Give the destination type as 'C_outer'.
We get compilation error in the extracted method that foo() is undefined for the type C_outer.
-------------------------------------------------
public class C_outer {
	class C_inner {
		void foo() {
		}

		void test() {
			foo(); // extract to method
		}
	}
}
--------------------------- Results in:
public class C_outer {
	class C_inner {
		void foo() {
		}

		void test() {
			extracted(); // extract to method
		}
	}

	public void extracted() {
		foo(); // compilation error here
	}
}
-------------------------------------------------

Same issue with interface methods also with destination type 'I_outer' (>= Java 1.8):

interface I_outer {
	interface I_inner {
		static void foo() {
		}

		default void test() {
			foo(); // extract to method
		}
	}
}

We should check if the code being extracted is accessible from the specified destination type and handle it accordingly.
Comment 1 Nikolay Metchev CLA 2013-09-18 11:06:00 EDT
Created attachment 235603 [details]
Starting point

This contribution complies with http://www.eclipse.org/legal/CoO.php

How about this for a starting point?
Comment 2 Eclipse Genie CLA 2019-09-03 12:35:34 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.