Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367088

Summary: [typing] Automatically add variable declaration
Product: [Eclipse Project] JDT Reporter: Nathan Reynolds <numeralnathan>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, deepakazad
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Nathan Reynolds CLA 2011-12-19 10:42:45 EST
Build Identifier: 20110916-0149

Let's say I have the following in a method.

int i;

Then, I type "j = i;"  The variable j is not declared.  So, the editor should automatically add the type in front of j or add the declaration at the top of the method.  Such as shown below.

int i, j;

j = i;

This could be done when assigning a variable to:

- the return value of a method
- a member variable
- a static variable
- a "new some_object_type();"
- a "new some_object_type[];"

Why bother the engineer with types when the editor can automatically do it?

Reproducible: Always
Comment 1 Deepak Azad CLA 2011-12-20 04:45:25 EST
> j = i;
You can use one of the quick fixes offered for the error on 'j' - 'Create local variable', 'Create Field' or 'Create parameter'. Is using a quick fix too hard ?

> So, the editor should
> automatically add the type in front of j or add the declaration at the top of
> the method.
It is not clear about what the developer wants to do in each and every situation, hence I would not start creating declarations automatically.

At best we may possibly show the quick fix popup automatically, but even this is stretching things a bit.
Comment 2 Nathan Reynolds CLA 2011-12-20 11:08:39 EST
I guess the current solution is good enough.