I've started working with Intellij (used Eclipse before), and I can't seem to mimic the eclipse formatting
the Eclipse Code Formatter plugin did most of the work, but there are still some differences.
for example:
Original line:
object.add(new ClassForSomething(param1, param2, paramObj.method()));
with IntelliJ formatting:
object.add(new ClassForSomething(param1, param2, paramObj
.method()));
with Eclipse formatting:
object.add(new ClassForSomething(param1, param2,
paramObj.method()));
where do I find the configuration to adjust my intelliJ formatter to what I used to have on the eclipse?
EDIT 1:
I've uploaded my code style --> wrapping and braces configuration
In Preferences > Editor > Code Style > Java > Wrapping and Braces
Method call arguments - Do not wrap
Take priority over call chain wrapping - True
Here's a screenshot:
I reproduced the method splitting behaviour you described and then 'fixed' it with the settings I propose here. However, there are so many formatter configurations, some of which impact each other, that it's possible I haven't reproduced exactly what you are seeing. If so, then I'd suggest trying the following:
Save your Java Code Style to a project specific version then start changing its configuration one item at a time until you find the right one.
Export your Eclipse codestyle (from Eclipse’s Preferences > Java > Code Style > Formatter and export the settings to an XML file via the Export All button) and then import that into IntelliJ (see screenshot below) ... perhaps IntelliJ can work out the correct configuration from the Eclipse formatter.
Check File -> Settings -> Code Style -> Java -> Wrapping and Braces. Make sure "Chained method calls" is set to "Do not wrap" and two squares are unchecked.
Related
Eclipse Version:2018-09 (4.9.0)
Plugin "Code Recommenders for Java Developers": 2.5.4.v20180909-1131
My Eclipse autocompletion does a little more than I like when it completes generic classes.
Example:
when(component.method(param)).thenReturn(Opt... [Press Strg+Enter])
Current Behavior
when(component.method(param)).thenReturn(Optional<Type>)
Wanted Behavior
when(component.method(param)).thenReturn(Optional)
I only want to complete the class name in order to call a static method (Optional.of(...)), but now I first have to delete the type and the diamond brackets.
What I found so far
This is old but partly similar: Eclipse Auto Complete: Java 1.7 Generics Diamond
The wanted behavior in this case is an empty diamond operator when creating a new instance. This issue seems to be fixed since 2014.
The plugin Code recommenders is mentioned there and that you can specify what eclipse will offer as autocompletion at
Eclipse -> Window -> Preferences
-> Java -> Editor -> Content Assist -> Advanced
Turning of the options "Java Proposals" and/or "Java Proposals (Code Recommenders)" will stop this behavior... because it turns of absolutely all Java Code recomendations.
May the force be with you!
Hello I want to ident my Java's code with the Google's style.
So I download the last version of checkstyle from the orginal source:
http://checkstyle.sourceforge.net/cmdline.html
I extract It so I get a checkstyle_packages.xml on my directory.
I run Eclipse:
In Eclipse I go to Window -> Preferences -> Java -> Code Style -> Formatter
I click Import
I select checkstyle_packages.xml
But It doesn't import anything.
What am I doing wrong ?
You might want to get the xml from here:
https://github.com/google/styleguide
You can also find JetBrains IDEA (IntelliJ) xml files in this repository which are the only ones I personally have experience with.
As far as I'm aware these don't require the use of checkstyle.
I'm using IntelliJ 12 and
It's putting my member variable annotations on the same line, which i hate! How do I setup the code formatter to keep annotations on separate lines?
thanks!
Navigate to Preferences → Editor → Code Style → Java → Wrapping and Braces tab, then locate the section Field annotations and check the option Do not wrap after single annotation.
In IntelliJ v14:
In IntelliJ 12 You can find it in setup here (bottom right):
I think all the above answers are correct but here is step by step for Mac users:
Click on "IntelliJ IDEA"
Click on "Preferences"
Go "Code Style" on the left navigation window and you will see "Java" listed below it and Click on it !
Look for the header tab "Wrapping and Braces" on the right side of Preferences window.
At this point you want to look for the item called "Do not wrap after single annotation" under "Field annotations". click "ok" and you are done !
Nothing seemed to work for me with version 2.3.3 or Android Studio. I gave up and checked Line breaks under Keep when reformatting. I just have to be very careful when I add line breaks.
Is there a way to have an IDE fix Checkstyle errors automatically without having to fix each manually?
If you are using IntelliJ, you can install the CheckStyle IDEA plugin.
Then import the CheckStyle settings into the editor, and Reformat like normal (Ctrl+Alt+L is default shortcut key).
If you're using Eclipse, yes. You can't correct all problems though. There are two ways:
Right click on the java file in Package Explorer or whatever, and select 'Apply Checkstyle Corrections'.
Click on the error in the problems view, and select 'Quick fix'. This corrects the problem.
Your question is rather vague, but I think what you're asking is if CheckStyle can automatically reformat code that it's checking to fix code layout problems that it finds.
The direct answer here is "no."
However, there are a number of "Java source code formatters" (google that, choose one) that will do what I believe you're asking for.
There is a way to do this every time you save your file but not all warnings in Checkstyle can be fixed automatically.
You can have Checkstyle generate a formatter for you by right clicking on your package in the Package/Project explorer and selecting Checkstyle->Create Formatter-Profile. This will create a new formatter called eclipse-cs [your-package-name] based off of your Checkstyle configuration. You'll find it in the "Active profile" drop-down in the formatter preferences of Eclipse.
You can then set the formatter to run each save by going to Preferences->[Language of Choice]->Editor->Save Actions. Check the "Perform the selected actions on save" and "Format source code" boxes.
I created a feature request for the Eclipse checkstyle plugin to also support quick fixes from within the code editor:
https://sourceforge.net/p/eclipse-cs/feature-requests/150/
I used jalopy. Create Tool to fix the Check style issues.
When I reformat code with Eclipse, it turns method headers like this:
public void myMethod(String param) {
into method headers like this:
public void myMethod(
String param) {
When I was brought on here I'd never used Eclipse before, and I imported project settings provided by someone else. I have seen that on small new projects I've worked on Eclipse does not do this, so it must be in the settings I've imported. But I've gone through every panel I can find, as well as every hidden file I can find in the workspace, and I can't figure out what is causing this.
How do I turn it off? I don't want a newline before parameters in my method signatures, and I can't imagine why anyone would!
Have a look at Window>Preferences>Java>Code Style>Formatter.
There you can configure almost everything. Your case is found at
Line Wrapping>Method Declarations>Parameters.
In my version of Eclipse, I found the option under Window->Preferences->Java->Code Style->Formatter, then clicked the Edit.. button.
In the new window, go to the Line Wrapping tab and find Method Declarations. You want to change the Line wrapping policy. The Force split check box seems to do the same.
Go into preferences: Java -> Code Style -> Formatter
Restore Defaults or edit what's there.
Additionally, Code Style -> Code Templates will allow you to define generate code formatting.
Note that this is for Eclipse Workspace as a whole, the same Preferences can be accessed under the project preferences if you want to get more fine grained at a per project level.
In eclipse you can define your code formatting use Code Style ,
for MAC System :--> Eclipse --> Preference -- > java--> code Style
for Window System :--> Window->Preferences->Java->Code Style->Formatter
The best way to change your format is to go to Window-> Preferences-> Java-> Code Style-> Formatter. Inside the formatter window, eclipse has a couple of built in styles, but the best way is create a new profile of your own by pressing on New. You can change the format as you please on the edit tab
You can change parentheses and curly braces positioning along with other stuff.