Community
Participate
Working Groups
I love the new easier API in 3.2 for codecompletion on IEvaluationContext, but I have some problems using newVariable method. For some reason newVariable does not take effect when I perform a codeComplete - is that intentional ? Here is a snippet to illustrate what I'm doing: IEvaluationContext evalCtx = null ; if (project != null) { evalCtx = project.newEvaluationContext(); } if (evalCtx != null) { evalCtx.setImports(getImports()); evalCtx.newVariable( "someType", "someVariable", null ); } String code = "someVariable."; IEvaluationContext e= getEvaluationContext(project); if (e != null) { e.codeComplete(code, code.length()-1, collector); } This result in no code completion for "someVariable." But if code is instead: "someType someVariable; someVariable."; then it works. someVariable get it's code completion. It looks like I have to call some of the evaluateXXX methods; but they all seem to want to deploy Class's which I don't understand the need for when writing the code in the string works fine. If evaluateXXX methods is the only way; what should I call them with ? Every implementations of the variables are internal API. (Asked by Jerome Lanneluc <jerome_lanneluc@fr.ibm.com> from the newsgroup to enter it as a bug here)
Btw. my workaround right now is to prefix my code with the declarations, but then I have to transpose all the offsets of the resulting JavaCompletionProposal which again requires me to use non-public API and dirty tricks ;(
btw. I do not know if this is related but with the codeComplete it seem to be required by the user to know the first letter of a method to get completion for the real type. e.g. Session s; s.<ctrl+space> Gives methods on java.lang.Object and nothing from the Session class. but Session s; s.c<ctrl+space> Gives methods on the Session that starts with "c" (and actually also some starting with "b" ?) Another bug maybe?
About comment 2: You don't use the correct offset. You must use 'code.length()' instead of 'code.length()-1'. About the original problem: Your diagnosis is good. Currently we have a bug. The global variables are ignored by code assist unless you evaluate them and deploy class files. codeComplete should be able to take into account this variables without evaluating them. This is not a regression, this bug seems to exist since 1.0. A fix to the problem should be investigated after 3.2.
comment to comment 2: doh! (thanks) original question: Any known workaround ?
I have no better workaround than added the variable declaration at the beginning of the snippet :( I have a question for you. Why do you say in your first comment 'I love the new easier API in 3.2 ...'? I ask that because this is not a new API. I can suppose that you used ICodeAssist#codeComplete() or IType#codeComplete() before, exact ? So why this one is easier for you ? I know, i am curious ;-)
I think i got this stuff mixed up with the new feature of being able to create a CU without a real JavaProject which I also started using ;)
Created attachment 41327 [details] The fix probably looks like this patch This patch: - evaluate the variables - add the classfiles to lookupEnvironment.
Created attachment 50801 [details] Proposed fix
Released for 3.3 M3. Test added CompletionTests#testEvaluationContextCompletion5()
Verified for 3.3 M3 using warm-up build I20061030-0010.