void main(){
runApp(MaterialApp(
home: Scaffold(
), //Scaffold
)); //MaterialApp
}
I didn't add comments, IDE did and I don't want to. How can I turn it off?
Settings -> Editor -> General -> Appearance, check box 'Show closing labels'.
Restart IDEA
I currently have Eclipse formatter set up to format an 'if-else' statement like so:
if(condition) {
return foo;
}
else{
return bar;
}
Note the space between the closing parenthesis of the condition, and the opening bracket of the true block - I'd like to remove this space.
In the formatter profile, under Whitespace -> Control statements -> 'if else', there is no option for 'after closing parenthesis'. In the Blocks section, there is an option for 'before opening brace', however this appears to only apply to the false block (and is turned off anyway).
I must be missing an option somewhere - how can I turn this whitespace off?
I am using Eclipse Mars 4.5.0.
You can do that in the Windows -> Preferences -> Java -> Code Style ->formatter -> Edit profile section
I think it does once you select the other option in drop down that you can see below
This is due to Eclipse Bug # 471145 (specific to Mars / 4.5.0), which was reported on 2015-06-26, fixed on 2015-08-01, and will be included in Eclipse 4.5.1 - which should be complete and ready for download by the end of September 2015 as part of the Mars coordinated service release.
Go to Windows > Preferences > Java > Code Style > Formatter > White Space and in Control statements > Blocks, unselect the "before opening brace" option :)
When I am entering a String literal in a Java file in Eclipse, and I want to break the String into multiple lines in the source (not the String's content/value), by default Eclipse wants to put the + at the beginning of the new line instead of at the end of the previous line.
For example, where | represents the text cursor:
String str = "This is a really long line which I would like| to break into several."
When I hit Enter, it now looks like:
String str = "This is a really long line which I would like"
+ " to break into several."
But I want it to look like:
String str = "This is a really long line which I would like" +
" to break into several."
Where in Eclipse can I set the preference for where this + goes?
You could either try the link that I have mentioned in my comment earlier or try the below settings. In my Eclipse, the settings were different, If you go to the "Preferences > Java > Code Style > Formatter" you have an Active Profile which you can Edit. Please find below the settings.
Preferences > Java > Code Style > Formatter -> Edit -> Line Wrapping Tab -> Expressions -> Binary Expressions -> Line Wrapping Policy -> Wrap where necessary -> (check box) Wrap before operator
I'm using Eclipse Luna 4.4.0 and Eclipse formatter takes this code:
users = getSingleColUserList(new XSSFWorkbook(fileInputStream),
userId, profCol);
and drops the method call onto a new line:
users =
getSingleColUserList(new XSSFWorkbook(fileInputStream),
userId, profCol);
As you can see, the line width is not the issue. It's not at all obvious what setting in the formatter dialog I need to change.
[UPDATED after Seelenvirtuose's answer]
I can set Eclipse to format Line Wrapping -> Assignments to Do not wrap. However that raises another issue with lines then not getting wrapped when they go over the line width:
List<Map<String, Object>> emailMap = jdbcTemplate.queryForList(DBQueries.LOAD_EMAILS);
The line width is 80 which is either the s or the . of DBQueries so it should be:
List<Map<String, Object>> emailMap = jdbcTemplate.queryForList(
DBQueries.LOAD_EMAILS);
None of the settings that I have tested for Line Wrapping -> Function Calls -> Arguments
It's cute that my browser is currently displaying a scrollbar under the unwrapped code!
It is the formatter's setting for "Line Wrapping -> Assignments". Set it to "Do not wrap".
I'm extremely frustrated with the Eclipse formatting rules for a series of qualified invocations (i.e., the Builder pattern style). For example, here is my preferred formatting for some code that creates a new Apache Commons CLI Options object:
Options options = new Options()
.addOption(OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit")
.addOption(OptionBuilder.withLongOpt(OPTION_PROPERTIES)
.hasArg()
.withArgName("FILE")
.withType(File.class)
.withDescription("specify a user properties file")
.create());
I.e., parameters are wrapped and indented if necessary and all qualified invocations except the first, unless necessary, are wrapped and indented if there is more than one. If a parameter list wraps inside a qualified invocation, the invocation should wrap first.
The default formatting in Eclipse ("Wrap only when necessary" for arguments and invocations) yields the following mess:
Options options = new Options().addOption(
OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit").addOption(
OptionBuilder.withLongOpt(OPTION_PROPERTIES).hasArg().withArgName(
"FILE").withType(File.class).withDescription(
"specify a user properties file").create());
Going into "Java Code Style -> Formatter -> Line Wrapping" and the line wrapping setting to "Wrap all elements, except first element if not necessary" for invocations yields:
Options options = new Options().addOption(
OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit")
.addOption(
OptionBuilder.withLongOpt(OPTION_PROPERTIES).hasArg().withArgName(
"FILE").withType(File.class).withDescription(
"specify a user properties file").create());
I don't like that the OptionBuilder expression isn't being wrapped, or that "FILE" gets wrapped without also wrapping withArgName.
Changing the indentation to "Indent on column" yields:
Options options = new Options().addOption(OPTION_HELP_SHORT, OPTION_HELP,
false, "print usage information")
.addOption(OPTION_VERSION_SHORT,
OPTION_VERSION, false,
"print version and exit")
.addOption(
OptionBuilder.withLongOpt(
OPTION_PROPERTIES)
.hasArg()
.withArgName("FILE")
.withType(File.class)
.withDescription(
"specify a user properties file")
.create());
The is breaking the lines where I'd prefer, but pushing things over much too far to the right.
Is there any way to convince Eclipse to apply my preferred formatting style or something closer to it than any of the above?
Turning off formatting with comments, or inserting line comments is too tedious.
The best way is described here:
... or you can select "Line Wrapping > Never join already wrapped
lines" globally. Then, you can break it manually and the formatter
will only format inside lines (or add additional line breaks if
necessary).
With this setting Eclipse formatter will stop ruining your builder statements.
Use comments:
Object o = foo() //
.bar() //
.toString();
Update for 2021. It is possible to change, navigate to: Code Style -> Formatter -> Line Wrapping -> Wrapping settings -> Function Calls -> Qualified invocations and change value to "Wrap all elements, except first element if not necessary"
In Eclipse 3.6 It's possible to turn off formatting for a region of code. See my answer to
How to turn off the Eclipse code formatter for certain sections of Java code?
AFAIK, this is known problem with Eclipse Formatter:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=59891
On the menu select Window -> Preferences when the window opens select Java -> Code Style -> Formatter and from there you can create your own format style to use by selecting the new or edit option. When editing a formatting profile a new window opens that gives you a lot of different options to use.