Bug 52246 - M7 Source formatter fails silently when assert present in source
Summary: M7 Source formatter fails silently when assert present in source
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M8   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 52771 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-02-17 09:47 EST by Colin Cooper CLA
Modified: 2004-03-25 09:36 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Colin Cooper CLA 2004-02-17 09:47:08 EST
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
    }

}
Comment 1 Olivier Thomann CLA 2004-02-17 11:04:15 EST
Do you set your compiler settings per project or is it a global setting?
Comment 2 Olivier Thomann CLA 2004-02-17 11:18:12 EST
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.
Comment 3 Martin Aeschlimann CLA 2004-02-20 12:24:13 EST
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
Comment 4 Martin Aeschlimann CLA 2004-02-22 14:02:58 EST
*** Bug 52771 has been marked as a duplicate of this bug. ***
Comment 5 Olivier Thomann CLA 2004-02-23 13:08:00 EST
Fixed and released in HEAD.
Regression test added.
Comment 6 Frederic Fusier CLA 2004-03-25 09:36:23 EST
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...