Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 318928 - Code completion does not recognize enum type from inherited class
Summary: Code completion does not recognize enum type from inherited class
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 4.11 M3   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-05 13:22 EDT by Chad CLA
Modified: 2019-02-20 00:08 EST (History)
4 users (show)

See Also:


Attachments
Screenshot of code completion (11.21 KB, image/png)
2010-07-05 18:37 EDT, Chad CLA
no flags Details
Screenshot of code completion recognizing after manually type "Type" (13.08 KB, image/png)
2010-07-05 18:44 EDT, Chad CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chad CLA 2010-07-05 13:22:29 EDT
Build Identifier: 20100218-1602

I have a class which contains an enumerated type. When I extend that class, code completion does not recognize the enumerated type from the parent class. Reproducing requires the creation of 3 classes, which are below:

public class Parent {
	public static enum Type {
		TYPE_1,
		TYPE_2,
		TYPE_3
	}
	public static int i = 0;
}

public class Child extends Parent {

}

public class Test {
	public Test() {
		Child child = new Child();
		child.i  <------ Code completion properly recognizes int type
		child.   <------ Code completion does not recognize enum "Type"
	}
}


Reproducible: Always

Steps to Reproduce:
1. Create class Parent
2. Create a 'public static enum' attribute in Parent
3. Create class Child, which extends Parent
4. Create a class Test, in this class, create an instance of Child
5. On that instance, hit the '.' to bring up code completion. You will not find the enumerated type available there
Comment 1 Stephan Herrmann CLA 2010-07-05 16:07:50 EDT
Already writing child.i is debatable and actually triggers a warning
"The static field Parent.i should be accessed in a static way"
(which may or may not be enabled in your settings).

"child.Type" isn't even accepted by the compiler:
"child.Type cannot be resolved to a type"
so it wouldn't be a good idea to propose this for completion :)

The proper way for using "Type" is "Parent.Type":
- don't use an instance to qualify a static member type
- for static members use the actual declaring type as qualification,
  not a subclass
Comment 2 Chad CLA 2010-07-05 18:37:30 EDT
Created attachment 173485 [details]
Screenshot of code completion
Comment 3 Chad CLA 2010-07-05 18:40:09 EDT
(In reply to comment #1)
> Already writing child.i is debatable and actually triggers a warning
> "The static field Parent.i should be accessed in a static way"
> (which may or may not be enabled in your settings).
> 
> "child.Type" isn't even accepted by the compiler:
> "child.Type cannot be resolved to a type"
> so it wouldn't be a good idea to propose this for completion :)
> 
> The proper way for using "Type" is "Parent.Type":
> - don't use an instance to qualify a static member type
> - for static members use the actual declaring type as qualification,
>   not a subclass

Yes, my apologies. I did not mean to access the static member with an instantiation. Please disregard the instantiation portion. Instead, for Test I meant to put:

public class Test {
	public Test() {
		Child.
	}
}

However, it seems that other static types that are declared in the parent are recognized by code completion in the Child. I have tested the following primitive types and objects, and code completion recognizes all of them except the enum type. Please find example code below:

public class Parent {
	public static enum Type {
		TYPE_1,
		TYPE_2,
		TYPE_3
	}
	public static long l = 0;
	public static int i = 0;
	public static short sh = 0;
	public static double d = 0d;
	public static float f = 0f;
	public static char ch = 'a';
	public static String s = "";
	public static StringBuilder sb = new StringBuilder();
}

public class Child extends Parent {

}

public class Test {
	public Test() {
		Child.    <----- Code completion recognizes every static attribute except of type "enum" (does not recognize "Type")
		Child.Type.   <------ Code completion recognizes "TYPE_1, TYPE_2, TYPE_3"
	}
}

Also, please find a screenshot attached.

Thanks!
Kindest Regards,
Chad
Comment 4 Chad CLA 2010-07-05 18:44:44 EDT
Created attachment 173486 [details]
Screenshot of code completion recognizing after manually type "Type"
Comment 5 Srikanth Sankaran CLA 2010-07-05 22:40:02 EDT
Ayush, please investigate. Thanks.
Comment 6 Ayushman Jain CLA 2010-07-06 02:36:50 EDT
I'll take a look
Comment 7 Eclipse Genie CLA 2019-02-17 16:32:19 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 8 Stephan Herrmann CLA 2019-02-17 17:48:03 EST
Child.x access for a static member of Parent is not recommended and will trigger a warning. Hence I don't see a priority in changing completion to propose more of that kind.
Comment 9 Jay Arthanareeswaran CLA 2019-02-20 00:06:56 EST
Verified for 4.11 M3