Community
Participate
Working Groups
Given a list of method parameters that's longer than the maximum line length, the formatter places each paramter on it's own line. Eg. public void doSomething(String param1, String param2, String param3, String param4) gets formatted into: public void doSomething( String param1, String param2, String param3, String param4) I'd prefer the minimum number of lines be used: public void doSomething(String param1, String param2, String param3, String param4) Since I'm sure some people prefer the current style, could we have an option to control how this is handled?
Ok, so bugzilla formatted my formatting for me. Hope the message is still clear, though.
formatter is owned by JDT CORE
Will consider post 2.0
quoting some examples from Subject: When will the code formatter will abide to standard ? From: (AHoma) where I agree // // Here is how I would format it (Sun's code converntions does not say) // String[][] doubleList = { // { "alfa", "beta" }, // { "alfa", "beta" }, // { "alfa", "beta" }, // { "alfa", "beta" }, // }; // // Here is how Eclipse format it String[][] doubleList = { { "alfa", "beta" }, { "alfa", "beta" }, { "alfa", "beta" }, { "alfa", "beta" }, };
Not sure Martin's comment is the same subject, but I agree with Scott and Martin.
Resurrecting formatter issues in 2.1 stream.
Clearing resolution
I suggest indenting method parameters by *2* tabs if the code formatter has to split lines. About minimum number of lines, I don't care. Extract from org.eclipse.jdt.core.search.SearchEngine: public void searchAllTypeNames( IWorkspace workspace, char[] packageName, char[] typeName, int matchMode, boolean isCaseSensitive, int searchFor, IJavaSearchScope scope, final ITypeNameRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException { IndexManager indexManager = ((JavaModelManager) JavaModelManager.getJavaModelManager()) .getIndexManager(); [...] So where does the method body start? Indenting by 2 tabs is much better readable: public void searchAllTypeNames( IWorkspace workspace, char[] packageName, char[] typeName, int matchMode, boolean isCaseSensitive, int searchFor, IJavaSearchScope scope, final ITypeNameRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException { IndexManager indexManager = ((JavaModelManager) JavaModelManager.getJavaModelManager()) .getIndexManager(); [...] http://java.sun.com/docs/codeconv/html/CodeConventions.doc3.html#11733 also suggests using 8 spaces (which means 2 tabs for 4-space-tabs) for intending method declarations.
Sorry, I indented my suggestion with tabs, which makes the rendering Browser-dependent. Here's the correct version (with spaces): public void searchAllTypeNames( IWorkspace workspace, char[] packageName, char[] typeName, int matchMode, boolean isCaseSensitive, int searchFor, IJavaSearchScope scope, final ITypeNameRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException { IndexManager indexManager = ((JavaModelManager) JavaModelManager.getJavaModelManager()) .getIndexManager();
We need to clear 2.1 bug reports that won't be addressed before 2.1. The new implementation is still in the works. Therefore we cannot include it for 2.1. Not enough testing and we need to polish the preferences. This will be address for 2.2 as stated in the JDT/Core plan.
Resurrecting for 3.0
Reopen for 3.0 consideration.
Glad to see this back! Commenting on the comments so far... Several have commented that if the formatter must break lines in a parameter list or declaration, it should put the *first* parameter or declaration group on a new line. Something like: public void foo(ExistentialConfusion em, Solipsism s, PhilosophicalNonsense pn) { looks sloppy. Should be: public void foo( ExistentialConfusion ec, Solipsism s, PhilosophicalNonsense pn) { As a separate option, it should be possible to keep lines together as much as possible within the wrap margin. E.g., public void foo(ExistentialConfusion ec, Solipsism s, PhilosophicalNonsense pn) { The request to use "two tabs" instead of one should, at most, be an option, not the default. This would defeat the point of keeping lines together by making lines unnecessarily longer. The whole thing can be boiled down to three options: When wrap margin reached: One unit per line -or- As many as will fit First unit on new line -or- First on same line if it fits Indent continuations ___ tab stops (default 1)
This should be improved with the new formatter. Fixed and released in HEAD.
Verified.