Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Request for "more open code completion"?
Request for "more open code completion"? [message #647796] Sun, 09 January 2011 10:45 Go to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 49
Registered: July 2009
Member
Hi JDT-Team,

I'm currently rewriting the code for the code recommenders intelligent
code completion engine. My initial goal was to provide a clean API that
would allow for various completion engines making proposals like the
recommended method call recommendations, code snippets etc.
Unfortunately, my efforts ended in a not-that-nice API which partially
reimplements stuff that's already there but is not accessible from
outside the JDT.

I wonder whether you could imagine to open code completion API a bit to
allow for arbitrary completion engines? For instance by extending the
JavaContentAssistInvocationContext with more context information such as
the local variable name and type code completion was triggered on, kind
of completion request etc.

Are there any resources left to open the code completion API - or at
least changing some field visibilities :-)?

Thanks,
Marcel
Re: Request for "more open code completion"? [message #647869 is a reply to message #647796] Mon, 10 January 2011 08:35 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3801
Registered: July 2009
Senior Member
On 09.01.2011 11:45, Marcel Bruch wrote:
> Hi JDT-Team,
>
> I'm currently rewriting the code for the code recommenders intelligent
> code completion engine. My initial goal was to provide a clean API
> that would allow for various completion engines making proposals like
> the recommended method call recommendations, code snippets etc.
> Unfortunately, my efforts ended in a not-that-nice API which partially
> reimplements stuff that's already there but is not accessible from
> outside the JDT.
>
> I wonder whether you could imagine to open code completion API a bit
> to allow for arbitrary completion engines? For instance by extending
> the JavaContentAssistInvocationContext with more context information
Did you look at the core context? Also, did you look at the
'org.eclipse.jdt.ui.javaCompletionProposalComputer' extension point?

Dani
> such as the local variable name and type code completion was triggered
> on, kind of completion request etc.
>
> Are there any resources left to open the code completion API - or at
> least changing some field visibilities :-)?
>
> Thanks,
> Marcel
>
Re: Request for "more open code completion"? [message #648039 is a reply to message #647869] Mon, 10 January 2011 22:26 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 49
Registered: July 2009
Member
On 10.01.11 09:35, Daniel Megert wrote:

> Did you look at the core context? Also, did you look at the
> 'org.eclipse.jdt.ui.javaCompletionProposalComputer' extension point?

Sure. I'm interested in getting access to JDTs codeassist nodes in
org.eclipse.jdt.internal.codeassist.complete since they contain much of
the information I need.


Actually parts of my code look like this:

private CompletionEngine engine = ...;
private CompletionParser parser = ...;

....

token = getTokenFromJdtContext();
final ASTNode assistNode = parser.assistNode;
if (assistNode == null) {
// assistNode has been deleted somewhere in JDT code
handleCompletionRequestWithoutAssistNode();
} else if (assistNode instanceof CompletionOnQualifiedNameReference) {
// hooray ...
handleCompletionOnQualifiedNameReference(..)
....

but some fields are erased or not accessible which forces me to
reconstruct the information form AST manually.

Thanks,
Marcel
Re: Request for "more open code completion"? [message #650429 is a reply to message #647869] Mon, 24 January 2011 19:57 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 49
Registered: July 2009
Member
Hi Dani,

On 10.01.11 09:35, Daniel Megert wrote:
> Did you look at the core context? Also, did you look at the
> 'org.eclipse.jdt.ui.javaCompletionProposalComputer' extension point?

I looked at both and I already use both. But we need more information
than their public api provides. Please have a look on this screencast to
see which information we use and need: http://goo.gl/88Fmu

The existing JDT API has some visibility restrictions when it comes to
details. For instance we need to know the variable name and type code
completion was triggered on etc. - which cannot be accessed from the
completion (core) context

This information, however, is internally available and we would like to
reuse this knowledge for performance reasons. Right now, we create our
own completion engine to get the JDT proposals and context information
(see code below). This takes from 8ms to 800ms depending on when/where
code completion was triggered.

My general question is:

Is it possible to hook into existing code to get more context
information? The information we would like to have can be found in
org.eclipse.jdt.internal.codeassist.InternalExtendedCompleti onContext
and surrounding package.


More detailed:

Is there any way to (a) reuse previous code completion results so that
we only need to compute proposals once, and/or (b) get access to types
and structures stored in org.eclipse.jdt.internal.codeassist.*?


Having access would allow eclipse.org/recommenders to improve
performance of its code completion drastically.


Runtime weaving would be a temporary solution.

Thanks,
Marcel





Code we use to obtain at least a completionParser:

final org.eclipse.jdt.internal.compiler.env.ICompilationUnit compilerCu
= cu.isWorkingCopy() ?
(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) cu
.getOriginalElement() : cu;
engine.complete(compilerCu, jdtCtx.getInvocationOffset(), 0,
cu.getPrimary());
parser = (CompletionParser) engine.getParser();

// analyze whats available in parser assistNode (which is not too much)
Re: Request for "more open code completion"? [message #650658 is a reply to message #650429] Tue, 25 January 2011 20:54 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 49
Registered: July 2009
Member
Solved. thanks.
Re: Request for "more open code completion"? [message #650790 is a reply to message #650658] Wed, 26 January 2011 15:15 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2943
Registered: July 2009
Senior Member
Marcel,
can you elaborate in a few words what you did to solve your problem?

Thanks,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 25.01.11 21:54, schrieb Marcel Bruch:
> Solved. thanks.
Re: Request for "more open code completion"? [message #651127 is a reply to message #650790] Thu, 27 January 2011 21:30 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 49
Registered: July 2009
Member
sure.

Goal:
Get access to org.eclipse.jdt.internal.codeassist.complete.CompletionOn*
Statements for own code completion.

My hack to achieve this is as follows:

1. Create your own org.eclipse.jdt.internal.codeassist.CompletionEngine
2. Call completionEngine.complete(..);
3. Get the (CompletionParser) completionEngine.getParser()
4. Traver the completionParser.compilationUnit or referenceContext with
your own version of org.eclipse.jdt.internal.compiler.ASTVisitor;
5. Override relevant methods for your code completion task to cast the
CompletionOn* ASTNodes.

Example: to get the information that code completion was triggered on a
method argument you can do the following:

@Override
public boolean visit(final MessageSend messageSend, final BlockScope
scope) {
if (messageSend instanceof CompletionOnMessageSend) {
// here is the requested info:
final CompletionOnMessageSend node = store(messageSend);
// collect info about enclosingMethod and enclosingType
evaluateBlockScope(scope);
// extract info like reveiver type and receiver name:
evaluateCompletionOnMessageSend(node);
// terminate traversal when done:
return false;
}
// in jdt core classes you can find a "CompletionNodeFound" exception
// which you may throw for convenience code. No idea whether this is
// actually costly or not.
return !isCompletionNodeFound();
}

Note that the AST you get from the completion parser is a "diet"
version. It only contains nodes relevant for code completion, i.e.,
declared local variables, fields, and methods but (almost) no other
statements.

I guess the source code will make it little bit easier to grasp. I can
send you the two classes per mail or post the link to source repository
in a few days after we moved code completion to Eclipse.

One note on performance:
Parsing the code of tiny classes takes ~10ms. Haven't tested with large
classes yet.

Cheers,
Marcel




On 26.01.11 16:15, Sebastian Zarnekow wrote:
> Marcel,
> can you elaborate in a few words what you did to solve your problem?
>
> Thanks,
> Sebastian
Re: Request for "more open code completion"? [message #651884 is a reply to message #651127] Tue, 01 February 2011 21:18 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 49
Registered: July 2009
Member
Hi Sebastian,

here the links to the sources mentioned:

IntelligentCompletionContext.java http://goo.gl/cnJyW

This class initializes the completion engine and triggers the AST traversal.



CompilerAstCompletionNodeFinder.java http://goo.gl/kBsbD

Traverses the compiler AST to find the CompletionOn* Node.

HTH,
Marcel
Re: Request for "more open code completion"? [message #651944 is a reply to message #651884] Wed, 02 February 2011 07:59 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 2943
Registered: July 2009
Senior Member
Hi Marcel,

thanks for coming back to this one. I'll check whether I can exploit
your findings somehow.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 01.02.11 22:18, schrieb Marcel Bruch:
> Hi Sebastian,
>
> here the links to the sources mentioned:
>
> IntelligentCompletionContext.java http://goo.gl/cnJyW
>
> This class initializes the completion engine and triggers the AST
> traversal.
>
>
>
> CompilerAstCompletionNodeFinder.java http://goo.gl/kBsbD
>
> Traverses the compiler AST to find the CompletionOn* Node.
>
> HTH,
> Marcel
Previous Topic:Decorators on classpath containers
Next Topic:How to define print page layout (margins font,...) ?
Goto Forum:
  


Current Time: Sat Nov 29 04:01:09 GMT 2014

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

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