谁能告诉我为什么我的 IFile 总是 returns null?
Can Anyone tell me why my IFile always returns null?
我有一个插件。在这个插件中,我有一个创建一些标记的视图,这样我就可以打开文件并自动导航到选定的行。但是,这种方法以前对我有用。它停止到现在?它只有 returns null 作为我的 IFile。
这是我创建标记的方法 注意:此方法不在 FXML 文件的控制 class 中。它位于另一个外部文件中。
public static String openAbsoluteFileInEclipseEditor(String absoluteLocationP, int lineNumberP) {
File absolute = new File(absoluteLocationP);
if(absolute.isFile() && absolute.exists()) {
if(Globals.testing) {
try {
Desktop.getDesktop().open(absolute);
return null;
} catch (IOException e) {
ErrorHandling.reportErrors(e);
return "";
}
}else {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
if(lineNumberP != 0) {
IPath location = Path.fromOSString(absolute.getAbsolutePath());
System.out.println("location " + location);
IFile iFile = workspace.getRoot().getFileForLocation(location);
System.out.println("iFile " + iFile);
IMarker marker = iFile.createMarker(IMarker.TEXT);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumberP);
IDE.openEditor(page, marker);
marker.delete();
}else {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(absolute.toURI());
IDE.openEditorOnFileStore( page, fileStore );
}
return null;
} catch (PartInitException e) {
ErrorHandling.reportErrors(e);
return "";
} catch (CoreException e) {
ErrorHandling.reportErrors(e);
return "";
}
}
}else {
return "File not found";
}
}
这是您可以在方法中间看到的两个打印值。
位置 C:/SoftwareAG_Workspaces/workspace105/HOSPITAL/Natural-Libraries/HOSPITAL/Programs/XX021P01.NSP
iFile 空
谁能告诉我为什么它可能不再有效以及为什么它只返回空值?如果可能的话,您能否建议一种可行的替代方法?该文件确实存在于我确定的那个位置。
提前致谢。
getFileForLocation
的 Javadoc 说:
This method returns null when the given file system location is not
under the location of any existing project in the workspace.
那么该位置是否在当前工作区和有效项目中?
Javadoc 还说:
The result will also omit resources that are explicitly excluded from
the workspace according to existing resource filters.
因此请检查所有资源过滤器。
最后 Javadoc 说:
Warning: This method ignores linked resources and their children.
Since linked resources may overlap other resources, a unique mapping
from a file system location to a single resource is not guaranteed.
To find all resources for a given location, including linked
resources, use the method findFilesForLocation
.
所以检查链接资源
我有一个插件。在这个插件中,我有一个创建一些标记的视图,这样我就可以打开文件并自动导航到选定的行。但是,这种方法以前对我有用。它停止到现在?它只有 returns null 作为我的 IFile。
这是我创建标记的方法 注意:此方法不在 FXML 文件的控制 class 中。它位于另一个外部文件中。
public static String openAbsoluteFileInEclipseEditor(String absoluteLocationP, int lineNumberP) {
File absolute = new File(absoluteLocationP);
if(absolute.isFile() && absolute.exists()) {
if(Globals.testing) {
try {
Desktop.getDesktop().open(absolute);
return null;
} catch (IOException e) {
ErrorHandling.reportErrors(e);
return "";
}
}else {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
if(lineNumberP != 0) {
IPath location = Path.fromOSString(absolute.getAbsolutePath());
System.out.println("location " + location);
IFile iFile = workspace.getRoot().getFileForLocation(location);
System.out.println("iFile " + iFile);
IMarker marker = iFile.createMarker(IMarker.TEXT);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumberP);
IDE.openEditor(page, marker);
marker.delete();
}else {
IFileStore fileStore = EFS.getLocalFileSystem().getStore(absolute.toURI());
IDE.openEditorOnFileStore( page, fileStore );
}
return null;
} catch (PartInitException e) {
ErrorHandling.reportErrors(e);
return "";
} catch (CoreException e) {
ErrorHandling.reportErrors(e);
return "";
}
}
}else {
return "File not found";
}
}
这是您可以在方法中间看到的两个打印值。
位置 C:/SoftwareAG_Workspaces/workspace105/HOSPITAL/Natural-Libraries/HOSPITAL/Programs/XX021P01.NSP iFile 空
谁能告诉我为什么它可能不再有效以及为什么它只返回空值?如果可能的话,您能否建议一种可行的替代方法?该文件确实存在于我确定的那个位置。
提前致谢。
getFileForLocation
的 Javadoc 说:
This method returns null when the given file system location is not under the location of any existing project in the workspace.
那么该位置是否在当前工作区和有效项目中?
Javadoc 还说:
The result will also omit resources that are explicitly excluded from the workspace according to existing resource filters.
因此请检查所有资源过滤器。
最后 Javadoc 说:
Warning: This method ignores linked resources and their children. Since linked resources may overlap other resources, a unique mapping from a file system location to a single resource is not guaranteed. To find all resources for a given location, including linked resources, use the method
findFilesForLocation
.
所以检查链接资源