Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Remove trailing spaces in ecilpse

Thread view: 
pd - 07 Dec 2007 04:58 GMT
guys,

i am using eclipse 3.2.2. in my preferences i have set spaces for the
tab key. now when i run checkstyle on my code, it says that the lines
contain trailing spaces. can somebody tell me how i can fix this.

i have already set the setting to spaces, so what else can i change
now. thanks.
Lew - 07 Dec 2007 05:36 GMT
> i [sic] am using eclipse 3.2.2. in my preferences i [sic] have set spaces for the
> tab key. now when i [sic] run checkstyle on my code, it says that the lines
> contain trailing spaces. can somebody tell me how i [sic] can fix this.

Is "checkstyle" part of Eclipse?

> i [sic] have already set the setting to spaces, so what else can i [sic] change
> now. [sic] thanks.

Have you examined the lines that have trailing spaces?

When did the IDE add the spaces?  What did you do, e.g., reformat the source,
hit newline, to which the IDE reacted by adding spaces at the end of the
line(s)?

Did it add them to all lines or just certain ones?  If the latter, which ones?

Sometimes IDEs will indent an empty line and it will be nothing but spaces.

public void trailingSpaces()
{
  int foo;

  String s =
"The above line has two spaces, therefore it has trailing spaces.";
}

I haven't seen them add spaces at the end of non-empty lines, though.

I use a regex search-and-replace for " +$" => "".  (Find "space-plus-dollar";
replace with empty string.)  It'll take care of trailing spaces whether or not
the line has other stuff on it.

Signature

Lew
This post contains four requests for information.  One of the five questions
is a rephrasing of the preceding one.

Lew - 07 Dec 2007 05:45 GMT
Sorry, that's five questions, of which the sixth was a rephrase.  I'll learn
my numbers someday.

Signature

Lew

Jeff Higgins - 07 Dec 2007 12:32 GMT
> guys,
>
[quoted text clipped - 4 lines]
> i have already set the setting to spaces, so what else can i change
> now. thanks.

This applies to Eclipse 3.3.0
I don't know if it applies to 3.2.2.

Go to Preferences, Java, Code Style, Clean Up.
Select Edit..., Select Code Organizing.
Check Remove trailing whitespace.
Select All lines, or Ignore empty lines.
Save your new profile.
You can run Clean Up from the Source menu.
*There is a way to run Clean Up when saving files,
but I cannot find it at this moment.
Note that this will apply ALL clean up rules.

You can also bind the Remove Trailing Whitespace
command to a key if you like.
Go to Preferences, General, Keys.
Check Include unbound commands.
Scroll to the Remove Trailing Whitespace command.
Select a key binding.
*I'm sure you can add this command to a menu item
if you wish, but I don't know how off the top of my head.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.