Eclipse formatter settings - java

Could anybody share their eclipse formatter settings file or point me to such a file which will prevent my eclipse from doing the following thing:
when I press ctrl+shift+F to format my code, eclipse from this string:
dayArrayList.add(new Day(WeekDay.SATURDAY));
the following string:
dayArrayList.
add(new Day
(WeekDay.SATURDAY));
So I want only really looooooooooong code strings be moved to next line (those, which don't fit into the eclipse window), but eclipse do this almost with all strings.
Thanks in advance!

Simply increase the Maximum line width to let's say 140 chars?
The following formatter does this.

In Eclipse go to Window->Preferences->Java->Code Style->Formatter
Then Create a new profile and in the Line Weapping Tab you have the Parameter "Maximum line width"

You can set the maximum line width in eclipse by:
Window -> Preferences -> Java -> Code style -> Formatter -> Edit
On line wrapping tab, change the default 80 to your preference. Note that you will have to save as a new profile if you are changing the default one.

Related

IntelliJ IDEA - double quotes and letters changed to Unicode letters

I am facing a weird issue in IntelliJ that whenever I entered double quotes it will automatically converted into either 3 double quotes or sometimes it is converted to some Unicode letters.
For example, if I enter A after " then the text would change into something shown in the image.
I am using macOS 10.13 High Sierra. Thanks in advance
I had the same issue and the problem was not in IntelliJ IDEA but in keyboard input source on MacOS.
The reason of issue: I was using "U.S. International - PC" keyboard on MacOS. When I changed it to "U.S." the issue was gone.
Steps to solve the issue:
Go to System Preferences -> Keyboard -> Input Source tab
Click on + button -> add "U.S." input source (or "British")
The default behaviour of IntelliJ IDEA is to saving you time by inserting a pair of quotes when you type the opening quote. This is controlled by Settings -> Editor -> General -> Smart Keys.
The funny characters appearing in your case may be due to some weird setting. Try going to Settings -> Keymap.

Eclipse neon: java formatter keeps spaces on empty lines?

Within our team, we have an eclipse formatter profile that we are using for some years. It seemed to work fine within Eclipse Neon, but today I discovered that the formatter is no longer "trimming" empty lines.
When using older versions of eclipse, running the formatter simply trims lines that only contain spaces. The line is still there, but the spaces are all gone after formatting.
I checked the formatter options; but I can't find a checkbox that would match.
For the record: I saw this, but using "trim on save" is a no go for me: very often I have to make subtle changes in files from other people; and I intentionally do not format those files; because the diff would be huge. And for the same reason, I don't want that "save" trims empty lines either. Before Neon, I would press ctrl-f on purpose; also to trim lines; now it doesn't have that effect any more.
Any idea where to fix that?
As the answer says in the linked question, you could do on save for only lines you have changed
Removing whitespace only from the lines I changed:
Preferences -> Java -> Editor -> Save Actions -> check "Perform the selected actions on save" -> check "Format source code" -> select "Format edited lines".

Is there a way in Eclipse to keep the values in multiple arrays lined up?

I want the values of two (or more) arrays to be lined up like in the bottom row of this example.
Is there a way to do this in Eclipse?
You can switch off Eclipse formatter (see https://stackoverflow.com/a/3353765/5277820) and format the lines by yourself.
If I misunderstood your question I apologize, I assume you are talking about the formatting in Eclipse.
(Windows version)
In Eclipse, go to
Window -> Preferences -> Java -> Code Style -> Formatter.
Open the profile (should be default, but I'd suggest creating your own)
In the Line Wrapping tab, there is a "Maximum Line Width" that you can change (default is 80). That will prevent lots of these automatic line wrappings.
See the image below. For the white spaces you need to navigate to the "White Space" tab.

How to avoid eclipse to create 2 lines when autoindent is ON?

Eclipse code-formatting options are vast (see Java -> CodeStyle -> code formatting)
What I want is to avoid that the autoindent split my lines of code in 2 (or more) lines (see below). When reading-debugging code, is far more clear to read complete lines (IMHO)
Ex
float vsleep = (float) (((nodelenght) * obj
.getFactorperchar()) * 1000);
If I understand correctly, you want to stop eclipse from wrapping text over one or more lines.
If you navigate to Window -> Preferences -> Java -> Code Style -> Formatter and then click "Edit" next to the active profile, you can edit all of the auto formatting options. Choose the Line Wrapping tab, and then select all of the options in the list that contains "Class Declarations", "Constructor Declarations" and so on. Underneath the list, set the Line wrapping policy to "Do not wrap".
I tested this in my version and it seems to work.
Try setting Line Wrapping -> Maximum line width to something larger.

remove indentation in source code

I use Eclipse IDE and Window Builder Pro for create window.
When I go to the source code I see a big indent text. How to delete ?
How about good old Shift + Tab?
If by "how to delete" you mean to say that you want to decrease the indentation level, try this:
Go to
Window->Preferences->general->Editors->Text
Editors
There specify the indentation level under :
Displayed Tab Width.
Additionally you can customize you formatting in Eclipse as :
Go to
Window->Preferences->Java->Code
Style->Formatter
Select the formatter and press Edit. Use whatever suits you.
Then Select the text you want to format and press Ctrl+Shift+F
If you want to fix indent only you can select lines and press Ctrl-I.
Take a look at Eclipse keys
Most likely you insert tab character which is being expanded to 8 positions in target IDE.
Change setting in Eclipse to insert 4 spaces (or whatever your style is) when tab is pressed.
Then you can try to reformat your file in Eclipse. Also, you can use sed to replace \t with 4 spaces.
If you like the way your formatter is set up for the rest of your code, perhaps telling the formatter not to work on this section would be desirable. Then you can unindent the section to make it visually appealing and not worry about it changing formatting.
Linked solution works in Eclipse 3.6.

Categories