Reputation: 17206
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;
}
}
}
Upvotes: 2
Views: 3764
Reputation: 425063
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:
import static com.mycompany.mypackage.XmlDataDefinitions.XmlTags.*;
Then you'll be able to use device_id
(for example) without XmlTags.
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).
Upvotes: 2
Reputation: 14769
I'm not exactly sure I know what you try to achieve. But maybe you want to write expressions like theese?
import test.XmlTagGroup;
import test.XmlTagGroup.XmlTag;
public class TestIt {
public static void main(String[] args) {
System.out.println(XmlTagGroup.xmlChatList.tags.contains(XmlTag.id));
System.out.println("");
for (XmlTag tag : XmlTagGroup.xmlChatList.tags)
System.out.println(tag);
}
}
to get
true
id
message
from_device_id
to_device_id
from_screen_name
to_screen_name
If so, try it like this:
import java.util.*;
public enum XmlTagGroup {
xmlLocationList(XmlTag.id, XmlTag.device_id, XmlTag.title, XmlTag.message, XmlTag.lat_coords, XmlTag.lng_coords,
XmlTag.loc_seen),
xmlMemberList(XmlTag.id, XmlTag.device_id, XmlTag.screen_name, XmlTag.address_string, XmlTag.lat_coords,
XmlTag.lng_coords, XmlTag.account_pic),
xmlChatList(XmlTag.id, XmlTag.from_device_id, XmlTag.to_device_id, XmlTag.from_screen_name, XmlTag.to_screen_name,
XmlTag.message),
xmlLocationMessage(XmlTag.id, XmlTag.device_id, XmlTag.message, XmlTag.screen_name),
xmlChatMessage(XmlTag.id, XmlTag.from_device_id, XmlTag.to_device_id, XmlTag.from_screen_name,
XmlTag.to_screen_name, XmlTag.message, XmlTag.date),
;
public static enum XmlTag {
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 SortedSet<XmlTag> tags;
private XmlTagGroup(XmlTag... tags) {
this.tags = Collections.unmodifiableSortedSet(new TreeSet<XmlTag>(Arrays.asList(tags)));
}
}
?
Upvotes: 1
Reputation: 17639
I've seen this before where the path to the compiled class is greater than 259 characters on Windows XP/2000. In this case I end up with class not found errors for static inner classes which have a path that exceeds this depth. These kind of issues are quite common when working with complex XSD schemas and generated classes.
Consider using shorter classnames/packages and relocating your source code to somewhere closer to the root of the directory structure.
Upvotes: 0