This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 238208 - organize imports expands "import static xxx.*" but it shouldn't
Summary: organize imports expands "import static xxx.*" but it shouldn't
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0
Hardware: PC Windows XP
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords: REGRESSION
: 246010 (view as bug list)
Depends on:
Blocks: 243435
  Show dependency tree
 
Reported: 2013-11-10 19:45 UTC by err
Modified: 2014-08-21 09:16 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description err 2013-11-10 19:45:49 UTC
import static com.raelity.jvi.core.ColonCommands.*;
HINT    import static com.raelity.jvi.core.Edit.*;
        import static com.raelity.jvi.core.GetChar.*;

HINT:
    The import section does not correspond to the specified code style rules
    (The action is organize imports)

If I do organize imports then each of the "import static xxx.*;" are turned
into lots of lines. Note that the import formatting option

        Member Count To Use Static Star Import

is not checked. This is discussed in Bug 203007 comment 6 from when this
feature was introduced.
Comment 1 ngx472 2014-07-19 09:22:35 UTC
I confirm that "organize import" expanding static import with star into lots of lines is dumb.

Scenario:
1) import static mypack.*;
2) auto completion on case/switch works fine
3) organize import. (removes star import)
4) auto completion does not work anymore when adding new cases in switch
(majority of static import is for constant lists)
This is even more frustrating when "organize import" is turned on automatically on save

Thanks to let the star live its life!
Comment 2 Jiri Prox 2014-07-23 12:03:03 UTC
IMHO the described behavior is correct, if the 'use single class' is selected and Member Count To Use Static Star Import is not checked the IDE tries to removed all star imports. The problem is that the 'Packages to use star import' does not work for static imports, e.g. when entering mypack.MyClass the star static imports from MyClass is replaced. This should be improvedWe can discuss the correct/expected behavior here, to get most user friendly UI
Comment 3 err 2014-07-24 13:21:08 UTC
There are two issues here.

1)  Broken feature
    When "member count to use static star imports" was introduced in
    NB-7.1 over two and a half years ago, it had a feature that
    allowed the rewrite logic to be disabled. This "disable rewrite"
    feature was broken/removed in 8.0 (thus it's a regression).

    As described in Bug 203007 comment 6 and mentioned in comment 1,
    if a user "disable rewrite" by unchecking "Member Count" and adds
    "import static xxx.*" then code completion works for the statics
    from xxx.

    Note that before this change to get "the IDE tries to removed all
    star imports" you could check the box, and set the count to a huge
    number. The change in behavior added no new feature, it removed
    one.

2)  UI issue
    (should probably be filed as a separate issue, then the regression
    could be fixed while a better UI is worked out)
    I'm not suggesting the following for a UI, but I think it shows
    all the possible configurations.

    [X] Allow static import rewrite
        |X| Allow import static star
            Member Count To Use Static Star Import      Integer-Slider

    So if "Allow rewrite" is unchecked, then "import static xxx.*" is
    left alone and code completion works and the following 2 lines are
    grayed and their settings don't matter. If "Allow rewrite" is
    checked then "Allow Star" controls whether the "Member Count"
    slider is used.
Comment 4 Jiri Prox 2014-07-25 19:10:06 UTC
*** Bug 246010 has been marked as a duplicate of this bug. ***
Comment 5 Svata Dedic 2014-08-12 10:53:18 UTC
Partially fixed by jet-main#3b40fe020d38
Comment 6 Svata Dedic 2014-08-13 13:13:25 UTC
Additional fix in jet-main#ebe618db4e18
I didn't want to rewrite the code, so I added some adjustments which will (I hope) cause these changes:
* if the Count is unchecked, the IDE will not convert star import into named imports
* if the Count is checked, and the actual number of used (imported) symbols is below the threshold, the star import is expanded
* if the Count is checked, and the actual number of used symbols from a certain scope exceeds threshold, a star import is created
The above should apply equally to both type imports and static imports.

I am not 100% sure that the "Packages to use star import" should be expanded to apply to static imports as well (e.g. not only packages, but types as well could be listed).
Comment 7 Quality Engineering 2014-08-16 04:54:50 UTC
Integrated into 'main-silver', will be available in build *201408160001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/3b40fe020d38
User: Svata Dedic <sdedic@netbeans.org>
Log: #238208: partial fix - comparator properly inserts static star imports