Special Content Assist [message #252756] |
Thu, 17 April 2008 12:46  |
Eclipse User |
|
|
|
Originally posted by: ferfox.gmail.com
Hello,
I would like to make an extension to
org.eclipse.jdt.ui.javaCompletionProposalSorters and
org.eclipse.jdt.ui.javaCompletionProposalComputer
My objective is to add an additional content assistant that will provide a
subset of default content assist (some elements will be removed and the
order of the elements may change).
I want to provide suggestions related to a method pattern, for instance,
if the method pattern ( say doSomething() )contains the sequence of method
calls:
doSomething(){
A;
B;
C;
D;
}
Then the user of the plugin will mark a checkbox that specify he/she is
writing the current method on the editor based on doSomething() pattern.
My goal is to provide: if the user types:
myMethod(){
A;
B;
<-- Now the optional content assist should suggest in order: C;
D;
}
What I found difficult is to get the ICompilationUnit of myMethod from its
beginning until B; offset It's easy to get the entire ICompilationUnit of
the .java file but the same thing from a specific SourceMethod until the
end of B; seens to be hard.
Any clues?
Thanks in advance!
|
|
|
|
|
Re: Special Content Assist [message #252817 is a reply to message #252797] |
Fri, 18 April 2008 20:49   |
Eclipse User |
|
|
|
Originally posted by: ferfox.gmail.com
Daniel Megert wrote:
> Fernando wrote:
>> Fernando wrote:
>>
>>> Hello,
>>
>>> I would like to make an extension to
>>> org.eclipse.jdt.ui.javaCompletionProposalSorters and
>>> org.eclipse.jdt.ui.javaCompletionProposalComputer
>>> My objective is to add an additional content assistant that will
>>> provide a subset of default content assist (some elements will be
>>> removed and the order of the elements may change).
>>
>>> I want to provide suggestions related to a method pattern, for
>>> instance, if the method pattern ( say doSomething() )contains the
>>> sequence of method calls:
>>
>>> doSomething(){
>>> A;
>>> B;
>>> C;
>>> D;
>>> }
>>
>>> Then the user of the plugin will mark a checkbox that specify he/she
>>> is writing the current method on the editor based on doSomething()
>>> pattern.
>>
>>> My goal is to provide: if the user types:
>>> myMethod(){
>>> A;
>>> B;
>>> <-- Now the optional content assist should suggest in order: C;
>>> D;
>>> }
>>> What I found difficult is to get the ICompilationUnit of myMethod
>>> from its beginning until B; offset It's easy to get the entire
>>> ICompilationUnit of the .java file but the same thing from a specific
>>> SourceMethod until the end of B; seens to be hard.
>>> Any clues?
>>
>>> Thanks in advance!
>> I finally found some clues related to my issue.
>>
>> Remember:
>>
>> doSomething(){
>> A;
>> B;
>> C;
>> D;
>> }
>>
>> Since I need a to know previous command calls sequence within a
>> method, and use this information to provide better content assist I
>> think I can do the following:
>>
>> I'll extend method AbstractProposalSorter and subscribe
>> public void beginSorting(ContentAssistInvocationContext context);
>>
>> 1) context.getInvocationOffset() <- this provides the current "cursor"
>> position in a ICompilationUnit
>>
>> 2) JavaContentAssistInvocationContext javaContext=
>> (JavaContentAssistInvocationContext) context;
>> IJavaElement jE =
>> javaContext.getElementAt(context.getInvocationOffset());
>>
>> <- this provides the SourceMethod in which the user has called content
>> assistant (in this case, doSomething)
>>
>> 3)
>>
>> ASTParser parser = ASTParser.newParser(AST.JLS3);
>> parser.setSource(iCu);
>> org.eclipse.jdt.core.dom.CompilationUnit result =
>> (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
>>
>> <- Now that I have this AST I can visit this Tree until I
>> find...doSomething.
>> Then, I can use ASTNode.getStartPosition() to each block of
>> doSomething until I find an index equal or higher than
>> context.getInvocationOffset().
>> I finally have at the previous blocks the commands before the
>> contentassist.
> Creating the AST might be expensive, especially when you need bindings.
> Doing this might be OK when inserting the proposal but not when
> computing the proposals. In 3.4 the CompletionContext gives you a bit
> more context. Also note, that a warning dialog will be presented to the
> user if your extension takes too long.
I wish I could wait until 3.4 :( but I cannot...
I had an idea, How about making my improved content assistant the last one
to appear, after Template Proposals. Do you think this can provide more
computing time since I have to create the AST.
Fortunately I think I won't need bindings :)
> Dani
>>
>>
>>
|
|
|
Re: Special Content Assist [message #252838 is a reply to message #252817] |
Sat, 19 April 2008 08:03  |
Eclipse User |
|
|
|
Fernando wrote:
> Daniel Megert wrote:
>
>> Fernando wrote:
>>> Fernando wrote:
>>>
>>>> Hello,
>>>
>>>> I would like to make an extension to
>>>> org.eclipse.jdt.ui.javaCompletionProposalSorters and
>>>> org.eclipse.jdt.ui.javaCompletionProposalComputer
>>>> My objective is to add an additional content assistant that will
>>>> provide a subset of default content assist (some elements will be
>>>> removed and the order of the elements may change).
>>>
>>>> I want to provide suggestions related to a method pattern, for
>>>> instance, if the method pattern ( say doSomething() )contains the
>>>> sequence of method calls:
>>>
>>>> doSomething(){
>>>> A;
>>>> B;
>>>> C;
>>>> D;
>>>> }
>>>
>>>> Then the user of the plugin will mark a checkbox that specify
>>>> he/she is writing the current method on the editor based on
>>>> doSomething() pattern.
>>>
>>>> My goal is to provide: if the user types:
>>>> myMethod(){
>>>> A;
>>>> B;
>>>> <-- Now the optional content assist should suggest in order: C;
>>>> D;
>>>> } What I found difficult is to get the ICompilationUnit of
>>>> myMethod from its beginning until B; offset It's easy to get the
>>>> entire ICompilationUnit of the .java file but the same thing from a
>>>> specific SourceMethod until the end of B; seens to be hard.
>>>> Any clues?
>>>
>>>> Thanks in advance!
>>> I finally found some clues related to my issue.
>>>
>>> Remember:
>>>
>>> doSomething(){
>>> A;
>>> B;
>>> C;
>>> D;
>>> }
>>>
>>> Since I need a to know previous command calls sequence within a
>>> method, and use this information to provide better content assist I
>>> think I can do the following:
>>>
>>> I'll extend method AbstractProposalSorter and subscribe public
>>> void beginSorting(ContentAssistInvocationContext context);
>>>
>>> 1) context.getInvocationOffset() <- this provides the current
>>> "cursor" position in a ICompilationUnit
>>>
>>> 2) JavaContentAssistInvocationContext javaContext=
>>> (JavaContentAssistInvocationContext) context;
>>> IJavaElement jE =
>>> javaContext.getElementAt(context.getInvocationOffset());
>>>
>>> <- this provides the SourceMethod in which the user has called
>>> content assistant (in this case, doSomething)
>>>
>>> 3)
>>>
>>> ASTParser parser = ASTParser.newParser(AST.JLS3);
>>> parser.setSource(iCu);
>>> org.eclipse.jdt.core.dom.CompilationUnit result =
>>> (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
>>>
>>> <- Now that I have this AST I can visit this Tree until I
>>> find...doSomething.
>>> Then, I can use ASTNode.getStartPosition() to each block of
>>> doSomething until I find an index equal or higher than
>>> context.getInvocationOffset().
>>> I finally have at the previous blocks the commands before the
>>> contentassist.
>> Creating the AST might be expensive, especially when you need
>> bindings. Doing this might be OK when inserting the proposal but not
>> when computing the proposals. In 3.4 the CompletionContext gives you
>> a bit more context. Also note, that a warning dialog will be
>> presented to the user if your extension takes too long.
>
> I wish I could wait until 3.4 :( but I cannot...
> I had an idea, How about making my improved content assistant the last
> one to appear, after Template Proposals. Do you think this can provide
> more computing time since I have to create the AST.
Nope.
Dani
> Fortunately I think I won't need bindings :)
>
>> Dani
>>>
>>>
>>>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03425 seconds