我的目标是扩展 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/