Removing trailing spaces in eclipse -- FROM THE COMMENTS
Asked Answered
T

3

14

Preferences -> Java -> Editors -> Save Actions Check "Perform the selected actions on save", then check "Additional actions" and click the "Configure.." button. In the "Code organizing" tab, check "Remove trailing whitespace"

That will do the job for any normal code, however this does not look to have any effect on the comments. Is there any way to automatically get rid of trailing spaces from the commented lines?

Thanks,

p

Tetzel answered 26/1, 2012 at 13:54 Comment(6)
Works as described on both single comment lines // and /* */. Version: Indigo Release Build id: 20110615-0604Centrosome
Works for me too, Build id 20100917-0705.Kalin
Doesn't work form me, Version: Indigo Service Release 1 Build id: 20110916-0149Nicko
Doesn't work for javadoc comments, works for other commentsTetraploid
also having this issue, the problem is definitely the javadoc comments auto-inserting spaces, and then there is no way to auto-remove them. Anyone know a way around this?Seaside
IIRC this issue has been annoying some (most?) Eclipse users for at least a decade.Lisle
W
3

This is something i've tried to remove trailing space:

Window->Preferences Jave->Editor->Save Actions Enable Perform the selected actions on save. Enable Additional actions. Click Configure.

In the Code Organizing tab, enable Remove trailing whitespace for All lines. Review all the other options there, since it will all happen automatically whenever you save -- make sure there isn't anything there you don't want. Dismiss the Configure window.

Review the other options under Save Actions, since these will also happen automatically now. Don't forget to click Apply in the Save Actions preference page. it should be fine.

Will answered 12/7, 2014 at 2:35 Comment(0)
N
0

I've contracted same trouble recently and it seems impossible to handle within IDE without any external tools. This is what worked for me:

sed -i 's/\s\+$//' MyClass.java
Nowicki answered 4/10, 2012 at 15:3 Comment(0)
S
-1

The normal way to format your code (and of course your comments/javadoc) is with a customized formatter. See Preferences/Java/Code Style/Formatter Button "Edit" => Tab "Comments", Option "Enable Javadoc formatting", etc. and then to click "Format source code" as an automatically save action.

Sacha answered 28/6, 2012 at 14:33 Comment(1)
Didn't work for me. Ordinary comments were fixed, but javadocs stand still·Bajaj

© 2022 - 2024 — McMap. All rights reserved.