Bug 474299 - Easier static import for subsequent names from same type
Summary: Easier static import for subsequent names from same type
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-05 05:19 EDT by Stephen Colebourne CLA
Modified: 2017-09-04 07:02 EDT (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 Stephen Colebourne CLA 2015-08-05 05:19:31 EDT
This is a request to enhance static imports when there has already been one static import.

Consider this class:

 import static java.time.temporal.ChronoUnit.DAYS;

 import java.time.LocalDate;

 public class TestBase {
   LocalDate d = LocalDate.now().plus(3, DAYS);
 }

It has one static import of the "ChronoUnit" class.

What would be highly desirable is that once there has been one static import from a specific type (ChronoUnit is this case), all the constants from that type should be made available via auto-complete within that class (TestBase in this case) as though they had been added to the Java/Editor/ContentAssist/Favorites preferences option.

In other words, entering the following line in the class above:

 LocalDate e = LocalDate.now().plus(3, !!!);

should, when the cursor is at !!!, provide all the static constants from ChronoUnit, such as DAYS, MONTHS and YEARS.

Some background info. While the preferences Favorites list is very useful, it is not widely known. There are also cases where some static imports only apply to small parts of a large system, and so are not appropriate to add to the general preferences. The change described above is relatively simple, but would dramatically make it easier to write and maintain classes with static imports in them. (Try adding the second line to the exact class above to see the number of steps necessary today - type name of ChronoUnit, import it, type desired constant MONTHS, then Ctrl-Shift-M, then Organize Imports to tidy up).