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

Bug 566881

Summary: [15] refactor patterninstanceof for extracting a method gives wrong code
Product: [Eclipse Project] JDT Reporter: Manoj N Palat <manoj.palat>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, jjohnstn, kalyan_prasad, manoj.palat
Version: 4.17   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Manoj N Palat CLA 2020-09-11 02:26:13 EDT
Given:

class X {
	private void foo(Object o) {
		if (o instanceof X x) { // select the entire o instanceof X x
			System.out.println(x.toString());
			x.foo(null);
		}

	}
} 

select the entire o instanceof X x and Refactor->Extract Method 
gives:

class X {
	private void foo(Object o) {
		if (extracted(o)) { // select the entire o instanceof X x
			System.out.println(x.toString());
			x.foo(null);
		}

	}

	private boolean extracted(Object o) {
		return o instanceof X x;
	}
} 

clearly an error at the method call extracted(o)

Y build

Version: 2020-09 (4.17)
Build id: Y20200909-1200
Comment 1 Jeff Johnston CLA 2021-11-09 17:59:48 EST
This no longer occurs.  The Extract Method menu item is not offered for the Pattern instanceof.