Community
Participate
Working Groups
The source formatter does not format a source file if it contains assert statements. No errors are logged. I have compiler compliance and source compatibility are set to 1.4 Simple example: public class Dummy { void doNothing(String bomType) { assert 1==2 : "junk"; String s="x"; // code formatter is configured to insert spaces before and after // assignment operator // // Source -> Format does not insert spaces round "=" UNLESS assert is // commented out } }
Do you set your compiler settings per project or is it a global setting?
Moving to JDT/UI. The code formatter is not called with the compiler settings. It has no idea that the source needs to be parsed in 1.4 mode. The method ToolFactory.createCodeFormatter(Map options) needs to be called with the options relative to the source that needs to be parsed. It could be project based or a global settings. The code formatter is using this option JavaCore.COMPILER_SOURCE defined on JavaCore to find out if assert is a keyword or an identifier.
I verifuied that JavaCore.COMPILER_SOURCE = 1.4 is passed. The fomatter doesn't seems to look at it. - Set the compiler prefeences to source compatibility 1.4, class files 1.4, assert as identifier 'error'. - select the following code public class A { private void foo() { assert true : "Hello;"; int i = 9; } } nothing happens. - breakpoint at ToolFactory.createCodeFormatter shows that JavaCore.COMPILER_SOURCE = 1.4 is passed
*** Bug 52771 has been marked as a duplicate of this bug. ***
Fixed and released in HEAD. Regression test added.
Verified for 3.0 using build I200403250010. Note that this work only when workspace compiler options are set. It does not work when only project options are set to 1.4 compliance. As code formatter rely on UI for these options, I've opened bug 56142 against jdt-ui for this issue...