Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 521959 - a getter for TextSelection.fDocument
Summary: a getter for TextSelection.fDocument
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Mickael Istria CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 521960
  Show dependency tree
 
Reported: 2017-09-06 16:50 EDT by Mickael Istria CLA
Modified: 2017-11-20 10:53 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mickael Istria CLA 2017-09-06 16:50:48 EDT
TextSelection can host a reference to the source document. In many cases, knowing the source document is very valuable and many clients could take advantage of it.
TextSelection should provide a public getter for the document.
Comment 1 Mickael Istria CLA 2017-09-06 16:56:42 EDT
getDocument() method is currently protected, and TextSelection allows subclassing. Some existing class may already override getDocument() and keep the package visibility. If we make the visibility `public` in TextSelection, extensions overriding it with a more restricted visibility would show a compilation error.
What would be the best procedure to handle this?
Should we create a new public final method that delegates "getDocument()"? If so, how to call it?
@Dani: Your advice would be extremely valuable there.
Comment 2 Nitin Dahyabhai CLA 2017-09-06 19:37:31 EDT
Is there a concrete use case for this?
Comment 3 Mickael Istria CLA 2017-09-07 01:28:09 EDT
Yes, see bug 521960 which has to deal with reflection.
In general, just adding that makes it possible to adapt a TextSelection to something, whereas the lack of public accessor for Document makes it impossible to adapt or use a TextSelection to define a common handler enablement for Project Explorer and Text Editor for instance (just check selection adapts to the desired type and the same handler cover both).
Comment 4 Mickael Istria CLA 2017-09-07 17:28:28 EDT
I also happen to use a similar adapter (with the same need for a getter) in BlueSky.
Comment 5 Mickael Istria CLA 2017-09-11 09:49:52 EDT
and also in LSP4E today, where I just want to check whether the selection is a TextSelection and whether the "document being selected" is associated with a language server.
Now that I know a TextSelection can provide the document, I see usage of this method everywhere and many handlers made more generic by relying on the selection rather than on the editor type.
Comment 6 Dani Megert CLA 2017-11-20 10:28:07 EST
(In reply to Mickael Istria from comment #3)
> Yes, see bug 521960 which has to deal with reflection.

Reflection is a no go. It is not maintainable.


The text selection is meant to be used along with viewers and is a UI concept. The document is internal knowledge that must not be revealed from the selection itself.
Comment 7 Mickael Istria CLA 2017-11-20 10:32:05 EST
This request/bug is exactly necessary to avoid reflection in clients such as JDT. Why do you mark it as WONTFIX ?
Comment 8 Dani Megert CLA 2017-11-20 10:36:59 EST
(In reply to Mickael Istria from comment #7)
> This request/bug is exactly necessary to avoid reflection in clients such as
> JDT. Why do you mark it as WONTFIX ?

Since it is not OK to access the document from the UI selection. I'd have to look at the other bug how to avoid reflection.
Comment 9 Mickael Istria CLA 2017-11-20 10:44:16 EST
(In reply to Dani Megert from comment #8)
> Since it is not OK to access the document from the UI selection.

Why? I don't think it's a layer breaker as Document is part of jface.text, like TextSelection, and the API could say that the Document can be still be null.
Comment 10 Dani Megert CLA 2017-11-20 10:49:05 EST
(In reply to Mickael Istria from comment #9)
> (In reply to Dani Megert from comment #8)
> > Since it is not OK to access the document from the UI selection.
> 
> Why? I don't think it's a layer breaker as Document is part of jface.text,
> like TextSelection, and the API could say that the Document can be still be
> null.

Because when you get the selection (e.g. offset) from the text selection object, the document can already be changed and the data/selection you fetch from the document is wrong.
Comment 11 Mickael Istria CLA 2017-11-20 10:53:04 EST
(In reply to Dani Megert from comment #10)
> Because when you get the selection (e.g. offset) from the text selection
> object, the document can already be changed and the data/selection you fetch
> from the document is wrong.

Ok, I see. It makes sense.