Community
Participate
Working Groups
3.1 RC1 1. Go to Preferences > Java > Editor > Templates; 2. Use code formatter is checked; 3. New... 4. Name: obj, Context: java, Pattern: Object obj = new Object(); Object obj2 = new Object(); When the above template is used, I get: Object obj = new Object();Object obj2 = new Object();
*** Bug 98040 has been marked as a duplicate of this bug. ***
Created attachment 22228 [details] Apply on HEAD Proposed patch. When probing, I check first for statements and then for body declarations. Your template could be seen as two local variable declaration statements or as two field declarations.
Created attachment 22230 [details] Apply on HEAD of org.eclipse.jdt.core.tests.model Regression test
+1 for RC2
Fixed and released in HEAD. Regression test added in org.eclipse.jdt.core.tests.formatter.FormatterRegressionTests.test577
For historical reason, need the old formatter API to continue to work, I revert the code to format them first as body declarations and then if it failed, as statements. Martin, what do you think? Should we format them first as statements and then as body declarations? The side effect of body declarations is an empty line between the two lines.
I think it would be not very nice to an empty line between the two lines. Also, the example above was suposed to be used inside a method, and not fields of a class, when the empty line would make sense.
The problem in this case is that there is no context given to the code formatter. So from the code formatter stand point there is no way to make the distinction between some statements or body declarations. In some cases, they might want to be body declarations and not statements.
I think the order is free to choose for jdt.core. If the templates prefer a different order they can themselves first try to format as statements then as unknown.
(In reply to comment #9) > I think the order is free to choose for jdt.core. If the templates prefer a > different order they can themselves first try to format as statements then as > unknown. This is probably what we would do - templates are typically statements, but if formatting as such fails, we could retry as unknown.
Ok, thanks. In this case it is up to you to improve this case. I keep the actual order (bodydeclarations and them statements).
Verified for 3.1 RC2 using build N20050607-0010 + JDT/Core HEAD
filed bug 98733 against jdt-text to track our side of this.
Verified for 3.1 RC2 using build I20050610-0010