Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.netbeans.modules.editor.completion/1 1.6.22
PREV NEXT | FRAMES NO FRAMES

# NetBeans Editor Code Completion SPI

See:
Description

Editor Code Completion SPI
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)?

- Nov 8 '05 Addition of CompletionResultSet.setWaitText()

  `void CompletionResultSet.setWaitText(String waitText)` was added to allow customization of the text in the label displayed if the completion query results are not computed in certain timeout.

- Nov 8 '05 Adddition of CompletionItem.getInsertPrefix()

  `CharSequence CompletionItem.getInsertPrefix()` was added.

- Nov 8 '05 Semantic change of CompletionTask.refresh()

  CompletionTask.refresh(CompletionResultSet resultSet) now allows `null` parameter.
  `void AsyncCompletionQuery.preQueryUpdate(JTextComponent component)` was added to reflect that in AsyncCompletionTask.

- Jul 27 '05 Editor Code Completion API created

  Editor Code Completion API was created.

### 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 Name | In/Out | Stability | Specified in What Document?
CodeCompletionAPI | Exported | Official | index.html

### Implementation Details

##### What do other modules need to do to declare a dependency on this one?

OpenIDE-Module-Module-Dependecies: org.netbeans.modules.editor.completion/1 > 1.6.22

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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| org.netbeans.modules.editor.completion/1 1.6.22
PREV NEXT | FRAMES NO FRAMES

Built on December 7 2006. | Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.