禁止复制和复制粘贴,有没有办法共享Java详细格式化程序

发布于 2024-10-21 23:21:26 字数 2799 浏览 1 评论 0原文

我们店里有 5-10 名开发人员使用 Java 来处理 Eclipse,而且我们经常调试不具有调试友好的 toString() 的类。

随之而来的是 详细格式化程序来挽救局面。欢呼!但只有的一天。如果我想与其他开发人员分享喜悦,我想我必须像他们一样进行一些复制和粘贴。

太糟糕了。我们有 N 个可以在 Eclipse 中工作的不同版本控制系统...这似乎是人们想要传递的东西。

文件 -> 导出... 对话框中没有任何内容。通过搜索在线帮助什么也没有。没有什么。

我设法跟踪至少一些设置 /workspace/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.dbug.ui.prefs,但有原因相信事情远不止于此。另外,一想到将隐藏文件夹深处的东西放入源代码管理中,我就感到紧张。

有没有更好的方法来共享详细格式化程序?理想情况下,我们只需检查我们的代码存储库并以这种方式传播即可。

编辑:我正在使用 Helios,服务版本 1,内部版本号 20100917-0705。


除了javaLogicalStructures 扩展点(用于向给定类添加逻辑结构)之外,还有一个名为detailPaneFactories 的扩展点。但这是为了创建详细格式化程序渲染到的文本(或其他任何内容,感谢这个扩展点)的窗格。两者都不允许扩展程序列出现有的详细格式化程序(或与此相关的逻辑结构)。

detailPaneFactories 扩展的底部确实有一些有趣的话:

    Supplied Implementation:
    The debug platform contributes a detail pane factory providing a default 
    text source viewer detail pane. The default detail pane displays textual
    details of a selected element based on the corresponding debug model 
    presentation's implementation of computeDetail(IValue value, 
    IValueDetailListener listener). 

computeDetail 听起来很有希望。我会随时通知您(除非其他人比我先一步...万岁赏金)。

嗯... org.eclipse.jdt.debug.ui.JavaDebugUtils.getPreferenceStore() 听起来很有希望,但我仍然不想自己为此编写一个插件。

啊……好吧。以下是 org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager 用于加载它们的代码:

    /**
     * Populate the detail formatters map with data from preferences.
     */
    private void populateDetailFormattersMap() {
            String[] detailFormattersList= JavaDebugOptionsManager.parseList(JDIDebugUIPlugin.getDefault().getPreferenceStore().getString(IJDIPreferencesConstants.PREF_DETAIL_FORMATTERS_LIST));
            fDetailFormattersMap= new HashMap(detailFormattersList.length / 3);
            for (int i= 0, length= detailFormattersList.length; i < length;) {
                    String typeName= detailFormattersList[i++];
                    String snippet= detailFormattersList[i++].replace('\u0000', ',');
                    boolean enabled= ! JavaDetailFormattersPreferencePage.DETAIL_FORMATTER_IS_DISABLED.equals(detailFormattersList[i++]);
                    fDetailFormattersMap.put(typeName, new DetailFormatter(typeName, snippet, enabled));
            }
    }

因此首选项存储中的字符串只是一堆带有类型名称、片段、启用的 CSV, type-name... 在代码片段中将 \u0000 替换为 , ,然后就可以开始了。

它处理导出(地狱,你可以直接转储整个偏好字符串)。

导入不会更困难,尽管最好不要覆盖现有类型,或者为用户提供这样做的选项,甚至可能存在所讨论的两个片段的差异。

OTOH,我真的宁愿不依赖*.internal.*中类的内部工作原理。

We have 5-10 developers working on Eclipse with Java here in our shop, and we often are debugging classes that don't have debug-friendly toString().

Along comes Detail Formatters to save the day. Hurray! But only my day. If I want to share the joy with my fellow devs, I THINK I have to do some copying and pasting, as do they.

That sucks. We've got N different version control systems that work in Eclipse... it seems like this would be something that folks would Like To Pass Around.

Nothing in the file->export... dialog. Nothing via searching the online help. Nothing.

I managed to track at least some of the settings to /workspace/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.dbug.ui.prefs, but Have Reason To Believe there's more to it than that. Plus, the thought of putting something burried deep in a hidden folder into source control puts my teeth on edge.

Is there a better way to share detail formatters? Ideally this would be something we could just check into our code repo and disseminate that way.

EDIT: I'm using Helios, Service Release 1, build id 20100917-0705.


In addition to the javaLogicalStructures extension point (for adding logical structure to given classes), there's also one called detailPaneFactories. But this is for creating the pane the text (or whatever, thanks to this extension point) the detail formatter renders to. Neither allows extenders to list existing detail formatters (or logical structures for that matter).

The bottom of the detailPaneFactories extension does have Something Interesting To Say:

    Supplied Implementation:
    The debug platform contributes a detail pane factory providing a default 
    text source viewer detail pane. The default detail pane displays textual
    details of a selected element based on the corresponding debug model 
    presentation's implementation of computeDetail(IValue value, 
    IValueDetailListener listener). 

computeDetail sounds promising. I'll keep ya posted (unless someone else beats me to it... hurray bounties).

Hmm... org.eclipse.jdt.debug.ui.JavaDebugUtils.getPreferenceStore() sounds promising, but I'd still rather not write a plugin for this myself.

Ah... well. Here's the code org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager uses to load them:

    /**
     * Populate the detail formatters map with data from preferences.
     */
    private void populateDetailFormattersMap() {
            String[] detailFormattersList= JavaDebugOptionsManager.parseList(JDIDebugUIPlugin.getDefault().getPreferenceStore().getString(IJDIPreferencesConstants.PREF_DETAIL_FORMATTERS_LIST));
            fDetailFormattersMap= new HashMap(detailFormattersList.length / 3);
            for (int i= 0, length= detailFormattersList.length; i < length;) {
                    String typeName= detailFormattersList[i++];
                    String snippet= detailFormattersList[i++].replace('\u0000', ',');
                    boolean enabled= ! JavaDetailFormattersPreferencePage.DETAIL_FORMATTER_IS_DISABLED.equals(detailFormattersList[i++]);
                    fDetailFormattersMap.put(typeName, new DetailFormatter(typeName, snippet, enabled));
            }
    }

So the string in the preference store is just a bunch of CSVs with type-name,snippet,enabled,type-name... replace \u0000 with , in the snippets, and you're good to go.

That handles the export (hell, you could just dump the preference string whole hog).

Import wouldn't be much harder, though it'd be nice to not overwrite existing types, or given the user the option to do so, perhaps even with a diff of the two snippets in question.

OTOH, I'd really rather not rely on the inner workings of a class in *.internal.*.

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

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

发布评论

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

评论(4

红焚 2024-10-28 23:21:26

来自 Eclipse 3.8 和 4.2 M5 - 新的和值得注意的

详细信息格式化程序现在可以导出为单独的首选项
以前,共享详细信息格式化程序的唯一方法是导出所有工作区设置。

detail formatter export

这将关闭 bug 224815Brian De Alwis他的回答中:
“使详细信息格式化程序可导出”(使用 补丁

From the Eclipse 3.8 and 4.2 M5 - New and Noteworthy:

Detail formatters can now be exported as separate preferences.
Previously the only way to share detail formatters was to export all of your workspace settings.

detail formatter export

This closes the bug 224815 mentioned by Brian De Alwis in his answer:
"Make Detail formatters exportable" (with that patch)

ゃ懵逼小萝莉 2024-10-28 23:21:26

尽管首选项导出向导中没有明确的内容,但导出所有内容也会写入详细格式化程序。只需在输出文件中搜索 /instance/org.eclipse.jdt.debug.ui/org.eclipse.jdt.debug.ui.detail_formatters 并仅共享这些行。

更新:导入器中似乎存在错误,您必须在导入文件之前从每行中删除 /instance/ 前缀。

或者,由于它们存储在工作区元数据中的属性文件中,您可以共享该文件(尽管如果您只是复制文件,您可能会覆盖其他调试设置):
${workspace}\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.debug.ui.prefs

Although there is nothing explicit in the preferences export wizard, exporting everything will also write the detail formatters. Just search in the output file for /instance/org.eclipse.jdt.debug.ui/org.eclipse.jdt.debug.ui.detail_formatters and share only those lines.

Update: There seems to be a bug in the importer, you have to remove the /instance/ prefix from each line before importing the file.

Alternatively, as they are stored in a properties file in the workspace metadata, you can share that (although you'll probably overwrite other debug settings if you just copy the file):
${workspace}\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.debug.ui.prefs

油饼 2024-10-28 23:21:26

使用“宏”可能会解决这个问题。

您必须

  1. 安装一个插件才能让您
    记录宏
  2. 开始记录宏并使用 Eclipse 菜单配置详细信息格式化程序
  3. 保存并保留
    某个共享目录上的宏
  4. 安装该插件并运行宏
    其他开发人员使用的 PC

此类插件之一是: http://sourceforge.net/projects/practicalmacro/reviews/

Using a "macro" might do the trick here.

You will have to

  1. Install a plugin that lets you
    record Macros
  2. Start recording Macro and configure Detail formatters using Eclipse Menus
  3. Save and keep that
    macro on some shared directory
  4. Install that plugin and run macro on
    PCs used by other developers

One such plugin is : http://sourceforge.net/projects/practicalmacro/reviews/

欢烬 2024-10-28 23:21:26

此问题已作为 bug 224815 归档在 Eclipse Bugzilla 中。问题是在配置导入/导出首选项传输时忽略了详细格式化程序。如果被接受,该修复应该会出现在 3.8/4.2 M6 中,预计一月底发布。

This issue was filed in the Eclipse Bugzilla as bug 224815. The problem is that the detail formatters were overlooked when configuring the import/export preference transfers. The fix, providing it's accepted, should be in the 3.8/4.2 M6 due out at the end of January.

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