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

java.lang.Object
  extended by org.eclipse.wst.jsdt.core.CompletionRequestor
      extended by org.eclipse.wst.jsdt.ui.text.java.CompletionProposalCollector

public class CompletionProposalCollector
extends CompletionRequestor

JavaScript UI implementation of CompletionRequestor. Produces IJavaCompletionProposals from the proposal descriptors received via the CompletionRequestor interface.

The lifecycle of a CompletionProposalCollector instance is very simple:

 IJavaScriptUnit unit= ...
 int offset= ...
 
 CompletionProposalCollector collector= new CompletionProposalCollector(unit);
 unit.codeComplete(offset, collector);
 IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals();
 String errorMessage= collector.getErrorMessage();
 
 // display / process proposals
 
Note that after a code completion operation, the collector will store any received proposals, which may require a considerable amount of memory, so the collector should not be kept as a reference after a completion operation.

Clients may instantiate or 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
CompletionProposalCollector(IJavaScriptProject project)
          Creates a new instance ready to collect proposals.
CompletionProposalCollector(IJavaScriptUnit cu)
          Creates a new instance ready to collect proposals.
 
Method Summary
 void accept(CompletionProposal proposal)
          Proposes a completion. Subclasses may replace, but usually should not need to.
 void acceptContext(CompletionContext context)
          Propose the context in which the completion occurs. Subclasses may extend, but usually should not need to.
 void beginReporting()
          Pro forma notification sent before reporting a batch of completion proposals. Subclasses may extend, but must call the super implementation.
 void completionFailure(IProblem problem)
          Notification of failure to produce any completions. Subclasses may extend, but must call the super implementation.
 void endReporting()
          Pro forma notification sent after reporting a batch of completion proposals. Subclasses may extend, but must call the super implementation.
 java.lang.String getErrorMessage()
          Returns an error message about any error that may have occurred during code completion, or the empty string if none.
 IJavaCompletionProposal[] getJavaCompletionProposals()
          Returns the unsorted list of received proposals.
 org.eclipse.wst.jsdt.internal.ui.text.java.JavaCompletionProposal[] getKeywordCompletionProposals()
          Returns the unsorted list of received keyword proposals.
 void setInvocationContext(JavaContentAssistInvocationContext context)
          Sets the invocation context.
 void setReplacementLength(int length)
          If the replacement length is set, it overrides the length returned from the content assist infrastructure.
 
Methods inherited from class org.eclipse.wst.jsdt.core.CompletionRequestor
getFavoriteReferences, isAllowingRequiredProposals, isIgnored, setAllowsRequiredProposals, setFavoriteReferences, setIgnored
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompletionProposalCollector

public CompletionProposalCollector(IJavaScriptUnit cu)
Creates a new instance ready to collect proposals. If the passed IJavaScriptUnit is not contained in an IJavaScriptProject, no javadoc will be available as additional info on the created proposals.

Parameters:
cu - the compilation unit that the result collector will operate on

CompletionProposalCollector

public CompletionProposalCollector(IJavaScriptProject project)
Creates a new instance ready to collect proposals. Note that proposals for anonymous types and method declarations are not created when using this constructor, as those need to know the compilation unit that they are created on. Use CompletionProposalCollector(IJavaScriptUnit) instead to get all proposals.

If the passed JavaScript project is null, no javadoc will be available as additional info on the created (e.g. method and type) proposals.

Parameters:
project - the project that the result collector will operate on, or null
Method Detail

setInvocationContext

public void setInvocationContext(JavaContentAssistInvocationContext context)
Sets the invocation context.

Subclasses may extend.

Parameters:
context - the invocation context
See Also:
getInvocationContext()

accept

public void accept(CompletionProposal proposal)
Proposes a completion. Has no effect if the kind of proposal is being ignored by this requestor. Callers should consider checking CompletionRequestor.isIgnored(int) before avoid creating proposal objects that would only be ignored.

Similarly, implementers should check isIgnored(proposal.getKind()) and ignore proposals that have been declared as uninteresting. The proposal object passed is only valid for the duration of completion operation.

Subclasses may replace, but usually should not need to. Consider replacing createJavaCompletionProposal instead.

Specified by:
accept in class CompletionRequestor
Parameters:
proposal - the completion proposal

acceptContext

public void acceptContext(CompletionContext context)
Propose the context in which the completion occurs.

This method is called one and only one time before any call to CompletionRequestor.accept(CompletionProposal). The default implementation of this method does nothing. Clients may override.

Subclasses may extend, but usually should not need to.

Overrides:
acceptContext in class CompletionRequestor
Parameters:
context - the completion context
See Also:
getContext()

beginReporting

public void beginReporting()
Pro forma notification sent before reporting a batch of completion proposals.

The default implementation of this method does nothing. Clients may override.

Subclasses may extend, but must call the super implementation.

Overrides:
beginReporting in class CompletionRequestor

completionFailure

public void completionFailure(IProblem problem)
Notification of failure to produce any completions. The problem object explains what prevented completing.

The default implementation of this method does nothing. Clients may override to receive this kind of notice.

Subclasses may extend, but must call the super implementation.

Overrides:
completionFailure in class CompletionRequestor
Parameters:
problem - the problem object

endReporting

public void endReporting()
Pro forma notification sent after reporting a batch of completion proposals.

The default implementation of this method does nothing. Clients may override.

Subclasses may extend, but must call the super implementation.

Overrides:
endReporting in class CompletionRequestor

getErrorMessage

public java.lang.String getErrorMessage()
Returns an error message about any error that may have occurred during code completion, or the empty string if none.

Subclasses may replace or extend.

Returns:
an error message or the empty string

getJavaCompletionProposals

public final IJavaCompletionProposal[] getJavaCompletionProposals()
Returns the unsorted list of received proposals.

Returns:
the unsorted list of received proposals

getKeywordCompletionProposals

public final org.eclipse.wst.jsdt.internal.ui.text.java.JavaCompletionProposal[] getKeywordCompletionProposals()
Returns the unsorted list of received keyword proposals.

Returns:
the unsorted list of received keyword proposals

setReplacementLength

public final void setReplacementLength(int length)
If the replacement length is set, it overrides the length returned from the content assist infrastructure. Use this setting if code assist is called with a none empty selection.

Parameters:
length - the new replacement length, relative to the code assist offset. Must be equal to or greater than zero.