简体   繁体   English

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

[英]Barring copy & paste, is there a way to share Java detail formatters

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() . 在我们的商店中,我们有5-10个开发人员在Eclipse上使用Java,我们经常调试那些没有调试友好的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. 我们有N个不同的版本控制系统可以在Eclipse中运行......看起来这将是人们想要传递的东西。

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. 我设法跟踪至少一些设置到/workspace/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.dbug.ui.prefs ,但有理由相信它还有更多那。 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. 编辑:我正在使用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 . 除了javaLogicalStructures扩展点(用于向给定类添加逻辑结构)之外,还有一个名为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: 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 sounds promising. computeDetail听起来很有希望。 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. 嗯... org.eclipse.jdt.debug.ui.JavaDebugUtils.getPreferenceStore()听起来很有希望,但我还是宁愿不为此自己编写插件。

Ah... well. 呃,好吧。 Here's the code org.eclipse.jdt.internal.debug.ui.JavaDetailFormattersManager uses to load them: 这是代码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));
            }
    }

So the string in the preference store is just a bunch of CSVs with type-name,snippet,enabled,type-name... replace \ with , in the snippets, and you're good to go. 因此,首选项存储中的字符串只是一堆带有类型名称,代码段,已启用,类型名称...替换\\ u0000的CSV,在代码段中,你很高兴。

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.* . OTOH,我真的宁愿不依赖于*.internal.*的一个类的内部运作*.internal.*

From the Eclipse 3.8 and 4.2 M5 - New and Noteworthy : 来自Eclipse 3.8和4.2 M5 - 新的和值得注意的

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. 以前,共享详细格式化程序的唯一方法是导出所有工作区设置。

详细格式化程序导出

This closes the bug 224815 mentioned by Brian De Alwis in his answer : 这结束了Brian De Alwis他的回答中提到的错误224815
"Make Detail formatters exportable" (with that patch ) “使详细格式化程序可导出”(使用该补丁

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. 只需在输出文件中搜索/instance/org.eclipse.jdt.debug.ui/org.eclipse.jdt.debug.ui.detail_formatters并仅共享这些行。

Update: There seems to be a bug in the importer, you have to remove the /instance/ prefix from each line before importing the file. 更新:导入器中似乎存在错误,您必须在导入文件之前从每行删除/instance/前缀。

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

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 开始录制宏并使用Eclipse Menus配置Detail格式化程序
  3. Save and keep that macro on some shared directory 保存并保留某个共享目录上的宏
  4. Install that plugin and run macro on PCs used by other developers 在其他开发人员使用的PC上安装该插件并运行宏

One such plugin is : http://sourceforge.net/projects/practicalmacro/reviews/ 一个这样的插件是: http//sourceforge.net/projects/practicalmacro/reviews/

This issue was filed in the Eclipse Bugzilla as bug 224815 . 此问题已在Eclipse Bugzilla中作为错误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. 修正案,如果它被接受,应该在1月底到期的3.8 / 4.2 M6中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM