Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » JavaSourceViewer and autocompletion
JavaSourceViewer and autocompletion [message #258515] Fri, 06 February 2009 03:07 Go to next message
Eclipse UserFriend
Hi everybody
for a personal project i want to create a view with a javasourceviewer.

I already succesed to create it and have syntax coloration. But i wanted
to know more information about it.

- autocompletion, how is it possible to set a context to my source
viewer and providing content assist ?

- is it possible to create in memory a "virtual" compilation unit (or
java project) and setting this virtual object to my source viewer to
provide content assist based on this ?

thank you in advance
Regards
Re: JavaSourceViewer and autocompletion [message #258540 is a reply to message #258515] Fri, 06 February 2009 16:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alamothe.ptt.yu

Tristan FAURE wrote:
> Hi everybody
> for a personal project i want to create a view with a
> javasourceviewer.
> I already succesed to create it and have syntax coloration. But i
> wanted to know more information about it.
>
> - autocompletion, how is it possible to set a context to my source
> viewer and providing content assist ?

If you're using source viewer in a dialog, take a look at
org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog on how to enable
content assist. It is a dialog used to edit detail formatters (windows /
preferences / java / debg / detail formatters)

> - is it possible to create in memory a "virtual" compilation unit (or
> java project) and setting this virtual object to my source viewer to
> provide content assist based on this ?

You can get a working copy of an existing ICompilationUnit, using
getWorkingCopy, while providing your own owner. Then, you can alter the
working copy's source, and use ICompilationUnit.codeComplete to get
proposals. I think you can make a whole virtual java project on top of an
existing one this way.

> thank you in advance
> Regards
Re: JavaSourceViewer and autocompletion [message #258550 is a reply to message #258540] Mon, 09 February 2009 09:29 Go to previous messageGo to next message
Eclipse UserFriend
Hi thank you for your answer

i have some comments/questions bellow

Nikola Mihajlovic a écrit :
> Tristan FAURE wrote:
>> Hi everybody
>> for a personal project i want to create a view with a
>> javasourceviewer.
>> I already succesed to create it and have syntax coloration. But i
>> wanted to know more information about it.
>>
>> - autocompletion, how is it possible to set a context to my source
>> viewer and providing content assist ?
>
> If you're using source viewer in a dialog, take a look at
> org.eclipse.jdt.internal.debug.ui.DetailFormatterDialog on how to enable
> content assist. It is a dialog used to edit detail formatters (windows /
> preferences / java / debg / detail formatters)

Thank you very much it works !

>
>> - is it possible to create in memory a "virtual" compilation unit (or
>> java project) and setting this virtual object to my source viewer to
>> provide content assist based on this ?
>
> You can get a working copy of an existing ICompilationUnit, using
> getWorkingCopy, while providing your own owner. Then, you can alter the
> working copy's source, and use ICompilationUnit.codeComplete to get
> proposals. I think you can make a whole virtual java project on top of an
> existing one this way.
>

I try this. and for my work i start from scratch (just a java project)
and i wanted to create virtual sources and i don't success to do this :(
i don't really know if it's possible ?

getWorkingCopy is only accessible from ICompilationUnit and not on
javaProject

>> thank you in advance
>> Regards
>
>
Re: JavaSourceViewer and autocompletion [message #258604 is a reply to message #258550] Tue, 10 February 2009 18:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alamothe.ptt.yu

Tristan FAURE wrote:
>> You can get a working copy of an existing ICompilationUnit, using
>> getWorkingCopy, while providing your own owner. Then, you can alter
>> the working copy's source, and use ICompilationUnit.codeComplete to
>> get proposals. I think you can make a whole virtual java project on
>> top of an existing one this way.
>>
>
> I try this. and for my work i start from scratch (just a java project)
> and i wanted to create virtual sources and i don't success to do this
> :( i don't really know if it's possible ?
>
> getWorkingCopy is only accessible from ICompilationUnit and not on
> javaProject

I'm not completely familiar with this, but if you can navigate from
IJavaProject to IPackageFragment you can call getCompilationUnit(String
name) which will return you an ICompilationUnit. This is a handle-only
method, it won't create anything on disk (the same is probably also true for
obtaining IPackageFragment).

Then you should be able to get a working copy (in-memory copy, this will
create an in-memory buffer) the way I described and set its contents. All
working copies with the same owner are related to each other (I think!)
Re: JavaSourceViewer and autocompletion [message #258616 is a reply to message #258604] Wed, 11 February 2009 03:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi thank you to try to help me
i already called getCompilationUnit but if the java project is empty it
returns null :(

but searchnig on internet it seems somebody already had the same idea as
me and it appears there is no solution except generating code :(
http://dev.eclipse.org/newslists/news.eclipse.tools.cdt/msg0 0048.html

Nikola Mihajlovic a écrit :
> Tristan FAURE wrote:
>>> You can get a working copy of an existing ICompilationUnit, using
>>> getWorkingCopy, while providing your own owner. Then, you can alter
>>> the working copy's source, and use ICompilationUnit.codeComplete to
>>> get proposals. I think you can make a whole virtual java project on
>>> top of an existing one this way.
>>>
>> I try this. and for my work i start from scratch (just a java project)
>> and i wanted to create virtual sources and i don't success to do this
>> :( i don't really know if it's possible ?
>>
>> getWorkingCopy is only accessible from ICompilationUnit and not on
>> javaProject
>
> I'm not completely familiar with this, but if you can navigate from
> IJavaProject to IPackageFragment you can call getCompilationUnit(String
> name) which will return you an ICompilationUnit. This is a handle-only
> method, it won't create anything on disk (the same is probably also true for
> obtaining IPackageFragment).
>
> Then you should be able to get a working copy (in-memory copy, this will
> create an in-memory buffer) the way I described and set its contents. All
> working copies with the same owner are related to each other (I think!)
>
>
Re: JavaSourceViewer and autocompletion [message #514492 is a reply to message #258616] Mon, 15 February 2010 10:22 Go to previous message
Eclipse UserFriend
I'm also trying to work with a JavaSourceViewer within a dialog, specifically for JavaScript editing. I too need content assist to work. I've tried looking at EditTemplateDialog and DetailFormatterDialog with no success. I have a dialog up with an embedded JavaSourceViewer, but only have syntax highlighting.

I do not have a JavaProject within my SourceViewer, or at least do not know how to get one.

How does one get access to a JavaProject or the inner CompilationUnit in a JavaSourceViewer?

How does one properly setup for content assist using a JavaSourceViewer?

Thanks in advance
Previous Topic:confused about ant-builders...
Next Topic:Problem launching java apps
Goto Forum:
  


Current Time: Tue Mar 25 02:16:16 EDT 2025

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

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

Back to the top