Community
Participate
Working Groups
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.
Philippe, Let me know if you want to fix this. I could be done in the same time than bug 111703.
Feels like a good change. We should also reduce the scope of other errors as well.
Change only in 3.2 stream
What other errors are you talking about?
Fixed and released in HEAD. Adapted test161 in the NegativeTests and test038 in the AssignmentTest.
Other reported problem locations, i.e. only highlight selector for a message send etc... generalizing ProblemReporter#fieldSourceStart --> problemSourceStart(ASTNode)
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.
Verified for 3.2 M3 using build I20051031-0010