how to turn off break line in eclipse - java

Does anybody know how to turn line breaking in eclipse after you press CTRL + SHIFT + F (code format), ex :
System.err
.println("Incorrect file name, make sure you include .extension with your file name");

Go to Window->Preferences->Java->Code Style->Formatter. Create new formatter. Click on edit and then pick tab Line Wrapping and set Line Wrapping policy to Do not wrap.

The default line wrapping in Eclipse is really rather irritating and the main reason why is that the 'line width' is set as 80 characters, clearly a hangover from the nineteen eighties. This really should be updated now that everyone uses high resolution monitors instead of 80 char wide punch cards.
You probably don't want to turn it off entirely but instead you want to change the 'line width' to something more sensible (otherwise when you use the auto formatter you may get lines of code that go on forever).
I would suggest a value of 140, which seems to work nicely for most of us now using 1080p monitors.
In order to do this you need to...
With-in Preferences, navigate to...
> Java
> Code Style
> Formatter
You can't edit the default profiles so you have to hit New... and type a name like 'Eclipse 140 Line Width' for your profile and OK.
Then Edit the profile
Change to the Line Wrapping tab
Change the Maximum Line width from 80 to 140.
Then OK your way out.
If you then want to fix up your existing code, select your target code and use the Source > Format menu option.

In Helios, set 'Line Wrapping/Function Call/Indentation Policy' to 'Indent on Column' for all cases. This seems to stop the pathological case where it splits a line to try and fit within a fixed width but ends up with it further to the right than it would have been unsplit.
Or, as suggested above, disable line wrapping, or set a very wide line width. But I find it better to have it wrap and get it right than not to wrap at all.

There is an option "never join wrapped lines". This will help to keep our custom wrapping unchanged. Great Feature.

Related

Changing the priority of markers in eclipse

When I set a break point on a row which already has a marker(The value of the local variable is not used) on it, I cannot see the break point marker; because the yellow lamp marker covers the break point marker.
Is it possible to change the priority of the markers so that the break point sits on top of the lamp marker?
As long as #Mena answer is ok, as he sais...
Use at your own risk :)
This can be dangerous in a big project.
To avoid problems with hided warnings due configurations, what I usually do is:
Leave config as is, to see warnings.
Remove all really unnecessary lines causing warnings
Add an annotation to method still having warnings but needing breakpoint at same line. You can annotate class if necessary when massive warnings or breakpoints needed.
#SuppressWarning("unused")
public void yourMethod() {
}
This will allow you to handle warnings individually and see breakpoints when necessary.
I find that incredibly annoying too.
The only solution I've found is to go to the Java editor preferences, and disable the checkbox "Report problems as you type".
This will not change the priority, it will disable the hint and only show the breakpoint.
Here's a picture to illustrate:
Use at your own risk :)
Finally a TRUE relief after years of a so annoying and tiny thing:
1) go to your eclipse install path and look for all files (filename) that contain the word "warn" and are of the format .gif or .png (because they contain transparency data), here there were 5 files whose icon/image matched, most were named as: quickfix_warning_obj.gif (or.png)
2) rename all of them to *.DISABLED like "quickfix_warning_obj.gif.DISABLED", and as soon you restart eclipse, this will force it to restore the right one as soon you open an editor that uses it and has some warning on it.
3) having detected the right file, replace it with one of identical size (width and height in pixels), I would like to suggest this image I just created, so simple and not annoying at all and still is useful!
4) restart eclipse again and clap with a smiling face!
PS.: you can try to just replace this file also, that was the right one here for Eclipse Luna:
$ECLIPSE_INSTALL_PATH/configuration/org.eclipse.osgi/478/0/.cp/icons/full/obj16/quickfix_warning_obj.gif
Obs.:
Of course you can replace all of them that look the same, change other annoying icons and so on, and experiment with your own gif/png size and image, just that these steps is what worked perfectly here.
The image I supplied is almost invisible some times, but they were never really useful to me as I let the code with warning become underlined as a highlight. A better image is welcome :)
And, of course, this is a workaround, like a theme change, that does not involve any coding/recompiling of eclipse, therefore the priority is not changed at all, but the results are good enough to me at least.
EDIT: here one for the search results: searchm_obj.gif at configuration/org.eclipse.osgi/331/0/.cp/icons/full/obj16/searchm_obj.gif on Luna

What's going on with CheckStyle's line length check?

I have CheckStyle set to check for lines over 80 characters in Eclipse, and I have a margin line set up in my editor at 80 characters. If I put my cursor at the end of a line of code in my editor, the co-ordinates read (for example) 1433, 77, indicating the 77th character column from the left - yet when I run CheckStyle over the same line it says the line is 88 characters long! There are no extraneous tabs or other whitespace characters at the end of the line, it's definitely 77 long. Is CheckStyle broken?
From the Checkstyle documentation:
The calculation of the length of a line takes into account the number of expanded spaces for a tab character ('\t'). The default number of spaces is 8. To specify a different number of spaces, the user can set TreeWalker property tabWidth which applies to all Checks, including LineLength; or can set property tabWidth for LineLength alone.
http://checkstyle.sourceforge.net/config_sizes.html#LineLength
To do this in Eclipse:
Open Window->Preferences from the Menu.
Select Checkstyle.
Type TreeWalker into the search box under Known modules.
Select TreeWalker on the list on the right.
Click Open.
Change the tabWidth to 4.
Click OK, and OK again.
Is CheckStyle broken?
Probably not.
I expect you/Eclipse and CheckStyle have a different idea of the width of a TAB character. It sounds you think it means 4 spaces, whereas CheckStyle thinks it means 8 characters (its default).
One way around this is to configure Eclipse to not use TAB characters in your source file, then re-indent your source files.
Another way is to make use that CheckStyle and Eclipse agree on the TAB width; e.g. see #MartinEllis's answer.
(I prefer the first approach because it means that my source code will look correctly indented, irrespective of the platform's default TAB width; i.e. Windows versus Linux/Unix. Hard TAB characters in source code are a bad idea.)

How do I extend the margin of the Eclipse source formatter?

Whenever I use Source > Format in Eclipse, it wraps the line starting at row 80. But my program has a lot of long lines and I'd like to extend its tolerance to 120. I've tried searching for a setting where I can change this but can't find one. Can this be done?
You can find it under Preferences->Java->Code Style->Formatter.
Click on the Edit button next to the currently active profile, go to the Line Wrapping tab and change the Maximum line width setting.
Go to Window/Prefences and open Java/Code Style Formatter. Then edit the profile. You can change the margin on the "Line Wrapping" tab ("Maximum line width").

Is it possible to modify Eclipse's comment behavior to add the slashes at the current level of indentation, rather than at the beginning of the row?

By default, pressing the Comment out shortcut keys Ctrl + /, has behavior like this:
Notice that the // get added at the left-most position of the row.
Is there a way to set it so that the // appear at the same level of indention as the code that is being commented out?
e.g.
Perhaps a Python habit, but I find it much easier to parse when everything is at the same indention level.
Is there a way to change where the slashes show up?
Yes, it's possible.
go to this link for detailed info
First go to Preferences, then
On the left side of the box, expand the Java option, then expand Code
Style and finally click Formatter
You'll land on the Java-Profile page:
The other, temporary way is via CTRL+SHIFT+F shortcut ( Eclipse: Change the block comment style of ctrl+shift+/ ) . So you'd highlight those comments, and press the combo.
I would then also use a shortcut for CTRL+SHIFT+F , like ALT+F5 (press CTRL+3 , 'keys' to get the preferences page.

Insert line break in editor

I'm trying to add a line break with the Find function in eclipse - What I want to do is put a line after each method in all my classes [I liked them all close together but now its hard to read through]. so I figure theres 2 ways to do this.
1. Find all with "public" and change to "\npublic", \n being the new line in a string to give you the idea of what I mean.
2. A convenient eclipse shortcut that separates all the methods in a class with an empty line.
Any ideas on how to achieve this? I'll be happy as long as it works and I don't have to go through every method in the project myself and push enter .-.
For #2, you can set the Eclipse auto-formatter to do so for you.
Look under the Preferences panel; in the left side (tree), select Java Code Style (click the arrow to expand the section), then Formatter. You can then decide to use a single formatting style for all of your projects, or check the box to apply a special set of formatting rules to just the current project. Some of the options include where to locate whitespace and newlines.
You can also use the “Save Actions” panel to re-apply the same formatting rules every time you save your files. Personally, I use (and team members as well) this method, to ensure that the formatting for the files is always consistent. By mechanically reformatting in this way, changes to the file will always show up “properly” in Subversion/Git — I don't accidentally have whitespace-only changes being introduced into files showing up as “false positive” changes.
Check box 'Regular Expressions' and use '\R' for Linebreak in the 'Replace with' box in eclipse
configure the auto-formatter its a bit of work for the first time but its worth, when ever you get ugly formatted code you can fix this in seconds ..

Categories

Resources