Provide java type code completion in a non-java editor ? [message #186316] |
Fri, 19 November 2004 06:35  |
Eclipse User |
|
|
|
Hi!
Is there in eclipse 3.1 API methods/classes to utilize the same
completionproposals which are generated in a Java Editor and Java Snippe=
t =
Editor
without such an editor ?
I would like to provide completions on all type and package names =
available to
a IJavaProject inside my own editor - any hints ?
I've been lurking around in the jdt code, but it look like all completio=
ns
are dependent on a Java Editor and/or IEvaluationContext - is this true =
?
If yes, any hints on providing a bare-bones IEvaluationContext which jus=
t
makes the codecompletion provide we with types and packages...
Thank you ;)
/max
|
|
|
Re: Provide java type code completion in a non-java editor ? [message #186338 is a reply to message #186316] |
Fri, 19 November 2004 07:52  |
Eclipse User |
|
|
|
On Fri, 19 Nov 2004 12:35:47 +0100, Max Rydahl Andersen =
<max.andersen@jboss.com> wrote:
After writing this I actually succeded in making something work ;)
Now it would just be nice to know if this actually is the best way of =
doing ths ?
(it actually works very nice :)
IJavaProject javaProject =3D getJavaProject(); // any kind of javaproj=
ect =
will do ;)
String packageName =3D null; // set it to something if you want it to =
=
complete as being inside a package
String start =3D ""; // intial string to complete on (could eg. be "Co=
l" =
to complete on Collection)
IEvaluationContext context =3D javaProject.newEvaluationContext();
ResultCollector rc =3D new ResultCollector(); // extend this to contro=
l =
what is provide as completions (e.g. to filter out everything but classe=
s =
or packages)
context.setPackageName(packageName);
rc.reset(offset, javaProject, null);
=
try {
// cannot send in my own document as it won't compile as java - so we=
=
just send in
// the smallest snippet possible
context.codeComplete(start, start.length(), rc);
} catch(JavaModelException jme) {
// TODO: handle/report!
jme.printStackTrace();
}
JavaCompletionProposal[] results =3D rc.getResults();
// As all completions have made with the assumption on a empty (or =
almost empty) string
// we move the replacementoffset on every proposol to fit nicely into =
=
our non-java code
for (int i =3D 0; i < results.length; i++) {
JavaCompletionProposal proposal =3D results[i];
proposal.setReplacementOffset(offset-start.length());
}
Arrays.sort(results, JavaCompletionProposalComparator.getInstance());
proposals.addAll(Arrays.asList(results));
Is that's how it's supposed to be done ?
TIA
/max
> Hi!
>
> Is there in eclipse 3.1 API methods/classes to utilize the same
> completionproposals which are generated in a Java Editor and Java =
> Snippet Editor
> without such an editor ?
>
> I would like to provide completions on all type and package names =
> available to
> a IJavaProject inside my own editor - any hints ?
>
> I've been lurking around in the jdt code, but it look like all =
> completions
> are dependent on a Java Editor and/or IEvaluationContext - is this tru=
e ?
>
> If yes, any hints on providing a bare-bones IEvaluationContext which j=
ust
> makes the codecompletion provide we with types and packages...
>
> Thank you ;)
>
> /max
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.02856 seconds