Bug 422011 - Don't add parentheses when auto-completing methods before an open parenthesis
Summary: Don't add parentheses when auto-completing methods before an open parenthesis
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-18 17:13 EST by David Harkness CLA
Modified: 2013-11-19 08:00 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Harkness CLA 2013-11-18 17:13:12 EST
When you auto-complete a method name in existing or copy-pasted code, Eclipse inserts an extra set of parentheses.

SETUP

You want to change the following method call to getLastName():

    name = contact.getFirstName();
                      ---------

1. Delete the underlined code "FirstName"
2. Hit ctrl-space to show a list of getters
3. Select getLastName

EXPECTED

    name = contact.getLastName();

ACTUAL

    name = contact.getLastName()();

FIX

Only insert new parentheses if the next non-whitespace character is *not* an open parenthesis.

TRICKY

When Java 8 adds closures (I haven't checked the syntax yet) and allows them to be returned from methods, the ACTUAL code above becomes valid. 999 times out of 1,000 it won't be desired, but it'll be possible. I don't think that should affect this enhancement request, however.
Comment 1 Timo Kinnunen CLA 2013-11-19 08:00:48 EST
The same happens with constructors:

Start editing from: List<String> strings = new ArrayList<>();
Show completions on: List<String> strings = new link<>();

Select LinkedList() constructor:
Expected: List<String> strings = new LinkedList<>();
Actual: List<String> strings = new LinkedList()<>();