auto static import

I would like it if IntelliJ were more intelligent about

out.println and err.println.

It should either automatically, or with the tiniest prod insert

import static java.lang.system.out;

Rearranger often removes them if there are any syntax errors.


Further.

Assume I  have many references to an enum e.g. Hint.IN and Hint.OUT in
a class.  I would like it if I could with a keystroke or two convert
all the references to unqualified IN and OUT with an inserted

import static com.mindprod.stores.Hint.*;


ditto System.out.println -> out.println.
--
Roedy Green Canadian Mind Products http://mindprod.com
The art of strongly-typed language design is largely arranging
that errors are automatically detected as soon as possible
in the compose, compile, run cycle.

5 comments
Comment actions Permalink

I would like it if IntelliJ were more intelligent about

out.println and err.println.

It should either automatically, or with the tiniest prod insert

import static java.lang.system.out;


  1. Go to File > Settings > [Project Settings] > Code Style > Java > Imports
  2. In the "Packages to Use import with '*'" section, click the add button add2.png
  3. Add   java.lang.System   to the "Package" and check the "Static" box.
  4. Close out of Settings

Now any references to  java.lang.System static methods will result in the use of import static java.lang.System.*;

Note that this feature is broken in 13.1.4 (and some earlier versions). See http://youtrack.jetbrains.com/issue/IDEA-127947



Assume I  have many references to an enum e.g. Hint.IN and Hint.OUT in
a class.  I would like it if I could with a keystroke or two convert an inserted

import static com.mindprod.stores.Hint.*;

Place your cursor on any of the Hint instances, Open the Intentions Action Menu (Alt+Enter) and select "Add on demand static import for Hint". If you just want to import one, such as IN, place your cursor on IN, Open the Intentions Action Menu (Alt+Enter) and select "Add static import for Hint.IN" (Note: if you do not szee those options in the Intentions Action Menu, turn them on in Settings > [IDE Settings] > Intentions > Imports)

0
Comment actions Permalink

On Wed, 06 Aug 2014 17:39:34 MSK, Mark Vedder <no_reply@jetbrains.com>
wrote, quoted or indirectly quoted someone who said :

>

>1. Go to File > Settings > > Code Style > Java > Imports
>2. In the "Packages to Use import with '*'" section, click the add button  Image:add2.png
>3. Add   java.lang.System   to the "Package" and check the "Static" box.
>4. Close out of Settings
>Now any references to  java.lang.System static methods will result in the use of import static java.lang.System.*;
>
>Note that this feature is broken in 13.1.4 (and some earlier versions). See http://youtrack.jetbrains.com/issue/IDEA-127947


I could never get that to work. There was no add button. Today I
figured out the problem. The button was scrolled off screen. There did
not appear to be anyway to add to the list.

--
Roedy Green Canadian Mind Products http://mindprod.com
The art of strongly-typed language design is largely arranging
that errors are automatically detected as soon as possible
in the compose, compile, run cycle.

0
Comment actions Permalink

On Wed, 06 Aug 2014 17:39:34 MSK, Mark Vedder <no_reply@jetbrains.com>
wrote, quoted or indirectly quoted someone who said :

>Now any references to  java.lang.System static methods will result in the use of import static java.lang.System.*;

I did that and a number of variants.  Nothing happens.
--
Roedy Green Canadian Mind Products http://mindprod.com
The art of strongly-typed language design is largely arranging
that errors are automatically detected as soon as possible
in the compose, compile, run cycle.

0
Comment actions Permalink

Guest wrote:

I did that and a number of variants.  Nothing happens.

Did you read the part in my reply about it being vroken in current releases? There's a link to the bug report.

0
Comment actions Permalink

On Fri, 15 Aug 2014 19:34:53 MSK, Mark Vedder <no_reply@jetbrains.com>
wrote, quoted or indirectly quoted someone who said :

>Did you read the part in my reply about it being vroken in current releases? There's a link to the bug report.

I improperly thought you were referring only to old versions.
--
Roedy Green Canadian Mind Products http://mindprod.com
The art of strongly-typed language design is largely arranging
that errors are automatically detected as soon as possible
in the compose, compile, run cycle.

0

Please sign in to leave a comment.