How is IPackageDeclaration#getSourceRange supposed to work? [message #326034] |
Thu, 06 March 2008 01:00  |
Eclipse User |
|
|
|
Originally posted by: no.ddress.now
IPackageDeclaration#getSourceRange is sometimes returning a range
specific to the package statement, but othertimes that includes the
package JavaDoc block.
So, for a file:
/** hello */
package com.mypackage;
....
when the ITextEditor (ICompilationUnitEditor actual) is first opened,
before any modification or save, IPackageDeclaration#getSourceRange
returns:
offset=15 and length=22.
After any editor UI/user made modification is made to the file (below
the package statement) and the file saved (ctrl-s),
IPackageDeclaration#getSourceRange returns:
offset=0 and length=37.
Is this expected behavior? Or, should I be doing more/different than:
....
ITextEditor editor = (ITextEditor) part;
IEditorInput editorInput = editor.getEditorInput();
ICompilationUnit unit = JavaUI.getWorkingCopyManager().getWorkingCopy
(editorInput);
for (IJavaElement element : unit.getChildren()) {
if (element instanceof IPackageDeclaration) {
ISourceRange range = ((IPackageDeclaration)
element).getSourceRange();
....
Noteably, IMember#getSourceRange always returns a range that includes
any JavaDoc block that is present on the field, class, or method.
|
|
|
Re: How is IPackageDeclaration#getSourceRange supposed to work? [message #326163 is a reply to message #326034] |
Mon, 10 March 2008 02:48  |
Eclipse User |
|
|
|
Originally posted by: no.ddress.now
Appreciate any thoughts on this problem. Is it a bug or am I not
initializing something correctly.
Thanks,
Gerald
In article <MPG.22392857da2749e89896b7@news.eclipse.org>, no@ddress.now
says...
> IPackageDeclaration#getSourceRange is sometimes returning a range
> specific to the package statement, but othertimes that includes the
> package JavaDoc block.
>
> So, for a file:
>
> /** hello */
> package com.mypackage;
> ...
>
> when the ITextEditor (ICompilationUnitEditor actual) is first opened,
> before any modification or save, IPackageDeclaration#getSourceRange
> returns:
>
> offset=15 and length=22.
>
> After any editor UI/user made modification is made to the file (below
> the package statement) and the file saved (ctrl-s),
> IPackageDeclaration#getSourceRange returns:
>
> offset=0 and length=37.
>
> Is this expected behavior? Or, should I be doing more/different than:
>
> ...
> ITextEditor editor = (ITextEditor) part;
> IEditorInput editorInput = editor.getEditorInput();
> ICompilationUnit unit = JavaUI.getWorkingCopyManager().getWorkingCopy
> (editorInput);
> for (IJavaElement element : unit.getChildren()) {
> if (element instanceof IPackageDeclaration) {
> ISourceRange range = ((IPackageDeclaration)
> element).getSourceRange();
> ...
>
> Noteably, IMember#getSourceRange always returns a range that includes
> any JavaDoc block that is present on the field, class, or method.
>
--
Gerald Rosenberg
Certiv
|
|
|
Powered by
FUDForum. Page generated in 0.05684 seconds