Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 416992 - [1.8][quick assist] Convert to 'if-!-return' not offered in lambda expression
Summary: [1.8][quick assist] Convert to 'if-!-return' not offered in lambda expression
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.4 M7   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 405305
  Show dependency tree
 
Reported: 2013-09-11 05:47 EDT by Noopur Gupta CLA
Modified: 2014-04-10 15:56 EDT (History)
4 users (show)

See Also:


Attachments
Patch + Tests (22.69 KB, patch)
2013-09-18 08:15 EDT, Noopur Gupta CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2013-09-11 05:47:34 EDT
The quick assist (Convert to 'if-!-return') is not offered in a lambda body at valid 'if' locations. Examples:

package misc.test;

@FunctionalInterface
interface A {
	void run(int n);
}

@FunctionalInterface
interface B {
	A foo(int x);
}

public class Test {
	A fi0 = (n) -> {
		if (n == 0) {	// [1]
			System.out.println(n);
			return;
		}
	};
	
	int fun1(int a, int b) {
		A fi2 = (n) -> {
			if (a == b) {	// [2]
				System.out.println(n);
				return;
			}
		};
		return a + b;
	}

	A fun2(int a, int b) {
		return (n) -> {
			if (a == b) {	// [3]
				System.out.println(n);
				return;
			}
		};
	}

	int fun3(int a, int b) {
		B fi3 = (x) -> (n) -> {
			if (a == b) {	// [4]
				System.out.println(a);
				return;
			}
		};
		return a + b;
	}
}
Comment 1 Noopur Gupta CLA 2013-09-18 08:15:15 EDT
Created attachment 235599 [details]
Patch + Tests

Updated the quick assist to handle 'if' in lambda body and added tests.
Markus, please have a look.
Comment 2 Noopur Gupta CLA 2014-04-02 04:51:35 EDT
Released in master after feedback from Manju:

http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fc0ad659419fa661152a0c0105211c1f1fca2167