Code Completion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Code Completion

melG
Hello,
I want to perform some action when a code completed.

For instance, when "toString" method completed, I will perform my action.

I've found that in "CompletionItem" class has a "defaultAction(JTextComponent component)" method which is invoked, after pressing VK_ENTER or double-clicking on that item.

http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-completion/org/netbeans/spi/editor/completion/CompletionItem.html

Simply, I tried to print something to output as follows:


Code:

public class SomeCompletionItem implements CompletionItem {
   ...
   @Override
   public void defaultAction(JTextComponent component) {
      System.out.println("Code Completed.");
   }
   ...
}



But I did not anything printed. Is there something I'm missing or is there any way that I can do that?




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Code Completion

Emilian Bold-2
A CompletionItem is literally a line in the completion popup. Did you inject your completion item in the completion via some CompletionProvider?

I guess you want a listener actually, but I'm not certain we have an official API for that.



--emi

On Tue, Mar 28, 2017 at 11:47 PM, melG <[hidden email]> wrote:
Hello,
I want to perform some action when a code completed.

For instance, when "toString" method completed, I will perform my action.

I've found that in "CompletionItem" class has a "defaultAction(JTextComponent component)" method which is invoked, after pressing VK_ENTER or double-clicking on that item.

http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-completion/org/netbeans/spi/editor/completion/CompletionItem.html

Simply, I tried to print something to output as follows:


Code:

public class SomeCompletionItem implements CompletionItem {
   ...
   @Override
   public void defaultAction(JTextComponent component) {
      System.out.println("Code Completed.");
   }
   ...
}



But I did not anything printed. Is there something I'm missing or is there any way that I can do that?





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Code Completion

melG
In reply to this post by melG
Actually, I followed the steps of the link you gave me.
In the "Implementing the Action" part, the "defaultAction(...)" method indicates that the completion popup should be closed when the code is completed. This is exactly where my action should be done (after closing code suggestions list), but it seems like I still can not reach that method.




Loading...