How can I set Idea collapse too long string? - intellij-idea

Look at Eclipse:
and in Idea:
So, how can I make Idea collapse multiline String like Eclipse?

Unfortunately, it seems there are no folding options for string literals.
You could try using custom folding tags, but this could will require extra comments for every string:
To check all existing folding options go to Settings > Editor > General > Code Folding.

Related

IntelliJ IDEA: is there a way to format java code in a canonical way?

I have two java source files. Both represent the same class (semantically), but they were formatted differently.
For example, one of them contains the following line:
return Boolean.valueOf(Boolean.getBoolean("abc"));
While in the second file it looks like 2 lines:
return Boolean.valueOf(
Boolean.getBoolean("abc"));
In both cases, when I apply formatting (Ctrl+Alt+L), these lines do not change.
Is it possible to format them in some canonical way: that is, to get the same code if the only difference is formatting?
Equivalently: is there any way to remove all ignorable whitespace? Such a 'dried-out' program would then be easily restored using 'Reformat code'.
You should be able to do this if you turn off "Wrapping and Braces | Keep when reformatting | Line Breaks" in the Java code style settings.
Go to File > Settings > Ediotor > Code Style > java
in tab Wrapping and Braces uncheck line breaks
Apply and make (Ctrl+Alt+L) again.

Intellij: how to convert indents for all files

I know how to convert indent for a single file. I go to edit -> convert indent -> space/tab.
But I want to do this for all files under a directory.
I try click on a directory and then go to edit -> convert indent, but the options are grayed out.
You can use the shortcut Ctrl+ALT+L (Windows/Linux) or ⌥⌘+L (MAC OS X) and select the Rearrange entries option to reformat the code in the current file or reformat a module or directory.
You can also Right-click a module, file, or directory from the context menu and select Reformat Code and also select the Rearrange entries option.
This will convert the indents for all files/directories selected:
This works on most of the Jetbrains IDES (iDea, PyCharm, WebStorm, RubyMine, and so on.)
It seems there is no such dedicated option in IntelliJ, but you could just work around it using a "low-level" Replace All action.
Open the Edit → Find → Replace in Files... dialog
In case you want to convert spaces to tabs, you should
Enter in the Find field (i.e. four spaces (or whatever number of spaces the project is currently indented with))
Press the Regex search modifier (Alt + X)
Enter \t in the Replace field
NB: In case you have valid strings with 4+ spaces in them, they will get replaced too. In most use cases, however, this is not happening.
In case you want to convert tabs to spaces, you should do the same as above, but swap the Find and Replace field contents
NB: Again, if you have valid strings with tabs in them, they will get replaced too. I haven't had this use case, because I've only needed to convert in the opposite direction.
You will probably also want to set a File mask in order not to replace spaces in code-irrelevant files

How do I stop SQL splitting string literals when I press Enter in DataGrip or IntelliJ Database Editor?

When my cursor is after an open quote in a SQL statement in an IntelliJ database console and I press Enter, it closes the quote on the current line and adds a concatenation symbol with an open quote on the newline.
I disabled formatting the SQL code style settings but that didn't fix it for me.
UPDATE blah SET blah2 = 'something<pressed enter>' ||
'<argh!>...';
Is there a way to disable this autoformatting?
This request was addressed in 2017.1 version, as a result, Insert string concatenation on Enter setting was added specifically for SQL:
This can be archived since IntelliJ 13. You simply need to wrap your code with
// #formatter:off
your code goes here
// #formatter:on
Since IntelliJ Idea 15-16(pardon if i'm wrong), you can also make permanent set up by Preferences > Editor > Code Style option
Hope it helps

Autoformat code CTRL+SHIFT+L add a space, between ending quote and parenthesis of string

For example when my code says:
System.out.println("Printing demo features");
I use CTRL+SHIFT+L and Intellij make this:
System.out.println("Printing demo features" );
Thanks for your help.
It looks like you have custom code styling in place for Java, thus the auto format function tries to match it:
Check Settings > Editor > Code Style > Java > Spaces and look for "Within" grouping. See if you have some options marked like "Method call parentheses". If you don't have any custom style in place, simple reset the Java style to default and it should be "fixed".
Obs.: I am on Intellij14, options might be different.
Check off Settings > Editor > Code Style > Java > Spaces > Within > Method call parentheses
If above didn't help: "File" -> "Invalidate Caches / Restart..." (sounds unrelated, but in my case actually solved it)

IntelliJ force code formatter to join lines based on wrap settings

How can i reformat file(s) in IntelliJ and join all lines that are split.
I know that I can do that individually by selecting lines and "join lines" with CTRL + SHIFT + J
Since we changed our code formatting wrap policy recently I want to be able to join lines in all files based on the updated wrap setting. (Settings > Code Style > General > Right margin)
The only thing is that IntelliJ seems happy to split lines based on wrap setting, but will silently deny to join lines based on that setting.
Unlike the question Force code formatter in IntelliJ to join lines, I am not satisfied by splitting lines or joining manually (as the accepted answer suggests). I want IntelliJ to join lines automatically.
Bonus question: Which other editors can do this?
Disable the following code style option - Project Settings - Code Style - Wrapping and Braces - Keep when reformatting - Line breaks
IntelliJ IDEA 15
File > Settings... > Editor > Code Style > Java > Wrapping and Braces > Keep when reformatting > uncheck Line breaks
(if you want to have the same setting for another type of file, choose it from Code Style)
Go to Code > Reformat Code (Ctrl + Alt + L).