public class CompletionProposalCollector extends CompletionRequestor
CompletionRequestor
. Produces
IJavaCompletionProposal
s from the proposal descriptors received via
the CompletionRequestor
interface.
The lifecycle of a CompletionProposalCollector
instance is very
simple:
ICompilationUnit unit= ... int offset= ... CompletionProposalCollector collector= new CompletionProposalCollector(unit); unit.codeComplete(offset, collector); IJavaCompletionProposal[] proposals= collector.getJavaCompletionProposals(); String errorMessage= collector.getErrorMessage(); // display / process proposalsNote 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.
Modifier and Type | Field and Description |
---|---|
protected static char[] |
METHOD_TRIGGERS
Triggers for method proposals without parameters.
|
protected static char[] |
METHOD_WITH_ARGUMENTS_TRIGGERS
Triggers for method proposals.
|
protected static char[] |
TYPE_TRIGGERS
Triggers for types.
|
protected static char[] |
VAR_TRIGGER
Triggers for variables.
|
Constructor and Description |
---|
CompletionProposalCollector(ICompilationUnit cu)
Creates a new instance ready to collect proposals.
|
CompletionProposalCollector(ICompilationUnit cu,
boolean ignoreAll)
Creates a new instance ready to collect proposals.
|
CompletionProposalCollector(IJavaProject project)
Creates a new instance ready to collect proposals.
|
Modifier and Type | Method and Description |
---|---|
void |
accept(CompletionProposal proposal)
Proposes a completion.
|
void |
acceptContext(CompletionContext context)
Propose the context in which the completion occurs.
|
void |
beginReporting()
Pro forma notification sent before reporting a batch of
completion proposals.
|
void |
completionFailure(IProblem problem)
Notification of failure to produce any completions.
|
protected int |
computeRelevance(CompletionProposal proposal)
Computes the relevance for a given
CompletionProposal . |
protected IJavaCompletionProposal |
createJavaCompletionProposal(CompletionProposal proposal)
Creates a new java completion proposal from a core proposal.
|
protected IContextInformation |
createMethodContextInformation(CompletionProposal methodProposal)
Creates the context information for a given method reference proposal.
|
void |
endReporting()
Pro forma notification sent after reporting a batch of
completion proposals.
|
protected ICompilationUnit |
getCompilationUnit()
Returns the compilation unit that the receiver operates on, or
null if the IJavaProject constructor was
used to create the receiver. |
protected CompletionContext |
getContext()
Returns the
CompletionContext for this completion operation. |
protected char[] |
getDeclaringType(CompletionProposal proposal)
Returns the type signature of the declaring type of a
CompletionProposal , or null for proposals
that do not have a declaring type. |
String |
getErrorMessage()
Returns an error message about any error that may have occurred during
code completion, or the empty string if none.
|
protected Image |
getImage(ImageDescriptor descriptor)
Returns a cached image for the given descriptor.
|
protected JavaContentAssistInvocationContext |
getInvocationContext()
Returns the invocation context.
|
IJavaCompletionProposal[] |
getJavaCompletionProposals()
Returns the unsorted list of received proposals.
|
IJavaCompletionProposal[] |
getKeywordCompletionProposals()
Returns the unsorted list of received keyword proposals.
|
protected CompletionProposalLabelProvider |
getLabelProvider()
Returns the proposal label provider used by the receiver.
|
protected int |
getLength(CompletionProposal proposal)
Returns the replacement length of a given completion proposal.
|
protected boolean |
isFiltered(CompletionProposal proposal)
Returns
true if proposal is filtered, e.g. |
void |
setIgnored(int completionProposalKind,
boolean ignore)
Sets whether the given kind of completion proposal is ignored.
|
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.
|
getFavoriteReferences, isAllowingRequiredProposals, isExtendedContextRequired, isIgnored, setAllowsRequiredProposals, setFavoriteReferences, setRequireExtendedContext
protected static final char[] METHOD_TRIGGERS
protected static final char[] METHOD_WITH_ARGUMENTS_TRIGGERS
protected static final char[] TYPE_TRIGGERS
protected static final char[] VAR_TRIGGER
public CompletionProposalCollector(ICompilationUnit cu)
ICompilationUnit
is not contained in an
IJavaProject
, no javadoc will be available as
additional info
on the created proposals.cu
- the compilation unit that the result collector will operate onpublic CompletionProposalCollector(IJavaProject project)
CompletionProposalCollector(ICompilationUnit)
instead to get all proposals.
If the passed Java project is null
, no javadoc will be
available as
additional info
on the created (e.g. method and type) proposals.
project
- the project that the result collector will operate on, or
null
public CompletionProposalCollector(ICompilationUnit cu, boolean ignoreAll)
ICompilationUnit
is not contained in an
IJavaProject
, no javadoc will be available as
additional info
on the created proposals.cu
- the compilation unit that the result collector will operate onignoreAll
- true
to ignore all kinds of completion proposalspublic void setIgnored(int completionProposalKind, boolean ignore)
CompletionRequestor
setIgnored
in class CompletionRequestor
completionProposalKind
- one of the kind constants declared
on CompletionProposal
ignore
- true
if the given kind of completion proposal
is ignored by this requestor, and false
if it is of
interestCompletionRequestor.isIgnored(int)
,
CompletionProposal.getKind()
public void setInvocationContext(JavaContentAssistInvocationContext context)
Subclasses may extend.
context
- the invocation contextgetInvocationContext()
protected final JavaContentAssistInvocationContext getInvocationContext()
setInvocationContext(JavaContentAssistInvocationContext)
, a new one is created.public void accept(CompletionProposal proposal)
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.
accept
in class CompletionRequestor
proposal
- the completion proposalpublic void acceptContext(CompletionContext context)
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.
acceptContext
in class CompletionRequestor
context
- the completion contextgetContext()
public void beginReporting()
The default implementation of this method does nothing. Clients may override.
Subclasses may extend, but must call the super implementation.beginReporting
in class CompletionRequestor
public void completionFailure(IProblem problem)
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.completionFailure
in class CompletionRequestor
problem
- the problem objectpublic void endReporting()
The default implementation of this method does nothing. Clients may override.
Subclasses may extend, but must call the super implementation.endReporting
in class CompletionRequestor
public String getErrorMessage()
Subclasses may replace or extend.
public final IJavaCompletionProposal[] getJavaCompletionProposals()
public final IJavaCompletionProposal[] getKeywordCompletionProposals()
public final void setReplacementLength(int length)
length
- the new replacement length, relative to the code assist
offset. Must be equal to or greater than zero.protected int computeRelevance(CompletionProposal proposal)
CompletionProposal
.
Subclasses may replace, but usually should not need to.
proposal
- the proposal to compute the relevance forproposal
protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal)
This method is called for every proposal that will be displayed to the user, which may be hundreds. Implementations should therefore defer as much work as possible: Labels should be computed lazily to leverage virtual table usage, and any information only needed when applying a proposal should not be computed yet.
Implementations may return null
if a proposal should not
be included in the list presented to the user.
Subclasses may extend or replace this method.
proposal
- the core completion proposal to create a UI proposal fornull
if
no proposal should be displayedprotected final IContextInformation createMethodContextInformation(CompletionProposal methodProposal)
CompletionProposal.METHOD_REF
.methodProposal
- the method proposal for which to create context informationmethodProposal
protected final ICompilationUnit getCompilationUnit()
null
if the IJavaProject
constructor was
used to create the receiver.null
protected final CompletionContext getContext()
CompletionContext
for this completion operation.CompletionContext
for this completion operationCompletionRequestor.acceptContext(CompletionContext)
protected final Image getImage(ImageDescriptor descriptor)
descriptor
- the image descriptor to get an image for, may be
null
descriptor
protected final CompletionProposalLabelProvider getLabelProvider()
protected final int getLength(CompletionProposal proposal)
proposal.getReplaceEnd
and
proposal.getReplaceStart
, but this behavior may be
overridden by calling setReplacementLength(int)
.proposal
- the completion proposal to get the replacement length forproposal
protected boolean isFiltered(CompletionProposal proposal)
true
if proposal
is filtered, e.g.
should not be proposed to the user, false
if it is valid.
Subclasses may extends this method. The default implementation filters proposals set to be ignored via setIgnored and types set to be ignored in the preferences.
proposal
- the proposal to filtertrue
to filter proposal
,
false
to let it passprotected final char[] getDeclaringType(CompletionProposal proposal)
CompletionProposal
, or null
for proposals
that do not have a declaring type. The return value is not
null
for proposals of the following kinds:
proposal
- the completion proposal to get the declaring type fornull
if there is noneSignature.toCharArray(char[])
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.