Newly Generated Imports Stomp Formatting of Existing Ones

I've have just noticed that in M2 (#7126) when I use a previously unused unqualified class name and then accept (ALT+Enter) an offered import, all the adjacent imports are reformatted.

I prefer columnar alignments and put three tabs between the "import" keyword and the fully qualified class name (only one tab after "import static").

This is a very unwelcome change and I hope it can be reversed.

In general, IDEA is far too heavy-handed in its altering of whitespace and I find it most displeasurable.

Randall Schulz

0
Avatar
Permanently deleted user

Hello Randall,

I've have just noticed that in M2 (#7126) when I use a previously
unused unqualified class name and then accept (ALT+Enter) an offered
import, all the adjacent imports are reformatted.

I prefer columnar alignments and put three tabs between the "import"
keyword and the fully qualified class name (only one tab after "import
static").

This is a very unwelcome change and I hope it can be reversed.


The change happened because Alt-Enter now inserts imports in proper sorted
order rather than adding them to the end of the import list (so that a subsequent
Optimize Imports doesn't introduce spurious changes). Frankly speaking, our
goal is to make the management of import statements so transparent and automatic
that no one ever has to look at them, much less add three tabs manually.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Avatar
Permanently deleted user

But people do read code. It's not just for compilers.

Why isn't white space considered significant? Code formatting is hardly a triviality.

IDEA alters whitespace on virtually every kind of refactoring operation, and I don't see how you can justify so blatantly changing existing code. Why don't you simply limit the alteration of the program text to those symbols you're altering and leave the surrounding white space out of it? And in the import case, you're taking lines of code not involved in the operation and changing them. That's even worse.

Please fix this.

0
Avatar
Permanently deleted user

The change happened because Alt-Enter now inserts imports in proper sorted
order rather than adding them to the end of the import list (so that a subsequent
Optimize Imports doesn't introduce spurious changes).


I assume this is only if "Optimize imports on the fly" is enabled? Otherwise, I don't think it should be touching the other import statements.

0
Avatar
Permanently deleted user

Hello Alex,

>> The change happened because Alt-Enter now inserts imports in proper
>> sorted
>> order rather than adding them to the end of the import list (so that
>> a subsequent
>> Optimize Imports doesn't introduce spurious changes).

I assume this is only if "Optimize imports on the fly" is enabled?
Otherwise, I don't think it should be touching the other import
statements.


It doesn't touch the other ones - it inserts the new one correctly.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Avatar
Permanently deleted user

No, I don't have "Optimize imports on the fly" enabled.

0
Avatar
Permanently deleted user

Well, that's not what I'm seeing. I can live with newly added imports having a canonical formatting, but in this case, it is changing imports that I already reformatted to suit my own standards.

0
Avatar
Permanently deleted user

I guess you never use "Optimize Imports"?
IDEA doesn't give any code style settings for formatting each import statement line, so you know it won't preserve the special formatting.

I agree that if IDEA is just adding an import it shouldn't reformat any other imports, unless you have that "Optimize Imports On the Fly" enabled.

0

Just to chime in here: I'm seeing this as well.

I have 'insert unambiguous' enabled, but I don't have 'optimize on the fly' enabled, and I have noticed that the imports are reformatted after an unambiguous import is added. I noticed this because I have jalopy set up to separate out the static imports, and they get re-scrambled when IDEA adds the new import.

I can't tell you if this happens 100% of the time, or only in certain circumstances, since, as you say above, one should never have to look at the import statements...

anders

0
Avatar
Permanently deleted user

As I've worked longer with M2, I'm seeing that this symptom is variable.

Sometimes it affects only other imports from the same package, say "java.io". Sometimes it affects every import, regardless of whether there is any overlap between the leading portions of the package path and sometimes it doesn't alter existing imports at all.


Randall Schulz

0

Another refactor/import bug I've just run across is reported in http://www.jetbrains.net/jira/browse/IDEA-14377

When extracting a variable from a statement that relies on static imports, the code is replaced with fully qualified class names, and the static imports are removed from the file, which breaks all the other code in the file that relies on the static imports.

0
Avatar
Permanently deleted user

The real problem is that I can't turn this off.
Thats not good:(

0

请先登录再写评论。