Search in sources :

Example 6 with VirtualFileSystem

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();
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Collection(java.util.Collection) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) Condition(com.intellij.openapi.util.Condition) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)

Example 7 with VirtualFileSystem

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);
}
Also used : VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with VirtualFileSystem

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) KtFile(org.jetbrains.kotlin.psi.KtFile) PsiFile(com.intellij.psi.PsiFile) Unit(kotlin.Unit) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VirtualFileSystem (com.intellij.openapi.vfs.VirtualFileSystem)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)2 JarFileSystem (com.intellij.openapi.vfs.JarFileSystem)2 PsiFile (com.intellij.psi.PsiFile)2 KtFile (org.jetbrains.kotlin.psi.KtFile)2 MockLocalFileSystem (com.intellij.mock.MockLocalFileSystem)1 ExtensionsArea (com.intellij.openapi.extensions.ExtensionsArea)1 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ProjectJdkTableImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkTableImpl)1 Condition (com.intellij.openapi.util.Condition)1 VirtualFileManagerImpl (com.intellij.openapi.vfs.impl.VirtualFileManagerImpl)1 com.intellij.psi (com.intellij.psi)1 PsiManager (com.intellij.psi.PsiManager)1 FileReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)1 PsiUtilCore (com.intellij.psi.util.PsiUtilCore)1 ProcessingContext (com.intellij.util.ProcessingContext)1 SmartList (com.intellij.util.SmartList)1