use of com.intellij.openapi.vfs.VirtualFileSystem in project intellij-community by JetBrains.
the class JavaFxFileReferenceProvider method getReferences.
public static PsiReference[] getReferences(@NotNull PsiElement element, String value, final String acceptedExtension) {
final PsiDirectory directory = element.getContainingFile().getOriginalFile().getParent();
if (directory == null)
return PsiReference.EMPTY_ARRAY;
final boolean startsWithSlash = value.startsWith("/");
final VirtualFileSystem fs = directory.getVirtualFile().getFileSystem();
final FileReferenceSet fileReferenceSet = new FileReferenceSet(value, element, 1, null, fs.isCaseSensitive()) {
@NotNull
@Override
public Collection<PsiFileSystemItem> getDefaultContexts() {
if (startsWithSlash || !directory.isValid()) {
return super.getDefaultContexts();
}
return Collections.singletonList(directory);
}
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return item -> {
if (item instanceof PsiDirectory)
return true;
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(item);
return virtualFile != null && acceptedExtension.equals(virtualFile.getExtension());
};
}
};
if (startsWithSlash) {
fileReferenceSet.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
}
return fileReferenceSet.getAllReferences();
}
use of com.intellij.openapi.vfs.VirtualFileSystem in project intellij-community by JetBrains.
the class LightFilePointer method toPresentableUrl.
@NotNull
private static String toPresentableUrl(@NotNull String url) {
String path = VirtualFileManager.extractPath(url);
String protocol = VirtualFileManager.extractProtocol(url);
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(protocol);
return ObjectUtils.notNull(fileSystem, StandardFileSystems.local()).extractPresentableUrl(path);
}
use of com.intellij.openapi.vfs.VirtualFileSystem in project kotlin by JetBrains.
the class CompileEnvironmentUtil method getKtFiles.
@NotNull
public static List<KtFile> getKtFiles(@NotNull final Project project, @NotNull Collection<String> sourceRoots, @NotNull CompilerConfiguration configuration, @NotNull Function1<String, Unit> reportError) throws IOException {
final VirtualFileSystem localFileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
final Set<VirtualFile> processedFiles = Sets.newHashSet();
final List<KtFile> result = Lists.newArrayList();
for (String sourceRootPath : sourceRoots) {
if (sourceRootPath == null) {
continue;
}
VirtualFile vFile = localFileSystem.findFileByPath(sourceRootPath);
if (vFile == null) {
String message = "Source file or directory not found: " + sourceRootPath;
File moduleFilePath = configuration.get(JVMConfigurationKeys.MODULE_XML_FILE);
if (moduleFilePath != null) {
String moduleFileContent = FileUtil.loadFile(moduleFilePath);
LOG.warn(message + "\n\nmodule file path: " + moduleFilePath + "\ncontent:\n" + moduleFileContent);
}
reportError.invoke(message);
continue;
}
if (!vFile.isDirectory() && vFile.getFileType() != KotlinFileType.INSTANCE) {
reportError.invoke("Source entry is not a Kotlin file: " + sourceRootPath);
continue;
}
SequencesKt.forEach(FilesKt.walkTopDown(new File(sourceRootPath)), new Function1<File, Unit>() {
@Override
public Unit invoke(File file) {
if (file.isFile()) {
VirtualFile virtualFile = localFileSystem.findFileByPath(file.getAbsolutePath());
if (virtualFile != null && !processedFiles.contains(virtualFile)) {
processedFiles.add(virtualFile);
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile instanceof KtFile) {
result.add((KtFile) psiFile);
}
}
}
return Unit.INSTANCE;
}
});
}
return result;
}
Aggregations