import org.eclipse.jdt.core.dom.ITypeBinding; //导入方法依赖的package包/类
private static IFile getClassfile(ITypeBinding typeBinding) throws CoreException {
// bug 191943
IType type = (IType) typeBinding.getJavaElement();
if (type == null || type.getCompilationUnit() == null || type.getJavaProject() == null || ProjectsManager.DEFAULT_PROJECT_NAME.equals(type.getJavaProject().getProject().getName())) {
return null;
}
IRegion region = JavaCore.newRegion();
region.add(type.getCompilationUnit());
String name = typeBinding.getBinaryName();
if (name != null) {
int packStart = name.lastIndexOf('.');
if (packStart != -1) {
name = name.substring(packStart + 1);
}
} else {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
}
name += ".class"; //$NON-NLS-1$
IResource[] classFiles = JavaCore.getGeneratedResources(region, false);
for (int i = 0; i < classFiles.length; i++) {
IResource resource = classFiles[i];
if (resource.getType() == IResource.FILE && resource.getName().equals(name) && resource.exists()) {
try (InputStream contents = ((IFile) resource).getContents()) {
} catch (Exception e) {
continue;
}
return (IFile) resource;
}
}
return null;
// throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, CorrectionMessages.SerialVersionHashOperation_error_classnotfound));
}