Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Eclipse编辑器中将IFile处理程序设置为活动文件_Java_Eclipse_Eclipse Plugin - Fatal编程技术网

Java 如何在Eclipse编辑器中将IFile处理程序设置为活动文件

Java 如何在Eclipse编辑器中将IFile处理程序设置为活动文件,java,eclipse,eclipse-plugin,Java,Eclipse,Eclipse Plugin,我正在准备一个eclipse插件,用于检查测试套件中的代码质量(编译器错误/警告/语法检查由默认编译器完成)。如果测试代码中出现错误,我们想通知测试套件的开发人员,比如GOTO jumps越过标签,它可能会导致无限循环(测试套件非常旧,它们不是java或任何普通语言) 我们希望在特定行和特定消息中报告带有警告的IMarker(我在一些ArrayList中同时得到了行和消息,现在我只需要将它们放在打开的文件中)。但我无法为打开的文件获取IFile处理程序(不是在任何项目中,只是编辑器窗格中的活动选

我正在准备一个eclipse插件,用于检查测试套件中的代码质量(编译器错误/警告/语法检查由默认编译器完成)。如果测试代码中出现错误,我们想通知测试套件的开发人员,比如GOTO jumps越过标签,它可能会导致无限循环(测试套件非常旧,它们不是java或任何普通语言)

我们希望在特定行和特定消息中报告带有警告的IMarker(我在一些ArrayList中同时得到了行和消息,现在我只需要将它们放在打开的文件中)。但我无法为打开的文件获取IFile处理程序(不是在任何项目中,只是编辑器窗格中的活动选项卡)

如何在Eclipse的编辑器窗格中为活动文件获取IFile处理程序

以下代码导致异常:

IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IEditorPart editor = page.getActiveEditor();
IFileEditorInput iFileInput = (IFileEditorInput) editor.getEditorInput(); //exception is here
控制台输出(异常):

java.lang.ClassCastException:org.eclipse.ui.ide.FileStoreEditorInput不能强制转换为org.eclipse.ui.IFileEditorInput
在se.ericsson.ttcnplugin.handlers.AltHandler.execute(AltHandler.java:45)
位于org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
位于org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
位于org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
位于org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
位于org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
位于org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:820)
在org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:806)
位于org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:796)
位于org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
位于org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
位于org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
在org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)上
位于org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
位于org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
位于org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
位于org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
位于org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
位于org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
位于org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
位于org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
在org.eclipse.equinox.internal.app.eclipseeapphandle.run上(eclipseeapphandle.java:196)
位于org.eclipse.core.runtime.internal.adapter.eclipseeappluncher.runApplication(eclipseeappluncher.java:110)
位于org.eclipse.core.runtime.internal.adapter.eclipseeappluncher.start(eclipseeappluncher.java:79)
位于org.eclipse.core.runtime.adapter.EclipseStarter.run(EclipseStarter.java:369)
位于org.eclipse.core.runtime.adapter.EclipseStarter.run(EclipseStarter.java:179)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)中
位于java.lang.reflect.Method.invoke(Method.java:597)
位于org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
位于org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
位于org.eclipse.equinox.launcher.Main.run(Main.java:1408)
位于org.eclipse.equinox.launcher.Main.Main(Main.java:1384)

并非所有编辑器都在实际编辑
如果文件
对象,有些编辑器可能正在编辑不在工作区中的文件。这些编辑器使用的编辑器输入不基于
IFileEditorEditor

在这种情况下,输入是
FileStoreEditorInput
,它实现了
iurieeditorinput
,它只为您提供正在编辑的文件的URI

您可以使用如下代码尝试从编辑器输入获取IFile:

public static IFile getFileFromEditorInput(IEditorInput input)
{
  if (input == null)
    return null;

  if (input instanceof IFileEditorInput)
    return ((IFileEditorInput)input).getFile();

  IPath path = getPathFromEditorInput(input);
  if (path == null)
    return null;

  return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}


public static IPath getPathFromEditorInput(IEditorInput input)
{
  if (input instanceof ILocationProvider)
    return ((ILocationProvider)input).getPath(input);

  if (input instanceof IURIEditorInput)
   {
     URI uri = ((IURIEditorInput)input).getURI();
     if (uri != null)
      {
        IPath path = URIUtil.toPath(uri);
        if (path != null)
          return path;
      }
   }

  return null;
}

如果编辑器未编辑工作区文件,则返回的
IFile
可能为空。

编辑器未从工作区编辑文件,而是通过“文件->打开文件”打开的文件如果它不在工作区中,则没有
IFile
,并且您不能使用标记或类似的东西。这是我不知道我在寻找的答案:)使用IMarker和IFile创建项目帮助,许多thx Greg!!!