帮助 eclipse 找到我的枚举值?
在使用代码完成时,我无法让 Eclipse 注意到枚举值。 XmlDataDefitions
类提供将从 XML 解析的数据架构。但我似乎无法调用 XmlDataDefitions.xmlTagGroups.xmlLocationList.values().YYZ
或 XmlDataDefinitions.xmlTagGroups.xmlLocationList.XmlTags.id
。代码完成&编译器似乎没有可见的 XmlTags
。
由于某种原因,Eclipse 无法在代码完成中列出 XmlTags
(枚举值)。理想情况下,我想调用 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;
}
}
}
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;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是您的枚举是静态内部类,并且令人难以置信的是,枚举值在包含的类中不可见!
要解决此问题,您需要将枚举类条目静态导入到定义它们的变化类中,如下所示:
然后您将能够使用
device_id
(例如),而无需XmlTags。
资格。我知道这很疯狂,但就是这样。添加静态导入后,Eclipse 将按预期对它们进行代码补全。
另一个解决方法是将枚举放入自己的类中,但像你一样,我通常更喜欢将我的枚举捆绑在一起
枚举到使用/拥有它们的类中(以避免类膨胀 - 这是有意义的)。
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).
我不太确定我知道你想要实现什么目标。但也许你想写这样的表达式?
如果是
这样,请尝试这样:
?
I'm not exactly sure I know what you try to achieve. But maybe you want to write expressions like theese?
to get
If so, try it like this:
?
我在之前看到了编译类的路径在 Windows XP/2000 上大于 259 个字符。在这种情况下,我最终会遇到静态内部类的类未找到错误,这些静态内部类的路径超出了此深度。在处理复杂的 XSD 模式和生成的类时,此类问题非常常见。
考虑使用较短的类名/包并将源代码重新定位到更靠近目录结构根部的位置。
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.