Bug 139937 - CompletionContext not automatically accepted when using IEvaluationContext
Summary: CompletionContext not automatically accepted when using IEvaluationContext
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC3   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-03 08:58 EDT by Max Rydahl Andersen CLA
Modified: 2006-05-04 20:32 EDT (History)
4 users (show)

See Also:


Attachments
Proposed fix (3.00 KB, patch)
2006-05-03 12:01 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Max Rydahl Andersen CLA 2006-05-03 08:58:22 EDT
I'm trying to port some 3.1 usage of Java code completion to 3.2.
 
Currently I am using something like this:
 
IEvaluationContext context = javaProject.newEvaluationContext();
if(packageName!=null) {
context.setPackageName(packageName);
}

HibernateResultCollector rc = new HibernateResultCollector(javaProject);
//rc.reset(offset, javaProject, null);
rc.setAccepts(settings);
try {
// cannot send in my own document as it won't compile as
// java - so we just send in
// the smallest snippet possible
context.codeComplete(start, start.length(), rc);
} catch (JavaModelException jme) {
HibernateConsolePlugin.getDefault().logErrorMessage("Could not complete 
java types", jme);
}
IJavaCompletionProposal[] results = rc.getJavaCompletionProposals();

This worked like a charm before, but now I am getting "null assertions", because
the ResultCollector does not have any CoreContext.
 
I fixed this by calling rc.accept(new CompletionContext()); before performing the code completion ?

Is this an expected change ? Cannot seem to find anything in the api docs on this.
Comment 1 David Audel CLA 2006-05-03 09:13:14 EDT
I think that this problem is caused by a bug in JDT/Core. When IEvaluationContext#codeComplete() is used, the given requestor is wrapped inside another requestor (see CodeSnippetToCuMapper#getCompletionRequestor()) and the wrapper doesn't call acceptContect(), beginReporting() and endReporting() of the original requestor.

This bug already exists in 3.1 but the usage of the context in JDT/Text seems to have change in 3.2 (usage of getContext().isInJavadoc()).
Comment 2 Dani Megert CLA 2006-05-03 09:14:46 EDT
>ResultCollector does not have any CoreContext.
To what 'ResultCollector' do you refer?
Comment 3 Max Rydahl Andersen CLA 2006-05-03 09:16:20 EDT
sorry, old habit of using the old api names ;)

The HibernateResultCollector extends CompletionProposalCollector.

Comment 4 David Audel CLA 2006-05-03 11:10:50 EDT
The bug is in JDT/Core.

Move to JDT/Core.
Comment 5 David Audel CLA 2006-05-03 12:01:22 EDT
Created attachment 40240 [details]
Proposed fix

As said in comment 1, the problem is in the wrapper. The wrapper doesn't do a callback of acceptContext(). To fix the problem i add this missing method call.

There are also other missing callbacks of beginReporting(), endReporting and isIgnored(). But as this bug exists in 3.1 and that we are late in 3.2 plan, the patch only fix the missing acceptContext() to avoid to potentially broke clients.
Comment 6 David Audel CLA 2006-05-03 12:03:12 EDT
Dani and Darin, please approve for RC3.
Comment 7 Darin Wright CLA 2006-05-03 12:14:41 EDT
+1 for RC3
Comment 8 Dani Megert CLA 2006-05-03 12:21:21 EDT
Approving for 3.2 RC3.
Comment 9 David Audel CLA 2006-05-03 13:10:35 EDT
Fix released and test added
  CompletionTests#testEvaluationContextCompletion()
Comment 10 David Audel CLA 2006-05-04 05:28:17 EDT
I opened a new bug for missing beginReporting() and endReporting(): bug 140123
Comment 11 Frederic Fusier CLA 2006-05-04 07:17:23 EDT
Verified using N20060504-0010 + JDT/Core v_663
Comment 12 Olivier Thomann CLA 2006-05-04 20:32:52 EDT
Verified for 3.2RC3 using I20060504-1600 (checking the source code).