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

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.

Related

Why is VS Code showing this these labels or parameter names for System.out.println() in java files?

I have the java extension pack installed. This just started happening today. Not sure if this is due to some json settings or something else.
See Random things such as "s:", "x:", and name of parameters are showing up inside of my print statements: java extension issues.
It's a new feature introduced in 1.5.0, called inlay hint. We use that
to display the parameter names of those arguments.
If you do not want to have them in your editor, you can set the
setting java.inlayHints.parameterNames.enabled to none
The newest extension has enabled inlay hints. They are actually helpful, but if you want to remove them:
Mac: Code -> Preferences -> Settings
Windows: File -> Preferences -> Settings.
**Type "inlay" in the search, and disable inlay hints.
To disable this setting Open 'setting.json' file
(CTRL + SHIFT + P and type "Open Settings (JSON)" to open setting.json)
Add this code in this file
"editor.inlayHints.enabled": "off"
The Java tooltip is now showing you the variable names from the methods in question. System.out is a PrintStream. The relevant method signatures are PrintStream.print(String s) and PrintStream.println(String x).
lets say you have a function setPassword that takes parameter of the name newPasswordandoldPassword. So, when you call that function, it would hightlight what the parameter is supposed to be. like
setPassword(newPassword: "SOME_NEW_PASSWORD",oldPassword:"SOME_OLD_PASSWORD")
This is supposed to reduce any confusion as to what value you entered is what. Extremely helpful when working with functions that take multiple parameters.
It's called inlay hints. You can set that to not show unless needed.
In Command Palette -> Language Specified Settings -> Java -> Search for inlay
-> Enable or Disable.
P.S. It's really helpful in debugging Problems, So you can set it to "offUnlessPressed".
None of this worked for me so here is how I fixed it:
When I did settings through CTRL + SHIFT + P and type "Open Settings
(JSON)", an uneditable JSON file would pop up called
defaultSettings.json that had the setting I needed to change.
Here is an image of this file:
defaultSettings.json
I had to find settings through the file directory (win + R) %APPDATA%
-> Code -> User -> settings.json
Then I just added "editor.inlayHints.enabled": "off",
Make sure to add a comma at the end of the previous line if there was
not an existing one or else an error will appear.
Here is an image of the settings.json file: settings.json

Eclipse Formatter: Break at Greater-Than Sign Rather Than at Dot

I have this line showing the problem:
Which setting in the Eclipse Java formatter do I have to change so the line will break like
return this.data.getNumberOfGenerationsWithoutSignificantImprovementPassed()
> MAX_NUMBER_OF_GENERATIONS_WITHOUT_SIGNIFICANT_IMPROVEMENT;
or like
return this.data.getNumberOfGenerationsWithoutSignificantImprovementPassed() >
MAX_NUMBER_OF_GENERATIONS_WITHOUT_SIGNIFICANT_IMPROVEMENT;
? If both is possible, I prefer the former.
On Mac, go to Eclipse -> preferences. On Windows, I believe it is Windows -> preferences... but don't quote me on that!
Expand Java -> Code Style -> Formatter
To the right of the "Active profile" bar, choose edit.
A new window will open- choose the "Line Wrapping" tab.
Scroll down to "Expressions" and choose conditionals. Pick your favorite!
Bonus points: This is where you can set all sorts of different styles, if you have not before, like number of spaces per tab character. Once you get everything set up just right, name your profile and export it. I use the same theme on 3 different computers and the consistency is nice!

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.

Eclipse - Only Auto-Indent On Typing

Is it possible to have Eclipse only indent new lines when you start typing code? For example, hitting enter brings the text cursor back to the left-hand margin, but starting to type on that line would tab it to the appropriate indentation?
I currently strip trailing whitespace on save, but that's not really the behavior I want.
Eclipse can automatically add/remove indentation in some cases (one of them is when line is empty). For that you need to enable auto formatting on save action.
Go to Window -> Preferences -> Java -> Editor -> Save Actions check both Perform the selected actions on save and Format source code.
Then make sure that currently used formatter doesn't indent empty lines.
Go to Window -> Preferences -> Java -> Code Style -> Formatter click Edit... button. In the Indentation tab un-check (if checked) Empty lines under Indent section.

Eclipse formatter settings

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.

Categories