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

java.lang.Object
  extended by org.eclipse.wst.jsdt.ui.text.java.ContentAssistInvocationContext
Direct Known Subclasses:
JavaContentAssistInvocationContext

public class ContentAssistInvocationContext
extends java.lang.Object

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.

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
ContentAssistInvocationContext(ITextViewer viewer)
          Equivalent to ContentAssistInvocationContext(viewer, viewer.getSelectedRange().x).
ContentAssistInvocationContext(ITextViewer viewer, int offset)
          Creates a new context for the given viewer and offset.
 
Method Summary
 java.lang.CharSequence computeIdentifierPrefix()
          Computes the identifier (as specified by Character.isJavaIdentifierPart(char)) that immediately precedes the invocation offset.
 boolean equals(java.lang.Object obj)
          Invocation contexts are equal if they describe the same context and are of the same type.
 IDocument getDocument()
          Returns the document that content assist is invoked on, or null if not known.
 int getInvocationOffset()
          Returns the invocation offset.
 ITextViewer getViewer()
          Returns the viewer, null if not available.
 int hashCode()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentAssistInvocationContext

public ContentAssistInvocationContext(ITextViewer viewer)
Equivalent to ContentAssistInvocationContext(viewer, viewer.getSelectedRange().x).

Parameters:
viewer - the text viewer that content assist is invoked in

ContentAssistInvocationContext

public ContentAssistInvocationContext(ITextViewer viewer,
                                      int offset)
Creates a new context for the given viewer and offset.

Parameters:
viewer - the text viewer that content assist is invoked in
offset - the offset into the viewer's document where content assist is invoked at
Method Detail

getInvocationOffset

public final int getInvocationOffset()
Returns the invocation offset.

Returns:
the invocation offset

getViewer

public final ITextViewer getViewer()
Returns the viewer, null if not available.

Returns:
the viewer, possibly null

getDocument

public IDocument getDocument()
Returns the document that content assist is invoked on, or null if not known.

Returns:
the document or null

computeIdentifierPrefix

public java.lang.CharSequence computeIdentifierPrefix()
                                               throws BadLocationException
Computes the identifier (as specified by Character.isJavaIdentifierPart(char)) that immediately precedes the invocation offset.

Returns:
the prefix preceding the content assist invocation offset, null if there is no document
Throws:
BadLocationException - if accessing the document fails

equals

public boolean equals(java.lang.Object obj)
Invocation contexts are equal if they describe the same context and are of the same type. This implementation checks for null 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().

Overrides:
equals in class java.lang.Object
Parameters:
obj -
Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object