mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
implementation of getVirtualFileForJar() that doesn't depend on specific VirtualFileSystem classes
This commit is contained in:
@@ -20,7 +20,7 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -662,8 +662,8 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
@Nullable
|
||||
public static VirtualFile getJarFile(PsiElement candidate) {
|
||||
VirtualFile file = candidate.getContainingFile().getVirtualFile();
|
||||
if (file != null && file.getFileSystem() instanceof JarFileSystem) {
|
||||
return JarFileSystem.getInstance().getVirtualFileForJar(file);
|
||||
if (file != null && file.getFileSystem().getProtocol().equals("jar")) {
|
||||
return VfsUtilCore.getVirtualFileForJar(file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -80,4 +80,15 @@ public class VfsUtilCore {
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VirtualFile getVirtualFileForJar(@Nullable VirtualFile entryVFile) {
|
||||
if (entryVFile == null) return null;
|
||||
final String path = entryVFile.getPath();
|
||||
final int separatorIndex = path.indexOf("!/");
|
||||
if (separatorIndex < 0) return null;
|
||||
|
||||
String localPath = path.substring(0, separatorIndex);
|
||||
return VirtualFileManager.getInstance().findFileByUrl("file://" + localPath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user