org.eclipse.wst.jsdt.ui.text.java

## Class JavaContentAssistInvocationContext

- java.lang.Object
- - org.eclipse.wst.jsdt.ui.text.java.ContentAssistInvocationContext
  - - org.eclipse.wst.jsdt.ui.text.java.JavaContentAssistInvocationContext

    public class JavaContentAssistInvocationContext
    extends ContentAssistInvocationContext

Describes the context of a content assist invocation in a JavaScript editor.

Clients may use but not subclass this class.

Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.

### Constructor Summary

Constructors
Constructor and Description
`JavaContentAssistInvocationContext(IJavaScriptUnit unit)` Creates a new context.
`JavaContentAssistInvocationContext(ITextViewer viewer, int offset, IEditorPart editor)` Creates a new context.

### Method Summary

All Methods Instance Methods Concrete Methods
`IJavaScriptUnit` `getCompilationUnit()` Returns the compilation unit that content assist is invoked in, `null` if there is none.
`CompletionContext` `getCoreContext()` Returns the `core completion context` if available, `null` otherwise.
`IEditorPart` `getEditor()` Returns the editor the context is associated with.
`IType` `getExpectedType()` Returns the expected type if any, `null` otherwise.
`float` `getHistoryRelevance(java.lang.String qualifiedTypeName)` Returns an float in [0.0, 1.0] based on whether the type has been recently used as a right hand side for the type expected in the current context. 0 signals that the `qualifiedTypeName` does not match the expected type, while 1.0 signals that `qualifiedTypeName` has most recently been used in a similar context.
`IJavaCompletionProposal[]` `getKeywordProposals()` Returns the keyword proposals that are available in this context, possibly none.
`CompletionProposalLabelProvider` `getLabelProvider()` Returns a label provider that can be used to compute proposal labels.
`IJavaScriptProject` `getProject()` Returns the project of the compilation unit that content assist is invoked in, `null` if none.
`IResource` `getResource()` Returns the underlined resource, `null` if none.
`protected void` `setCollector(CompletionProposalCollector collector)` Sets the collector, which is used to access the compilation unit, the core context and the label provider.

### Methods inherited from class org.eclipse.wst.jsdt.ui.text.java.ContentAssistInvocationContext

`computeIdentifierPrefix, equals, getDocument, getInvocationOffset, getViewer, hashCode`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### JavaContentAssistInvocationContext

    public JavaContentAssistInvocationContext(ITextViewer viewer,
                                              int offset,
                                              IEditorPart editor)

Creates a new context.

Parameters:
  `viewer` - the viewer used by the editor
  `offset` - the invocation offset
  `editor` - the editor that content assist is invoked in

#### JavaContentAssistInvocationContext

    public JavaContentAssistInvocationContext(IJavaScriptUnit unit)

Creates a new context.

Parameters:
  `unit` - the compilation unit in `document`

### Method Detail

#### getCompilationUnit

    public IJavaScriptUnit getCompilationUnit()

Returns the compilation unit that content assist is invoked in, `null` if there is none.

Returns:
  the compilation unit that content assist is invoked in, possibly `null`

#### getProject

    public IJavaScriptProject getProject()

Returns the project of the compilation unit that content assist is invoked in, `null` if none.

Returns:
  the current JavaScript project, possibly `null`

#### getEditor

    public IEditorPart getEditor()

Returns the editor the context is associated with.

Returns:
  the IEditorPart editor, possibly `null`
Since:
  2.0

#### getResource

    public IResource getResource()

Returns the underlined resource, `null` if none.

Returns:
  the current IResource resource, possibly `null`
Since:
  2.0

#### getKeywordProposals

    public IJavaCompletionProposal[] getKeywordProposals()

Returns the keyword proposals that are available in this context, possibly none.

Note: This method may run codeComplete on the compilation unit.

Returns:
  the available keyword proposals

#### getCoreContext

    public CompletionContext getCoreContext()

Returns the `core completion context` if available, `null` otherwise.

Note: This method may run codeComplete on the compilation unit.

Returns:
  the core completion context if available, `null` otherwise

#### getHistoryRelevance

    public float getHistoryRelevance(java.lang.String qualifiedTypeName)

Returns an float in [0.0, 1.0] based on whether the type has been recently used as a right hand side for the type expected in the current context. 0 signals that the `qualifiedTypeName` does not match the expected type, while 1.0 signals that `qualifiedTypeName` has most recently been used in a similar context.

Note: This method may run codeComplete on the compilation unit.

Parameters:
  `qualifiedTypeName` - the type name of the type of interest
Returns:
  a relevance in [0.0, 1.0] based on previous content assist invocations

#### getExpectedType

    public IType getExpectedType()

Returns the expected type if any, `null` otherwise.

Note: This method may run codeComplete on the compilation unit.

Returns:
  the expected type if any, `null` otherwise

#### getLabelProvider

    public CompletionProposalLabelProvider getLabelProvider()

Returns a label provider that can be used to compute proposal labels.

Returns:
  a label provider that can be used to compute proposal labels

#### setCollector

    protected void setCollector(CompletionProposalCollector collector)

Sets the collector, which is used to access the compilation unit, the core context and the label provider. This is a performance optimization: `IJavaCompletionProposalComputer`s may instantiate a `CompletionProposalCollector` and set this invocation context via `CompletionProposalCollector.setInvocationContext(JavaContentAssistInvocationContext)`, which in turn calls this method. This allows the invocation context to retrieve the core context and keyword proposals from the existing collector, instead of computing theses values itself via `computeKeywordsAndContext()`.

Parameters:
  `collector` - the collector