Community
Participate
Working Groups
Version: 3.3.0 Build id: I20070809-1105 Creating a new package-info file for the non default package always results in an error and no immediate way to quick fix it. In a project with 5.0 compliance: 1. Create a package 2. Create a new file called package-info.java in the package 3. The problem view will correctly show an error about an incorrect package specification (The declared package "" does not match the expected package "foo") 4. Observe: there are no quick fixes available to the problem (either in the problems view or in the editor) 5. Insert a space and save the editor 6. The quickfix is now available The problem seems to be that the problem annotation has a position of 0 and a length of 1. This causes the annotation model to throw a BadLocationException as the document has a length of 0. Would it be possible to link this type of error with the file instead of a text position?
>Would it be possible to link this type of error with the file instead of a text >position? JDT Core should set length 0 and not invalid length 1.
JDT/Core sets the end of the marker to 1 since this is exclusive. So the problem goes from 0 inclusive to 1 exclusive. What should we change?
>JDT/Core sets the end of the marker to 1 since this is exclusive. >So the problem goes from 0 inclusive to 1 exclusive. Start is inclusive and there is nothing at position 0. You have to report start= -1 end= -1 and because you already correctly set the line number to 1, the error will be shown in the editor.
ProblemReporter.packageIsNotExpectedPackage() uses 0 & 0 as the start/end. Changing these values to -1 & -1 does not improve anything, it actually makes the case of a single space, worse. No quick fix shows up at all. Also tried 0 & 1, and -1 & 0. 0 & 0 is the only pair that causes a quick fix to show up when a space is added. No quickfix appears with any values, if the file is empty. So Dani, why should we change from 0 & 0 to -1 & -1 ?
Hi Kent, the initial problem is with the MARKER values which are currently set to start=0 and end=1. This causes a BadLocationException on our side as the document has no characters at all and also disables the quick fix in the Problems view. On the marker you should either not set start and end at all or set it to 0,0. -1/-1 is Platform Text convention and not specified directly on CHAR_START/END. Now when it comes to the temporary IProblem reported during reconcile JDT Core has a problem in the definition of IProblem.getSourceStart/End() because both are declared as being inclusive, hence you cannot report the difference between x ^ bug at first character in document i.e. 0/0 and the case when the document is empty. As you can see, this can be expressed with the marker by either setting it to 0/0 or better: not set it at all. A workaround could be to use -1/-1 on your side for the problem position i.e. unknown as speced in Javadoc. I committed code on the JDT Text side to handle such IProblems (this was missing on our side).
Created attachment 79360 [details] Possible Fix
Well in that case, why don't we use 0 & -1 ? The marker would then be created with 0 & 0.
Changed my mind, instead we'll detect a source end position of 0 and leave it alone when we're creating the marker. There are numerous problems created with 0 & 0 as their positions, so we'll leave all of them alone, and create the marker differently.
>There are numerous problems created with 0 & 0 as their positions That's what I also suspected. I might to adjust our code regarding 0/0 as well.
Fixed up positions in tests from BuildpathTests, ErrorTests & MultiProjectTests Released into HEAD for 3.4M3
Adjusted JDT Text side and tested it.
Added org.eclipse.jdt.core.tests.builder.PackageInfoTest#test003 as a regression test.
Verified for 3.4M3 using I20071029-0010 build.