Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How is IPackageDeclaration#getSourceRange supposed to work?
How is IPackageDeclaration#getSourceRange supposed to work? [message #326034] Thu, 06 March 2008 01:00 Go to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Bug 182800
Next Topic:Highlighting related terms in a text editor
Goto Forum:
  


Current Time: Fri Apr 25 19:47:47 EDT 2025

Powered by FUDForum. Page generated in 0.05684 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top