Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA 13: how do I disable refactor comments and strings?

public class KV<K, V> {     public K key;     public V value;     public KV(K key, V value) {         this.key = key;         this.value = value;     }  } 

I am trying to refactor the class variable value, which happens in place. That means no dialog pops up; I press enter and it tries to refactor across the entire project, including comments and what not, including:

<%--<link href="<c:url value="../core/core.css" />" />--%> 

in a .jsp file. That is way too "clever" to try to refactor comments that match across the entire project. This often causes lots of bug risk, and refactoring in a Java environment is no longer safe.

The same thing was occurring in Intellij 12. Seriously, I don't need Intellij to recommend anything that is considered unsafe, or when it is not sure it is the same thing!

I can exclude the refactorings but I don't have time to evaluate five "suggestions" every time. It just raises the chance of human error: most of the time I just press enter, and woops things are refactored.

Refactoring is also a major issue in a Java environment when it sometimes tries to replace things in .js files. Seriously, this has to stop.

Without the popup dialog, I can't untick "search strings". Even if that was ticked, Intellij should never include the suggestions by default, especially when it is outside the current file. It can recommend to refactor them as well, but they should be excluded by default. That is, it should be an opt-in feature, rather than by default destroying everything.

This is a serious user experience problem with more recent so called "smart" Intellij refactoring. When refactoring JS files, I don't want to search Java files for comments or strings! Period! And vice versa!

Safety comes first! Developers that know what they are doing will search for strings themselves if needed. In a dynamic language environment it makes Intellij impossible to use, because frequently, and without any clear pattern, sometimes refactorings go through, sometimes it changes things across the project and what not.

There should be an option that says, "refactor only relative to this file or when 100% inferred!", especially for dynamic languages! For static languages it shouldn't even attempt to look for comments and strings outside the file.

I didn't mean to put it out in public, but I have raised this issue over 2 years ago in the bugtracker, but nobody paid any attention.

EDIT

For those of you that think that I might be going to far, I just tried this out:

With this class:

public class KV<K, V> {     public K key;     public V val;     public KV(K key, V val) {         this.key = key;         this.val = val;     } } 

And adding this to any Java class, for instance:

public class CoreConfig {     String abc = "kv.val";     String def = "somethingElse.val"; } 

When refactoring KV.val as before, I get the following recommendations, an ENTER from disaster and something I have to evaluate and exclude one at a time. It takes effort and is just annoying and risky. It's like someone yelling out, STOP! And then ooh, nothing after a minute, frustration and a 1000 long word essay ( this ).

enter image description here

Seriously, is there a way to disable this kind of risky behaviour!? And is there any reason why this is on by default??

EDIT 20200706

Shit continues in 2020: https://youtrack.jetbrains.com/issue/IDEA-245370

like image 839
mjs Avatar asked Jan 01 '14 17:01

mjs


People also ask

How do I undo refactoring in IntelliJ?

If you need to undo your refactoring, press Ctrl+Z .

What is refactoring in IntelliJ?

IntelliJ Code Refactoring. Refactoring is the process of changing the structure of the existing program without changing its functionality and usage. Refactoring also used to improve the code reusability, increase performance and also remove the duplicate functionality or unused functionality.

How do I Refactor variable type in IntelliJ?

In the editor, highlight or place the caret at a type you want to refactor. Press Ctrl+Shift+F6 or on the main menu, select Refactor | Type Migration. In the dialog that opens, specify the new type and scope where to look for the usages. Preview and apply the changes.


1 Answers

When you press Shift + F6 (Refactor Rename) twice, it opens the dialog and you can disable "Search in comments and strings"

like image 176
Meo Avatar answered Sep 19 '22 17:09

Meo