Community
Participate
Working Groups
Source files get enriched with nasty whitespace while editing them with Eclipse. It seems to originate mainly from the smart indentation feature (as well as from the programmers' sloppiness). This little deficiency turns out to be really bad when many programmers work on the same project that is backed by a source code management system (particularly when different editors are used). Then differences between revisions tend to consist of whitespace. However trimming trailing whitespace from each line when saving a file would minimize the problem.
Could you please add concrete examples/bug reports where you see this happening and also tell us which build. Set bug resolution from REMIND back to open once you added this information.
The phenomenon can be studied in Eclipse versions from about 2.0 up to the latest Builds. As a rule of thumb, the higher the source file's revision number is, the more of this ws gets into it. It spawns like rabbits :-) A simple example: class A { void f() { Object l_obj;| <- The caret is here. Now press <return>. } } => class A { void f() { Object l_obj; _______<- Eclipse has inserted whitespace for indentation (indicated by _) here } } Now once again hit <return>. The inserted whitespace will stay on the empty line forever unless you delete it by hand or you open the file in an editor thet strips off trailing whitespace on each line. Here are some of my code formatter properties: org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.newline.emptyBlock=do not insert org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.lineSplit=120 org.eclipse.jdt.core/org.eclipse.jdt.core.codeComplete.fieldPrefixes=m_ org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.newline.openingBrace=insert org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=w arning org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.newline.controlStatement=ins ert org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.space.castexpression=do not insert
void f() { Object l_obj; _______<- Eclipse has inserted whitespace for indentation (indicated by _) here } } Now once again hit <return>. Would you expect this: void f() { Object l_obj; <no spacing> <caret at beginning of line> } } And then you manually add the Tab or it jumps autmatically to the correct indentation when typing? The first solution is not "smart typing" and the other one would be too noisy in the UI. If you don't like the smart mode you can change it by pressing "Insert" key or clicking on "Smart Insert" in the status field. You will then get the normal I-caret and smartness will be gone i.e. no spaces will be inserted.
... Now once again hit <return>. What I would expect is class A { void f() { Object l_obj; <no spacing> <caret at the correct indentation position> } } A less sophisticated solution for the problem would be to strip trailing whitespace from the end of each line when saving the source file.
The 80% case when typing in your last scenario is that you continue at the indented location. I support your last suggestion. *** This bug has been marked as a duplicate of 25360 ***