Indentation after chain of method calls - eclipse

Even though I should have the same setup as the rest of my team, Eclipse's formatter has one small anomaly in my setup.
You can see the difference in the attached picture.
On the left is my formatting.
On the right is the rest of the team's formatting.
I want to have the same formatting as the rest of the team.
The difference arises when there is an empty line after a chain of method calls.
Question: How do I achieve the formatting on the right?

I expect you are using the same formatter definition and have already tried to export the formatter on one of your team members machine and import it on yours.
Another thing you should check are the Save Actions in the preferences (Java -> Editor -> Save Actions). Maybe the settings for removing whitespaces differs here.

Related

Disable IDE auto format command

I have a code base that many developers work on. Some people blindly use auto format in their IDE and mess up the formatting of sql statements or other things. It appears that some IDE's like eclipse do have the ability to use //#Formatter:off (which I have put around many things I do want to not get formatted), but by default these are ignored. Thus, is there a way to either enable the setting so that will be used by default, or is there a way to disable any shortcut key linked to auto format using some sort of maven plugin? Basically I am looking for a way to enforce this for anyone who is working on the codebase since everyone can change their own formatter settings.
I found https://code.revelc.net/formatter-maven-plugin/format-mojo.html, but I dont think it can do either of those things.
Thanks in advance!

WebStorm formatting settings - port to another editor

Is there any way to get another editor, like VSCode, to format code ( JavaScript in my case, if it matters ) like the WebStorm IDE formats code by default? I'm not familiar with that IDE, but I'm hoping that it uses a config of some sort that can maybe be exported and imported in another editor. I tried looking for one, but couldn't find anything.
The core problem, if it matters, is that all of our team members use WS to write code and they use the built in formatter, so if I use another one it creates inconsistencies and long commits when editing already written files. As you are probably guessing by now, I would like to use another editor, because I find IDE's bloated and slow.
I don't know if there is a way to import Webstorm formatting rules into VS Code, but I think there is another solution:
I remember in one of the projects i worked on, we used a linter which also auto-formatted code. The advantage is that Webstorm and VSCode can pick pick the linter rules automatically, and then you have same formatting on both.
The downside is that you would need to agree with the team on what does rule will be and then configure them on the linter.

Eclipse format upon open

Eclipse can automatically format a file upon save. One use for this is to insure everyone's code meets a common corporate standard. Let's say "hypothetically" this standard is dumb. Is it possible to have a second set of formatting rules that get automatically applied on file open, so you can work sanely?
The short answer is no, you cannot specify one set of formatting rules when opening a file, and another set of formatting rules when saving a file because Eclipse does not provide the functionality to reformat a file using different formatting rules on open. But even if that were true, you would still have problems:
You open your file and Eclipse automatically uses your "good" formatter.
You work on the file and save it because you are going to lunch (or Eclipse autosaves while you are on the phone), and the "dumb" formatter is automatically used.
You would now have to close the file and reopen it to resume using the "good" formatter.
However, an alternative approach that would achieve what you want with very little effort is:
Create your own profile with your "good" formatting rules (e.g. For Java use Window -> Preferences -> Java -> Code Style -> Formatter -> New...).
Make that the active profile for the project you are working on (e.g. For Java use Window -> Preferences -> Java -> Code Style -> Formatter -> Configure Project Specific Settings...).
Make your changes and test locally using the "good" formatter, but immediately prior to committing any changes to source control switch to using the "dumb" formatting rules.
Of course that approach is potentially disastrous if you fail to revert a modified file to use the "dumb" formatter; a one line change in the source could result in thousands of differences within source control due to reformatting.
Perhaps I'm being unfair, but your question sets off flashing red warning lights in my head. Is it simply that you don't like the formatting rules that have been laid down? If not, what would be a scenario where the hypothetical approach you describe would make good sense?

Netbeans automatic code completion of variables

I found an interesting Stackoverflow topic, but it is an old one and I'm afraid people won't be reacting anymore, so I hope it is ok to create a new one.
First of, I am using Netbeans 7.2 and I want to use automatic code completion more. It works nice on methods/classes with the '.' already, but I would like it for the variable names aswell.
So I found this topic: How can I make auto completion in netbeans include both variables as well as methods? , more precisly the accepted answer.
This is what I have always wanted! Except one issue, it decides to automatically insert the name if only one result is available, while I am still typing unaware of that fact.
I have tried disabling Insert Single Proposals Automatically (Tools -> Options -> Editor -> Code Completion), and it does kind of work. But once I type the next letter, it still decides to complete it automatically.
Does anyone know a fix for this or another way to achieve the same?
Regards.
Ah, I found it now: If you want it as I described in the opening post, then set this for Completion Selectors in Java:
[.,;:([+-=] (Note the extra white space on the end, it is important.
Now it will not autocomplete on any character anymore, but still give you the suggestions box.
Go to (Tools -> Options -> Editor -> Code Completion)
Select Language Java
add tick to Auto Popup on Typing Any Java Identifier Part
and you can tick Subword Completion

How to make Eclipse Formatter to not destroy commented out code?

A lot of my co-workers enjoy leaving behind commented out code, how to make Eclipse Formatter to not destroy formatting of that code(now it makes a big blob or block of it).
P.S. I know I can somehow configure the formatter to just ignore that code, I done it once, but I cant remember how.
In the Eclipse Formatter Settings (Preferences/Java/Code Style/Formatter) in the tab Comments UNCHECK the checkbox "Enable Block Comment Formatting" and "Enable Line Comment Formatting" These should be disabled anyway.
One option in 3.6 would be to tell Eclipse not to format these blocks, using /* #formatter:off */
Another option that I use a lot when working in other people's code is to select the lines I'm working on before invoking the formatter - that way I only format the areas I've actually changed, and leave the rest untouched (to get more readable diffs etc.).
For Eclipse 3.7.1, there's a new configuration page (Off/On Tags) in the code format profiles. Make sure you've enabled them. You can also specify the exact comment off and comment on tags.