Package org.eclipse.jdt.ui.text.java
Class ContentAssistInvocationContext
java.lang.Object
org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext
- Direct Known Subclasses:
JavaContentAssistInvocationContext
Describes the context of an invocation of content assist in a text viewer. The context knows the
document, the invocation offset and can lazily compute the identifier prefix preceding the
invocation offset. It may know the viewer.
Subclasses may add information to their environment. For example, source code editors may provide specific context information such as an AST.
Clients may instantiate and subclass.
- Since:
- 3.2
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new context with no viewer or invocation offset set.ContentAssistInvocationContext
(org.eclipse.jface.text.IDocument document, int offset) Creates a new context for the given document and offset.ContentAssistInvocationContext
(org.eclipse.jface.text.ITextViewer viewer) ContentAssistInvocationContext
(org.eclipse.jface.text.ITextViewer viewer, int offset) Creates a new context for the given viewer and offset. -
Method Summary
Modifier and TypeMethodDescriptionComputes the identifier (as specified byCharacter.isJavaIdentifierPart(char)
) that immediately precedes the invocation offset.boolean
Invocation contexts are equal if they describe the same context and are of the same type.org.eclipse.jface.text.IDocument
Returns the document that content assist is invoked on, ornull
if not known.final int
Returns the invocation offset.org.eclipse.jface.text.ITextSelection
Return the current known selection for the viewer, usable in non-UI Thread.final org.eclipse.jface.text.ITextViewer
Returns the viewer,null
if not available.int
hashCode()
-
Constructor Details
-
ContentAssistInvocationContext
public ContentAssistInvocationContext(org.eclipse.jface.text.ITextViewer viewer) - Parameters:
viewer
- the text viewer that content assist is invoked in
-
ContentAssistInvocationContext
public ContentAssistInvocationContext(org.eclipse.jface.text.ITextViewer viewer, int offset) Creates a new context for the given viewer and offset.- Parameters:
viewer
- the text viewer that content assist is invoked inoffset
- the offset into the viewer's document where content assist is invoked at
-
ContentAssistInvocationContext
protected ContentAssistInvocationContext()Creates a new context with no viewer or invocation offset set. -
ContentAssistInvocationContext
public ContentAssistInvocationContext(org.eclipse.jface.text.IDocument document, int offset) Creates a new context for the given document and offset.- Parameters:
document
- the document that content assist is invoked inoffset
- the offset into the document where content assist is invoked at
-
-
Method Details
-
getInvocationOffset
public final int getInvocationOffset()Returns the invocation offset.- Returns:
- the invocation offset
-
getViewer
public final org.eclipse.jface.text.ITextViewer getViewer()Returns the viewer,null
if not available.- Returns:
- the viewer, possibly
null
-
getDocument
public org.eclipse.jface.text.IDocument getDocument()Returns the document that content assist is invoked on, ornull
if not known.- Returns:
- the document or
null
-
computeIdentifierPrefix
Computes the identifier (as specified byCharacter.isJavaIdentifierPart(char)
) that immediately precedes the invocation offset.- Returns:
- the prefix preceding the content assist invocation offset,
null
if there is no document - Throws:
org.eclipse.jface.text.BadLocationException
- if accessing the document fails
-
equals
Invocation contexts are equal if they describe the same context and are of the same type. This implementation checks fornull
values and class equality. Subclasses should extend this method by adding checks for their context relevant fields (but not necessarily cached values).Example:
class MyContext extends ContentAssistInvocationContext { private final Object fState; private Object fCachedInfo; ... public boolean equals(Object obj) { if (!super.equals(obj)) return false; MyContext other= (MyContext) obj; return fState.equals(other.fState); } }
Subclasses should also extend
Object.hashCode()
. -
hashCode
public int hashCode() -
getTextSelection
public org.eclipse.jface.text.ITextSelection getTextSelection()Return the current known selection for the viewer, usable in non-UI Thread.- Returns:
- the text selection if running in UI-Thread or viewer implements
ITextViewerExtension9
, ornull
in other cases. - Since:
- 3.20
-