Bug 86970 - [codeassist] Add an API on completion proposal API to surface the expected type
Summary: [codeassist] Add an API on completion proposal API to surface the expected type
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-02 04:10 EST by David Audel CLA
Modified: 2005-03-31 10:48 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Audel CLA 2005-03-02 04:10:47 EST
We should add an API on completion proposal API to surface the expected type
when we had one in the engine.
Comment 1 Dirk Baeumer CLA 2005-03-02 13:48:22 EST
Tom,

this will allow use to get the rhs of an assigment to guess the type arguments
for generics (e.g List<String> l= new ArrayList<???>)
Comment 2 David Audel CLA 2005-03-16 07:49:17 EST
Fixed.

Added new completion API to describe context in which the completion occurs.<br>
Currently only the expected types of the potential completion proposals are
proposed.

 X x = zzz<complete here>

In this example the expected type is <code>X</code>. It is not mandatory to a
proposal to respect this expectation and it is possible that there is no
completion proposal.

/**
 * Completion context.
 * 
 * Represent the context in which the completion occurs.
 * 
 * @see CompletionRequestor#acceptContext(CompletionContext)
 * @since 3.1
 */
public class CompletionContext  {
  /**
   * Return signatures of expected types of a potential completion proposal at
the completion position.
   * 
   * It's not mandatory to a completion proposal to respect this expectation. 
   * 
   * @return signatures expected types of a potential completion proposal at the
completion position or
   * <code>null</code> if there is no expected types.
   * 
   * @see Signature
   */
  public char[][] getExpectedTypesSignatures() {...}
  /**
   * Return keys of expected types of a potential completion proposal at the
completion position.
   * 
   * It's not mandatory to a completion proposal to respect this expectation. 
   * 
   * @return keys of expected types of a potential completion proposal at the
completion position or
   * <code>null</code> if there is no expected types.
   * 
   * @see org.eclipse.jdt.core.dom.ASTParser#createASTs(ICompilationUnit[],
String[], org.eclipse.jdt.core.dom.ASTRequestor,
org.eclipse.core.runtime.IProgressMonitor)
   */
  public char[][] getExpectedTypesKeys() {...}
}

Client must override 'CompletionRequestor#acceptContext(..)' to know the
context. This method call ocurs after the call to 'beginReporting()' and before
the call to any 'accept(CompletionProposal)' method.

public class CompletionRequestor {
  ...
  /**
   * Propose the context in which the completion occurs.
   * <p>
   * This method is called one and only one time before any call to
   * {@link #accept(CompletionProposal)}.
   * The default implementation of this method does nothing.
   * Clients may override.
   * </p>
   * @param context the completion context
   * 
   * @since 3.1
   */
  public void acceptContext(CompletionContext context) {..}
  ...   
}
Comment 3 Jim des Rivieres CLA 2005-03-18 18:34:24 EST
Why does the new API class CompletionContext have an internal class 
InternalCompletionContext as its superclass? The superclass has protected 
methods which are inherited by the API class, and would normally be considered 
API as well. However, CompletionContext is final, so there is 0 change that a 
client could use those method. Would it not be simpler simpler to get rid of 
InternalCompletionContext entirely?
Comment 4 David Audel CLA 2005-03-21 04:41:52 EST
Methods of InternalCompletionContext are not design to be API.
InternalCompletionContext is not inside the same package of API class
CompletionContext, so client can use this protected methods only inside the same
package. But the package of InternalCompletionContext is an 'internal' not API
package.

If these methods are inside CompletonContext, then they would be public method
inside an API class. In this case the only way to forbid access to these methods
would be to add a comment /** this method is not API */.

Move methods inside CompletionContext and add the comment would be better ?
Comment 5 Jim des Rivieres CLA 2005-03-23 18:55:59 EST
I couldn'd find any internal callers of those methods on 
InternalCompletionContext. Are there any?  If there are, what I suggest
doing is change the protected methods on InternalCompletionContext to
package-private so that they do not show up in generated Javadoc as being 
inherited.
Comment 6 David Audel CLA 2005-03-24 03:30:00 EST
These methods are called inside CompletionEngine.
Comment 7 David Audel CLA 2005-03-30 08:54:53 EST
Change the resolution to Fixed
Comment 8 David Audel CLA 2005-03-31 10:48:59 EST
Verified in I20050330-0500