How to access an editor's SourceViewer and AnnotationModel [message #330266] |
Wed, 23 July 2008 20:03  |
Eclipse User |
|
|
|
Originally posted by: kevin.oberg.baesystems.com
Hey,
I want to take the active editor and search through it and verify that
each class has a certain set of comments of the form:
/*!
\brief <brief overview of the class>
\usage <normal case usage examples>
\extending <any kind words on deriving from the class>
*/
And each function has a set of comments of the form:
/*!
\brief <brief overview of the function>
\pre <description of any pre-conditions>
\post <description of any post-conditions>
\param <parameter name> <parameter description (one line per)>
\return <return value description>
\exception <exception type> <why it could be thrown (one line per)>
*/
If there is an easy way to do this, I'm all ears. However, I am trying to
get the active editor and get at its SourceViewer in order to get at its
AnnotationModel and then look for AnnotationMarkers indicating classes and
functions then searching around them for said comments and adding if
necessary. Unfortunately I can't seem to get at the SourceViewer or
AnnotationModel. Here is what I tried:
TextEditor activeEd =
(TextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().getActiveEditor();
TextFileDocumentProvider tfdp =
(TextFileDocumentProvider)activeEd.getDocumentProvider();
Document doc = (Document)tfdp.getDocument(Object obj);
AnnotationModel am = (AnnotationModel)tfdp.getAnnotationModel(Object obj);
The problem I have is I don't know what Object it wants and the
documentation is not helpful in this area.
Any help is appreciated, and if there's an easier way, again, I'd love to
hear it.
Thanks!
Kevin
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330267 is a reply to message #330266] |
Wed, 23 July 2008 20:36   |
Eclipse User |
|
|
|
> TextEditor activeEd =
> (TextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().getActiveEditor();
>
> TextFileDocumentProvider tfdp =
> (TextFileDocumentProvider)activeEd.getDocumentProvider();
> Document doc = (Document)tfdp.getDocument(Object obj);
> AnnotationModel am = (AnnotationModel)tfdp.getAnnotationModel(Object obj);
>
> The problem I have is I don't know what Object it wants and the
> documentation is not helpful in this area.
>
Once you have the TextEditor just call getSourceViewer() to get
ISourceViewer, since the method is from AbstractTextEditor, which is
extended by TextEditor. From there just get the AnnotationModel.
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330268 is a reply to message #330267] |
Wed, 23 July 2008 20:39   |
Eclipse User |
|
|
|
AL wrote:
>
>> TextEditor activeEd =
>> (TextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().getActiveEditor();
>>
>> TextFileDocumentProvider tfdp =
>> (TextFileDocumentProvider)activeEd.getDocumentProvider();
>> Document doc = (Document)tfdp.getDocument(Object obj);
>> AnnotationModel am = (AnnotationModel)tfdp.getAnnotationModel(Object
>> obj);
>>
>> The problem I have is I don't know what Object it wants and the
>> documentation is not helpful in this area.
>>
>
> Once you have the TextEditor just call getSourceViewer() to get
> ISourceViewer, since the method is from AbstractTextEditor, which is
> extended by TextEditor. From there just get the AnnotationModel.
Ah...Crab...getSourceViewer() is protected :-) So, one way is to have
your editor implement a getSourceViewer() that calls
super.getSourceViewer().
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330284 is a reply to message #330268] |
Thu, 24 July 2008 13:29   |
Eclipse User |
|
|
|
Originally posted by: kevin.oberg.baesystems.com
AL wrote:
> AL wrote:
>>
>>> TextEditor activeEd =
>>>
(TextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().getActiveEditor();
>>>
>>> TextFileDocumentProvider tfdp =
>>> (TextFileDocumentProvider)activeEd.getDocumentProvider();
>>> Document doc = (Document)tfdp.getDocument(Object obj);
>>> AnnotationModel am = (AnnotationModel)tfdp.getAnnotationModel(Object
>>> obj);
>>>
>>> The problem I have is I don't know what Object it wants and the
>>> documentation is not helpful in this area.
>>>
>>
>> Once you have the TextEditor just call getSourceViewer() to get
>> ISourceViewer, since the method is from AbstractTextEditor, which is
>> extended by TextEditor. From there just get the AnnotationModel.
> Ah...Crab...getSourceViewer() is protected :-) So, one way is to have
> your editor implement a getSourceViewer() that calls
> super.getSourceViewer().
So, you are suggesting that I create a new class that extends TextEditor
and implements getSourceViewer, or is there some way I can implement that
without actually creating a whole new class?
I am not formally a Java programmer, so I don't know all the ins and outs,
but it seems fairly inefficient to extend an entire class simply to
implement a method in order to make a currently protected method public.
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330287 is a reply to message #330284] |
Thu, 24 July 2008 13:58   |
Eclipse User |
|
|
|
Originally posted by: subs._nospam_consertum.com
Kevin Oberg wrote:
> AL wrote:
>
>> AL wrote:
>>>
>>>> TextEditor activeEd =
> (TextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().getActiveEditor();
>
>>>>
>>>> TextFileDocumentProvider tfdp =
>>>> (TextFileDocumentProvider)activeEd.getDocumentProvider();
>>>> Document doc = (Document)tfdp.getDocument(Object obj);
>>>> AnnotationModel am = (AnnotationModel)tfdp.getAnnotationModel(Object
>>>> obj);
>>>>
>>>> The problem I have is I don't know what Object it wants and the
>>>> documentation is not helpful in this area.
>>>>
>>>
>>> Once you have the TextEditor just call getSourceViewer() to get
>>> ISourceViewer, since the method is from AbstractTextEditor, which is
>>> extended by TextEditor. From there just get the AnnotationModel.
>
>> Ah...Crab...getSourceViewer() is protected :-) So, one way is to have
>> your editor implement a getSourceViewer() that calls
>> super.getSourceViewer().
> So, you are suggesting that I create a new class that extends TextEditor
> and implements getSourceViewer, or is there some way I can implement
> that without actually creating a whole new class?
>
> I am not formally a Java programmer, so I don't know all the ins and
> outs, but it seems fairly inefficient to extend an entire class simply
> to implement a method in order to make a currently protected method public.
>
Actually, subclassing is very efficient.
--
Derek
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330301 is a reply to message #330284] |
Thu, 24 July 2008 18:32   |
Eclipse User |
|
|
|
Kevin Oberg wrote:
> AL wrote:
>
>> AL wrote:
>>>
>>>> TextEditor activeEd =
> (TextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().getActiveEditor();
>
>>>>
>>>> TextFileDocumentProvider tfdp =
>>>> (TextFileDocumentProvider)activeEd.getDocumentProvider();
>>>> Document doc = (Document)tfdp.getDocument(Object obj);
>>>> AnnotationModel am = (AnnotationModel)tfdp.getAnnotationModel(Object
>>>> obj);
>>>>
>>>> The problem I have is I don't know what Object it wants and the
>>>> documentation is not helpful in this area.
>>>>
>>>
>>> Once you have the TextEditor just call getSourceViewer() to get
>>> ISourceViewer, since the method is from AbstractTextEditor, which is
>>> extended by TextEditor. From there just get the AnnotationModel.
>
>> Ah...Crab...getSourceViewer() is protected :-) So, one way is to have
>> your editor implement a getSourceViewer() that calls
>> super.getSourceViewer().
> So, you are suggesting that I create a new class that extends TextEditor
> and implements getSourceViewer, or is there some way I can implement
> that without actually creating a whole new class?
>
> I am not formally a Java programmer, so I don't know all the ins and
> outs, but it seems fairly inefficient to extend an entire class simply
> to implement a method in order to make a currently protected method public.
>
Yep...If you are looking for the source viewer from an editor that you
implement. Then:
(a) Have your editor extends TextEditor and implement the
getSourceViewer() to call super.getSourceViewer() and return the
ISourceViewer. Yes, sub-classing/extending the TextEditor is extremely
efficient, because you get *all* the benefits that TextEditor gives, not
to mention it's an OO concept :-)
(b) Define a marker interface something IMyEditor, and have your editor
implement it. This way, once you get the active editor like above you
can check if the active editor is instance of IMyEditor. If so, you
know it's your editor. You don't really have to do this step, but I
recommend always to work with interfaces. You just check if it's an
instance of MyEditor, assuming 'MyEditor' is the your editor class that
extends TextEditor, as mentioned in part (a).
If you are looking for the source viewer of a 3rd-party editor, an
editor that is not written by you, oh well...:-)
|
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330678 is a reply to message #330266] |
Fri, 08 August 2008 10:40   |
Eclipse User |
|
|
|
Kevin Oberg wrote:
> Hey,
>
> I want to take the active editor and search through it and verify that
> each class has a certain set of comments of the form:
>
> /*!
> \brief <brief overview of the class>
> \usage <normal case usage examples>
> \extending <any kind words on deriving from the class>
> */
>
> And each function has a set of comments of the form:
>
> /*!
> \brief <brief overview of the function> \pre <description of any
> pre-conditions>
> \post <description of any post-conditions>
> \param <parameter name> <parameter description (one line per)>
> \return <return value description>
> \exception <exception type> <why it could be thrown (one line per)>
> */
>
> If there is an easy way to do this, I'm all ears. However, I am
> trying to get the active editor and get at its SourceViewer in order
> to get at its AnnotationModel and then look for AnnotationMarkers
> indicating classes and functions then searching around them for said
> comments and adding if necessary. Unfortunately I can't seem to get
> at the SourceViewer or AnnotationModel. Here is what I tried:
>
> TextEditor activeEd =
> (TextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWind ow().getActivePage().getActiveEditor();
>
> TextFileDocumentProvider tfdp =
> (TextFileDocumentProvider)activeEd.getDocumentProvider();
> Document doc = (Document)tfdp.getDocument(Object obj);
> AnnotationModel am = (AnnotationModel)tfdp.getAnnotationModel(Object
> obj);
Well looks like you have the mode, don't you? Why do you need the viewer?
Dani
>
> The problem I have is I don't know what Object it wants and the
> documentation is not helpful in this area.
>
> Any help is appreciated, and if there's an easier way, again, I'd love
> to hear it.
>
> Thanks!
> Kevin
>
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330688 is a reply to message #330678] |
Fri, 08 August 2008 13:07   |
Eclipse User |
|
|
|
Originally posted by: kevin.oberg.baesystems.com
"I have the active editor IEditorPart, its input IFileEditorInput, and its
file IFile. I am trying to write a plug-in that will check the file open
in the active editor for proper Doxygen commenting above each function and
class, and add it if it is not present.
Is there any part of the file that will identify to me where (via line
number or position from start of file) the classes or functions are
declared or defined for .cpp and .h files?"
That is from my old post, so you can see what I'm getting at. I think I
need to get at the file's DOM which is what usually talks to the CDT
plugin to get syntax highlighting to work, but I really don't know where
to start.
|
|
|
Re: How to access an editor's SourceViewer and AnnotationModel [message #330691 is a reply to message #330688] |
Fri, 08 August 2008 13:45  |
Eclipse User |
|
|
|
Kevin Oberg wrote:
> "I have the active editor IEditorPart, its input IFileEditorInput, and
> its file IFile. I am trying to write a plug-in that will check the
> file open in the active editor for proper Doxygen commenting above
> each function and class, and add it if it is not present.
>
>
> Is there any part of the file that will identify to me where (via line
> number or position from start of file) the classes or functions are
> declared or defined for .cpp and .h files?"
>
> That is from my old post, so you can see what I'm getting at. I think
> I need to get at the file's DOM which is what usually talks to the CDT
> plugin to get syntax highlighting to work, but I really don't know
> where to start.
Asking on eclipse.tools.cdt might help.
Dani
|
|
|
Powered by
FUDForum. Page generated in 0.02926 seconds