I’m having trouble getting Eclipse to notice the enum values when using code completion. The XmlDataDefitions class provides the schema of data that will be parsed from XML. But I cannot seem to call XmlDataDefitions.xmlTagGroups.xmlLocationList.values().YYZ or XmlDataDefinitions.xmlTagGroups.xmlLocationList.XmlTags.id. Code completion & the compiler do not seem to have the XmlTags visible.
For some reason Eclipse is unable to list off the XmlTags (enum values) in code completion. Ideally I’d like to call XmlDataDefinitions.xmlTagGroups.xmlLocationList.(something).XmlTags.id…
public class XmlDataDefinitions {
public static enum XmlTags {
id,device_id,screen_name,
title,message,
lat_coords,lng_coords,address_string,
loc_seen,account_pic,
from_device_id,to_device_id,
from_screen_name,to_screen_name,
date,
}
public static enum xmlTagGroups {
xmlLocationList(XmlTags.id, XmlTags.device_id, XmlTags.title, XmlTags.message, XmlTags.lat_coords, XmlTags.lng_coords, XmlTags.loc_seen),
xmlMemberList(XmlTags.id, XmlTags.device_id, XmlTags.screen_name, XmlTags.address_string, XmlTags.lat_coords, XmlTags.lng_coords, XmlTags.account_pic),
xmlChatList(XmlTags.id, XmlTags.from_device_id, XmlTags.to_device_id, XmlTags.from_screen_name, XmlTags.to_screen_name, XmlTags.message),
xmlLocationMessage(XmlTags.id, XmlTags.device_id, XmlTags.message,XmlTags.screen_name),
xmlChatMessage(XmlTags.id, XmlTags.from_device_id, XmlTags.to_device_id, XmlTags.from_screen_name, XmlTags.to_screen_name, XmlTags.message, XmlTags.date),
;
public XmlTags[] tags;
private xmlTagGroups (XmlTags ... tags){
this.tags = tags;
}
public XmlTags[] getTags(){
return this.tags;
}
}
}
The problem is that your enums are static inner classes and unbelievably the enum values are not visible inside the containing class!
To fix, you need to static import the enum class entries into the vary class they are defined in, like this:
Then you’ll be able to use
device_id(for example) withoutXmlTags.qualification.Crazy, I know, but there it is. Once you add the static import, Eclipse will code-complete them as expected.
The other fix is to put the enums into their own class, but like you I usually prefer to bundle my
enums into the class that uses/owns them (to avoid class bloat – where it makes sense).