Bug 137452 - Autocomplete adds "Void" instead of doing nothing
Summary: Autocomplete adds "Void" instead of doing nothing
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.4 M1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-19 03:50 EDT by Koen van Dijken CLA
Modified: 2007-08-03 07:10 EDT (History)
0 users

See Also:


Attachments
Proposed fix (3.81 KB, patch)
2007-06-28 06:12 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 Koen van Dijken CLA 2006-04-19 03:50:42 EDT
In the next code snippet

public class AutoCompleteBug {

    interface I {
        void doIt();
    }
    
    class C1 implements I {
        public void doIt() {
        }
    }
    
    class C2 extends C1 {
        @Override
        public void doIt() {
            super.doIt();
        }
    }
    
}

when te cursor is placed in C2.doIt, just before the '(' and Ctrl-space is pressed, the auto complete feature adds "Void" to the method name, resulting in 

    class C2 extends C1 {
        @Override
        public void doItVoid() {
            super.doIt();
        }
    }

which is illegal. In this case the autocomplete should do nothing.

Usecase and how I discovered this: I have a base class with three methods

class Base {
   method()
   method_1()
   method_2()
}

In a subclass 

class Sub extends Base {
   @Override
   method()
}

I place the cursor in Sub, method 'method', just before the '(', press ctrl-space, I would like to see the following choices:

method()
method_1()
method_2()

Eclipse SDK
Version: 3.2.0
Build id: I20060331-2000
Comment 1 Martin Aeschlimann CLA 2006-04-19 09:49:01 EDT
Moving to jdt.core

At the location there's a single proposal: Local variable 'doItVoid'. Very strange.
Comment 2 David Audel CLA 2006-04-19 11:25:18 EDT
This completion proposal is almost valid. If the type was Object instead of void then a valid proposal would be 'doItObject'. But with void it would better to propose nothing.

'doItObject' would be valid because completion doesn't take into account characters after the completion location. So the proposals must be the same as the proposals of the following test case.
-----------------------------------------
public class AutoCompleteBug {

    interface I {
        Object doIt();
    }

    class C1 implements I {
        public Object doIt() {
            return null;
        }
    }

    class C2 extends C1 {
        @Override
        public void doIt // complete here
    }

}
-----------------------------------------

In this case the completed element is a field name and we compute the field name from the type of this field.



But if the field type is void (as in your test case) this cannot be a field, so we should do nothing instead of propose 'doItVoid'.
Comment 3 David Audel CLA 2007-06-28 06:12:16 EDT
Created attachment 72669 [details]
Proposed fix
Comment 4 David Audel CLA 2007-06-28 06:14:00 EDT
Released for 3.4M1.

Test added
  CompletionTests#testCompletionVariableName39()
Comment 5 Frederic Fusier CLA 2007-08-03 07:10:25 EDT
Verified for 3.4M1 using build I20070802-0800.

Note that only the 'Void' completion is fixed (summary of the  bug).
In other comment 0 test case:
class Base {
   void method() {}
   void method_1() {}
   void method_2() {}
}
class Sub extends Base {
	@Override
	void method // <- complete here...
}

there's still no completion proposal.

I'm not sure if this is the expected behavior or not.