Bug 479030 - Ctrl+2, l does not work for Optional without the import
Summary: Ctrl+2, l does not work for Optional without the import
Status: CLOSED DUPLICATE of bug 444870
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-05 06:55 EDT by Lars Vogel CLA
Modified: 2015-10-28 04:44 EDT (History)
3 users (show)

See Also:


Attachments
Animated Gif (71.65 KB, image/gif)
2015-10-27 10:03 EDT, Lars Vogel CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2015-10-05 06:55:09 EDT
Ctrl+2, l allows to assign variables even without importing there type first but this does not work for Optional.

package snippet;

public class Snippet {
	
	public static void main(String[] args) {
		// Using a String
		String s = "Hello";
		Optional.ofNullable(s) -> PRESS CTRL+2, l, does not work

	}
}


package snippet;

public class Snippet {
	
	public static void main(String[] args) {
		// Using a String
		String s = "Hello";
		new Todo()-> PRESS CTRL+2, l, does work

	}
}
Comment 1 Noopur Gupta CLA 2015-10-08 08:24:58 EDT
Consider the following example:

package snippet;

public class Snippet {
	
	public static void main(String[] args) {
		// Using a String
		String s = "Hello";
//		Optional.ofNullable(s) 		// [1]
//		Todo.instance(null) 		// [2]
//		new Todo()			// [3]
	}
}

Without import, Ctrl+2, L works only at [3] and not at [1], [2].

It works at [3] as the type of variable declaration is known with the constructor call "new Todo()", and the type need not be resolved.

At [1] and [2] it doesn't work as the type of variable declaration to be created is not known until the Type is resolved (import is added) and the method's return type is known.
Comment 2 Lars Vogel CLA 2015-10-27 10:03:07 EDT
Created attachment 257543 [details]
Animated Gif

See the animated GIF for a demonstration. Example snippet:


// for pasting
// Optional.ofNullable(s)
// new Todo()
public class Main {

	public static void main(String[] args) {
		// Using a String
		String s = "Hello";
		// After I paste the text I try Ctrl+2, l
		Todo todo = new Todo();
	}

	private class Todo {
	}
}
Comment 3 Lars Vogel CLA 2015-10-27 10:03:40 EDT
See comment 2
Comment 4 Dani Megert CLA 2015-10-27 16:51:59 EDT
(In reply to Lars Vogel from comment #0)
> Ctrl+2, l allows to assign variables even without importing there

Please reopen if you can provide a link to documentation that says so.
Comment 5 Lars Vogel CLA 2015-10-27 17:48:37 EDT
(In reply to Dani Megert from comment #4)
> (In reply to Lars Vogel from comment #0)
> > Ctrl+2, l allows to assign variables even without importing there
> 
> Please reopen if you can provide a link to documentation that says so.

Works for new Todo() even if you move it out.
Comment 6 Dani Megert CLA 2015-10-28 04:44:39 EDT
(In reply to Lars Vogel from comment #5)
> (In reply to Dani Megert from comment #4)
> > (In reply to Lars Vogel from comment #0)
> > > Ctrl+2, l allows to assign variables even without importing there
> > 
> > Please reopen if you can provide a link to documentation that says so.
> 
> Works for new Todo() even if you move it out.

It does not resolve the type but because it is a constructor we know what name will be on the LHS. In your examples (method call or field) the type cannot be known until the import is done.


Normally I would not want a certain quick assist/fix to do more than advertised, but in this case where it doesn't do anything, we could do better. I mark this as duplicate of bug 444870, since once the import is done as first step, the type of the method or field will be available.

*** This bug has been marked as a duplicate of bug 444870 ***