Bug 141518 - IEvaluationContext.newVariable is not considered when doing codecomplete.
Summary: IEvaluationContext.newVariable is not considered when doing codecomplete.
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.3 M3   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-12 06:53 EDT by Max Rydahl Andersen CLA
Modified: 2006-10-30 12:44 EST (History)
0 users

See Also:


Attachments
The fix probably looks like this patch (3.70 KB, patch)
2006-05-12 12:12 EDT, David Audel CLA
no flags Details | Diff
Proposed fix (5.50 KB, patch)
2006-09-25 05:40 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-12 06:53:06 EDT
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)
Comment 1 Max Rydahl Andersen CLA 2006-05-12 06:54:58 EDT
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 ;(
Comment 2 Max Rydahl Andersen CLA 2006-05-12 07:07:04 EDT
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?
Comment 3 David Audel CLA 2006-05-12 10:31:56 EDT
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 4 Max Rydahl Andersen CLA 2006-05-12 10:49:08 EDT
comment to comment 2: doh! (thanks)

original question: Any known workaround ?
Comment 5 David Audel CLA 2006-05-12 11:22:58 EDT
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 ;-)
Comment 6 Max Rydahl Andersen CLA 2006-05-12 11:37:11 EDT
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 ;)
Comment 7 David Audel CLA 2006-05-12 12:12:15 EDT
Created attachment 41327 [details]
The fix probably looks like this patch

This patch:
- evaluate the variables
- add the classfiles to lookupEnvironment.
Comment 8 David Audel CLA 2006-09-25 05:40:05 EDT
Created attachment 50801 [details]
Proposed fix
Comment 9 David Audel CLA 2006-09-25 05:44:34 EDT
Released for 3.3 M3.

Test added
  CompletionTests#testEvaluationContextCompletion5()
Comment 10 Frederic Fusier CLA 2006-10-30 12:44:55 EST
Verified for 3.3 M3 using warm-up build I20061030-0010.