Community
Participate
Working Groups
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.
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()).
>ResultCollector does not have any CoreContext. To what 'ResultCollector' do you refer?
sorry, old habit of using the old api names ;) The HibernateResultCollector extends CompletionProposalCollector.
The bug is in JDT/Core. Move to JDT/Core.
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.
Dani and Darin, please approve for RC3.
+1 for RC3
Approving for 3.2 RC3.
Fix released and test added CompletionTests#testEvaluationContextCompletion()
I opened a new bug for missing beginReporting() and endReporting(): bug 140123
Verified using N20060504-0010 + JDT/Core v_663
Verified for 3.2RC3 using I20060504-1600 (checking the source code).