eclipse - 从 Eclipse 插件写入标准输出

标签 eclipse eclipse-plugin

我的目标是扩展 eclipse QuickFix 组件并自动化解决语法错误的过程。基本上,QuickFix 组件提供了一个解决方案列表,我的任务是选择最佳的修复并将其应用于有错误的代码。但是,现在我被要求在控制台中打印标记的分辨率。我试图编写一个教程,但现在有点卡住了。我尝试锻炼的教程是:http://www.informit.com/articles/article.aspx?p=370625&seqNum=21 我首先在我的plugin.xml 文件中添加了扩展

<extension point="org.eclipse.ui.ide.markerResolution">
    <markerResolutionGenerator
        markerType="org.eclipse.core.resources.problemmarker"
        class="org.eclipse.escript.quickfix.QuickFixer"/>
</extension>

然后我创建了两个类 QuickFixer 和 QuickFix。

package quickfixer;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IMarkerResolution;
import org.eclipse.ui.IMarkerResolutionGenerator;

class QuickFixer implements IMarkerResolutionGenerator {

    public IMarkerResolution[] getResolutions(IMarker arg0) {
    try {
            Object problem = arg0.getAttribute("Whatsup");
            return new IMarkerResolution[] {
            new QuickFix("Fix #1 for "+problem),
            new QuickFix("Fix #2 for "+problem),
            };
        } catch(CoreException e) {
            return new IMarkerResolution[0];
        }
    }
}

然后是 QuickFix 类:

package quickfixer;

import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IMarkerResolution;

public class QuickFix implements IMarkerResolution {

       String label;
       QuickFix(String label) {
          this.label = label;
       }
       public String getLabel() {
          return label;
       }

    public void run(IMarker arg0) {
        MessageDialog.openInformation(null, "QuickFix Demo",
                     "This quick-fix is not yet implemented");
        System.out.println("Label: " + label);              
    }
}

我已设法纠正遇到的所有错误,然后运行该插件。 我无法在控制台中打印标签。有什么建议吗???...

最佳答案

使用System.out不是一个好主意。检查relevant FAQ为什么?

you should avoid using standard output or standard error in your plug-in

并使用正确的日志记录(或调试器)。

关于eclipse - 从 Eclipse 插件写入标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13342465/

相关文章:

eclipse - Eclipse BuildShip插件中未显示Gradle任务

java - 从列表中获取任何元素

java - 在 ScrolledComposite 中包含两个复合 Material

java - 如何在一个 .properties 文件的末尾添加属性

java - 如何将 Eclipse 插件中现有 View 的上下文弹出菜单重用到新创建的 View ?

editor - 没有 Presentation Reconciler 的语法着色

java - 从 ILaunchConfiguration 对象中获取项目名称

android - 未能从

eclipse - Eclipse可以自动刷新资源吗?

在 Eclipse 中使用 Joda Time 出现 java.lang.NoClassDefFoundError