Bug 426743 - [content assist] Need Java current line completion feature similar to IntelliJ idea
Summary: [content assist] Need Java current line completion feature similar to Intelli...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-27 13:33 EST by Gopi Krishna CLA
Modified: 2014-01-29 13:43 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gopi Krishna CLA 2014-01-27 13:33:02 EST
I'm used to code in IntelliJ  and it has very good feature of current line completion . Upon Clicking Ctrl + Shift + Enter it will complete current line like put necessary end " , ) , ; , {} etc . It may look small but i'm very much missing it in eclipse . 

See link http://www.jetbrains.com/idea/webhelp/completing-statements.html

It just takes the first few letters of current line( like if , for ) and based on that it will end the statement ( like { }) , if it is not conditional statements then end it will semicolon , if current statement already has semicolon then just go to end of line do nothing else.
Comment 1 Stephan Herrmann CLA 2014-01-28 14:31:21 EST
Sounds like a variant of JDT/UI's template proposals?
Comment 2 Sebastian Zarnekow CLA 2014-01-28 17:26:03 EST
I think it's more like smart semicolon or complete expression-statement.
Comment 3 Martin Mathew CLA 2014-01-28 19:44:57 EST
Eclipse has code completion invoked via "Ctrl+Space" which will help in completing the code. You can also check the options available in Eclipse Preferences page Java -> Editor -> Typing. Enable the options that suite your coding style. If you are looking for some specific functionality/feature, kindly give us the details.
Comment 4 Timo Kinnunen CLA 2014-01-28 21:14:10 EST
I haven't used Idea, but I take the feature provides mainly completion of missing syntax. In a way it's filling the gaps between source code and the AST generated from it. Or maybe filling the gaps in the source code to match the shape of the AST.

These three cases could offer a completion:

    //from int[] array = new int[]|
    //give int[] array = new int[] { | };
    //from Comparator.comparing(i |) 
    //give Comparator.comparing(i -> i|);
    //from Runnable r = new Runnable() { public void run() {| 
    //give Runnable r = new Runnable() { public void run() { | } };

The above might seem trivial, but being able to do this would be really helpful:

    //from:
    //display.asyncExec(new Runnable() {
    //  @Override public void run() {
    //    textField.addListener(SWT.Dispose, new Listener() {
    //      @Override public void handleEvent(Event event) |

    //give:
    //display.asyncExec(new Runnable() {
    //  @Override public void run() {
    //    textField.addListener(SWT.Dispose, new Listener() {
    //      @Override public void handleEvent(Event event) { |
    //      }
    //    });
    //  }
    //});

Above, | shows where caret was when completion was requested but it could also be thought of as a placeholder for some unknown non-empty token(s) that should be inserted there.
Comment 5 Gopi Krishna CLA 2014-01-29 13:43:05 EST
@Timo Kinnunen - Yes, that's what this feature will do, add the missing syntax of the current statements . Its much more than Ctrl + Space , template proposals because it takes the current line Code/letters and completes the line intelligently.

So its just write one letter ->Basic Completion (Ctrl + Space) -> currentline completion ( Ctrl + Shift + Enter ) to go to next line .

/* below | means cursor position */

    //from System.out.print("I'm printing |
    //give System.out.print("I'm printing ");|

    //from System.out.print|("I'm printing "
    //give System.out.print("I'm printing ");|   /* regardless of cursor position in the line it will complete the current line */

    //from int index | = 2
    //give int index  = 2; |

    //from for(|)
    //give for(|) { }  /* cursor still in same place bcoz no condition written in for */

    //from for(int i=0;i<10;i++ | )
    //give for(int i=0;i<10;i++  ) { | }

    //from public String getMethod(|)
    //give public String getMethod() {
      | }

This feature might look trivial but once you start using it in idea , then you will know much its useful.  Its like IDE aware of current line code and completing the statement accordingly. Also current line completion also does the FORMAT of the current line according to defined code style. Typing {,( etc is bit tedious. Also most of the times we forget using templates/write partial for etc statement like "for (int i=0;|" so template proposals will not be useful for this but line completion is useful regardless of line.  

One more thing i was just recently known that "Autoactivation triggers for Java" can be assigned with multiple characters like ".abcd....zABC...Z" so no need of pressing Ctrl + Space ,very useful don't know why its not kept as default in eclipse.