JShell: Input requested -- variable creation short-cut -- import?

Robert Field robert.field at oracle.com
Fri Nov 11 04:30:47 UTC 2016


There are currently two shortcut options:

     <shortcut> v

         Convert expression to variable

     <shortcut> i

         Import type

Where the <shortcut> key is either Alt-F1 or Alt-Enter.

Current behavior (annotated with invisible keystrokes) --

%  jshell --no-startup
|  Welcome to JShell -- Version 9-internal
|  For an introduction type: /help intro

jshell> Pattern<shortcut>i
0: Do nothing
1: import: java.util.regex.Pattern
Choice:   1
Imported: java.util.regex.Pattern

jshell> Pattern.compile("a.*b").matcher("acccccb")<shortcut>v
jshell> java.util.regex.Matcher m = 
Pattern.compile("a.*b").matcher("acccccb")
m ==> java.util.regex.Matcher[pattern=a.*b region=0,7 lastmatch=]

Note that the resultant variable is created with the fully qualified type.

Here is a prototype that combines these functionalities --

jshell> Pattern.compile("a.*b").matcher("acccccb")<shortcut>x
0: Do nothing
1: Create variable
2: import: java.util.regex.Matcher. Create variable
Choice:  2
Imported: java.util.regex.Matcher

jshell> Matcher m = Pattern.compile("a.*b").matcher("acccccb")
m ==> java.util.regex.Matcher[pattern=a.*b region=0,7 lastmatch=]

Note: both the import and the simple type name.

Thoughts?

This could be the default behavior of <shortcut>v or have a different 
shortcut letter -- but what?

Note: there is no menu with this if there is no need for an import -- 
just converts to variable form.


For people who care about such things, this is the bug:

     https://bugs.openjdk.java.net/browse/JDK-8166333

and prototype webrev:

     http://cr.openjdk.java.net/~rfield/8166333v0.webrev/

Thanks,
Robert



More information about the kulla-dev mailing list