Skip navigation links
org.netbeans.modules.editor.completion/1 1.45.0 2

Editor Code Completion
Official

See: Description

Editor Code Completion 
Package Description
org.netbeans.api.editor.completion  
org.netbeans.spi.editor.completion  
org.netbeans.spi.editor.completion.support  

The Code Completion module is located under /cvs/editor/completion directory. It provides the CodeCompletionAPI with a simple API for showing and hiding of the completion located in org.netbeans.api.editor.completion and with SPI defining the completion providers that is located in org.netbeans.spi.editor.completion, and the implementation located in org.netbeans.modules.editor.completion.

What is New (see all changes)?

Use Cases

API

Show or hide completion window

The API is small and it only allows to explicitly show or hide the completion window.
It's being used by code templates that need to explicitly show the code completion window when tabbing to a particular parameter.
There may be certain actions that want to ensure that the code completion is hidden at the time when they are invoked. For example the actions pasting the content of the completion item into the document.

SPI

Provide completion content by independent providers

Completion infrastructure needs to obtain the results that are then displayed in the completion window.
There are three types of displayed results related to the current caret offset:

  • Code completion items
  • Documentation (e.g. the javadoc documentation)
  • Tooltip (e.g. for method parameters)

For the purpose of obtaining these completion results CompletionProvider exists.
There may be an arbitrary number of independent completion providers for a single completion popup window.
The completion providers are registered through the xml layer into Editors/<mime-type>/CompletionProviders. Once the document with the particular mime-type gets loaded the corresponding completion providers will get instantiated and used.

Threading:
The code completion's infrastructure invokes the requests for the completion results in the AWT thread.
Therefore all the methods of the completion providers are invoked in AWT thread but they may reschedule their processing into other threads.

Provide completion results computed asynchronously

The completion provider creates a task that computes the resulting data that will then be displayed by the code completion infrastructure.
The task creation and computation are called synchronously from the AWT event dispatch thread.
However there can be potentially long-running tasks (e.g. working with MDR) that are not desirable to be run in AWT thread.
Therefore the completion infrastructure provides a listener to which the completion task notifies the results.
The support class AsyncCompletionTask allows to post the task computation into RequestProcessor.

Provide list of completion items fulfilling various requirements

The completion task computes a collection of completion items which are then collected by the completion infrastructure and displayed.
Displaying. Each completion item must be able to display itself in a JList.
Sorting. The completion items may come from different completion providers and they must be sorted before displaying. The sort order should not only be alphabetical but it should also allow a prioritization of the items according to their importance in the given context.
Actions. The interaction of the user with the completion item is done by interacting with item's input map and action map.
Documentation. The item may want to display additional detailed information in a documentation popup window.

Exported Interfaces

This table lists all of the module exported APIs with defined stability classifications. It is generated based on answers to questions about the architecture of the module. Read them all...
Group of java interfaces
Interface NameIn/OutStabilitySpecified in What Document?
CodeCompletionAPIExportedOfficialindex.html

Group of logger interfaces
Interface NameIn/OutStabilitySpecified in What Document?
org.netbeans.ui.editor.completionExportedUnder Development

Since version 1.8 the completion cooperates with UI Gestures Collector by sending following messages to the org.netbeans.ui.editor.completion
logger:
  • COMPL_INVOCATION - message about a code completion being invoked. Arguments:
    • {0}: true - if explicit, false if implicit invocation happened
  • COMPL_KEY_SELECT - send when user selects an item from completion using keyboard character. Arguments:
    • {0}: character that invoked the action
    • {1}: the index of selected item
    • {2}: the classname of the selected item
  • COMPL_KEY_SELECT_DEFAULT - send when user selects an item from completion using enter. Arguments:
    • {0}: '\n'
    • {1}: the index of selected item
    • {2}: the classname of the selected item
  • COMPL_MOUSE_SELECT - send when user selects an item from completion using mouse. Arguments:
    • {0}: null
    • {1}: the index of selected item
    • {2}: the classname of the selected item
  • COMPL_CANCEL - send when user selects cancels completion without any selection. No arguments.

Group of systemproperty interfaces
Interface NameIn/OutStabilitySpecified in What Document?
org.netbeans.modules.editor.completion.slowness.reportExportedPrivate ...//wiki.netbeans.org/FitnessViaPostMortem

You can suppress automatic reporting of slow code completion computation by increasing value of -J-Dorg.netbeans.modules.editor.completion.slowness.report property to more than 2000 ms (the default value).

Implementation Details

Where are the sources for the module?

The sources for the module are in the NetBeans Mercurial repositories.

What do other modules need to do to declare a dependency on this one, in addition to or instead of a plain module dependency?
Nothing.

Read more about the implementation in the answers to architecture questions.

Skip navigation links
org.netbeans.modules.editor.completion/1 1.45.0 2

Built on March 28 2017.  |  Portions Copyright 1997-2017 Oracle. All rights reserved.