Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Special Content Assist
Special Content Assist [message #252756] Thu, 17 April 2008 12:46 Go to next message
Eclipse UserFriend
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 #252786 is a reply to message #252756] Thu, 17 April 2008 23:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ferfox.gmail.com

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.
Re: Special Content Assist [message #252797 is a reply to message #252786] Fri, 18 April 2008 03:10 Go to previous messageGo to next message
Eclipse UserFriend
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.

Dani
>
>
>
Re: Special Content Assist [message #252817 is a reply to message #252797] Fri, 18 April 2008 20:49 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
>>>
>>>
>>>
>
>
Previous Topic:Caching of build path jars
Next Topic:How to share compiler settings across working set
Goto Forum:
  


Current Time: Sun May 11 04:29:35 EDT 2025

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

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

Back to the top