如何覆盖/停止平台SDK提供的问题装饰器

发布于 2024-10-31 10:28:48 字数 1098 浏览 1 评论 0原文

我提到了 http://www.eclipse.org/articles/Article-Decorators /decorators.html 并了解使用与 SDK 装饰器冲突的自定义装饰器是一种不好的做法。

不过,我有一个例外。在我工作的项目中,我们将有关各种模型元素的信息存储在一个物理资源文件下。模型元素在项目资源管理器中表示为单独的节点。当我们编译这些节点时,我想在资源上标记错误,并使用行号来指示有错误的确切元素,从而项目反映它有错误。但同时在项目资源管理器中,我不希望存储在该资源中的所有节点都有问题标记。只有出现错误的节点才应该有问题标记。

我尝试在 BOTTOM_LEFT 位置设置自定义装饰器(使用轻量级和非),但我总是得到 SDK 问题叠加显示。

还有其他方法可以使这项工作有效吗?

这是一个例子。

我们有一个名为nodes.xml 的文件,用于保存电动势模型。 nodel.xml 看起来像

<xml>
<rootnode name="root">
   <childnode name="child1"/>
   <childnode name="child2"/>
   <rootnode name="subroot">
     <childnode name="subchild1"/>
     <childnode name="subchild2"/>
   </rootnode>
</rootnode>
</xml>

所有上述节点在项目资源管理器中表示为项目下树结构的不同节点。作为验证的一部分,我们分别验证每个节点根、child1、child2 等。如果 child1 验证失败,我想添加一个问题标记,以便在第 3 行文件 Nodes.xml 的问题视图中标记错误,但在项目资源管理器中希望错误 Bottom_left 覆盖层仅显示在 child1、根和项目节点上,而不显示在在其他节点上,例如 child2、subroot 等。

希望这能解释我想要实现的目标。

I have referred to http://www.eclipse.org/articles/Article-Decorators/decorators.html and understand that having custom decorators that conflict with SDK decorators is a bad practice.

Though, I have an exception. In project I work we store information about various model elements under one physical resource file. The model elements get represented as separate nodes in project explorer. When we compile these nodes I want to mark error on the resource with line number indicating the exact element with error and thus project reflecting that it has errors. But at same time in Project explorer I do not want all nodes stored in that resource to have problem markers.Only node that had error should have the problem marker.

I have tried setting up custom decorator at BOTTOM_LEFT position(using both lightweight and non), but I always get the SDK problem overlay show.

Are there any other ways to make this work?

Here is an example.

We have a file called nodes.xml where we save our emf model. The nodel.xml looks like

<xml>
<rootnode name="root">
   <childnode name="child1"/>
   <childnode name="child2"/>
   <rootnode name="subroot">
     <childnode name="subchild1"/>
     <childnode name="subchild2"/>
   </rootnode>
</rootnode>
</xml>

All of the above nodes get represented in project explorer as different nodes of tree structure under project. As part of validation we validate each node root, child1, child2 etc separately. If validation fails for child1 I want to add a problem marker such that error gets marked in Problem View on file nodes.xml at line 3, but in project explorer want the error bottom_left overlay show up only on child1, root and project node and not on other nodes such as child2, subroot etc.

Hope this explains what I am trying to acheive.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丘比特射中我 2024-11-07 10:28:48

我不认为你所采取的方法是正确的。您似乎想要从某些 Java 文件中删除问题,因为在您的世界中,它们并不是真正的问题,尽管普通 Java 编译器认为它们是问题。

相反,您应该向工作区注册一个org.eclipse.core.resources.IResourceChangeListener。将其设置为使用 org.eclipse.core.resources.IResourceChangeEvent.POST_BUILD 标志进行通知。像这样:

ResourcesPlugin.getWorkspace.addResourceChangeListener(myListener, POST_BUILD);

您应该在插件启动时执行此操作。这将在工作区中任何项目的所有构建完成后向您发出通知。当弹出您感兴趣的项目时,您可以删除所有 Java 问题标记:

interestingProject.deleteMarkers(
    IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, 
    true, IResource.DEPTH_INFINITE);

这将删除 Java 编译器添加的所有 Java 标记。然后您可以到处添加回您需要的内容。

但警告:上面的操作并不快,即使是中等规模的项目也可能需要几秒钟的时间来扫描所有文件。您可以更加智能地了解要删除的文件,但这需要更多代码和对 API 更深入的了解。上面的片段应该足以帮助您入门。

I do not think that the approach you are taking is the right one. It seems like you want to remove problems from some Java files because in your world they are not really problems even though the vanilla Java Compiler thinks they are.

Instead, you should register a org.eclipse.core.resources.IResourceChangeListener with the workspace. Set it to be notified with the org.eclipse.core.resources.IResourceChangeEvent.POST_BUILD flag. Like this:

ResourcesPlugin.getWorkspace.addResourceChangeListener(myListener, POST_BUILD);

You should do this when your plugin is being started. This will give you notification after all builds of any project in the workspace. When a project that you are interested pops up, you can delete all of the Java problem markers:

interestingProject.deleteMarkers(
    IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, 
    true, IResource.DEPTH_INFINITE);

This will remove all Java markers that the Java compiler adds. You can then go around and add back the ones that you need.

A warning, though: the operation above is not fast and will probably take several seconds to scan through all the files of even medium sized projects. You can be much more intelligent about exactly what files you delete, but that takes more code and a deeper knowledge of the API. The snippets above should be enough to get you started.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文