Bug 111812

Summary: [compiler] should improve error highlighting for static initializer errors
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: philippe_mulet
Version: 3.2   
Target Milestone: 3.2 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Olivier Thomann CLA 2005-10-06 13:43:59 EDT
Following of bug 111703, we should improve error highlighting for static
initializer. We are underlining the whole static initializer. I suggest to
highlight only the opening brace.

For example, on the test case from bug 111703, we now report:
----------
1. ERROR in D:\tests_sources\X.java
 (at line 27)
	static {
                      myTree.addTreeSelectionListener(list);
                      }
	      
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Cannot define static initializer in inner type new ActionListener(){}
----------
2. ERROR in D:\tests_sources\X.java
 (at line 28)
	myTree.addTreeSelectionListener(list);
	^^^^^^
Cannot make a static reference to the non-static field myTree
----------
2 problems (2 errors)

I suggest:
----------
1. ERROR in D:\tests_sources\X.java
 (at line 27)
	static {
	       ^
Cannot define static initializer in inner type new ActionListener(){}
----------
2. ERROR in D:\tests_sources\X.java
 (at line 28)
	myTree.addTreeSelectionListener(list);
	^^^^^^
Cannot make a static reference to the non-static field myTree
----------
2 problems (2 errors)

This would help the user to locate the error without the whole body of the
static initializer or I could start the highlighting on the static keyword, but
this could lead to the same issue in case of javadoc comment before the static
initializer.
Comment 1 Olivier Thomann CLA 2005-10-06 15:28:57 EDT
Philippe,

Let me know if you want to fix this. I could be done in the same time than bug
111703.
Comment 2 Philipe Mulet CLA 2005-10-07 03:35:58 EDT
Feels like a good change. We should also reduce the scope of other errors as well.
Comment 3 Philipe Mulet CLA 2005-10-07 03:36:16 EDT
Change only in 3.2 stream
Comment 4 Olivier Thomann CLA 2005-10-07 08:45:30 EDT
What other errors are you talking about?
Comment 5 Olivier Thomann CLA 2005-10-07 08:48:15 EDT
Fixed and released in HEAD.
Adapted test161 in the NegativeTests and test038 in the AssignmentTest.
Comment 6 Philipe Mulet CLA 2005-10-07 09:30:34 EDT
Other reported problem locations, i.e. only highlight selector for a message
send etc... generalizing ProblemReporter#fieldSourceStart -->
problemSourceStart(ASTNode)
Comment 7 Olivier Thomann CLA 2005-10-07 09:34:40 EDT
I will open a new bug report for this.
This is a more general problem than this specific one for initializer. It should
consider source start and source end.
Comment 8 David Audel CLA 2005-10-31 06:21:07 EST
Verified for 3.2 M3 using build I20051031-0010