Search in sources :

Example 1 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class NoNamespaceConfigImpl method setMapping.

@Override
public void setMapping(@NotNull PsiFile file, String location) {
    final VirtualFile virtualFile = file.getVirtualFile();
    assert virtualFile != null;
    final String url = virtualFile.getUrl();
    final VirtualFilePointerManager manager = VirtualFilePointerManager.getInstance();
    for (VirtualFilePointer pointer : myMappings.keySet()) {
        if (url.equals(pointer.getUrl())) {
            if (location == null) {
                myMappings.remove(pointer);
                return;
            } else if (!location.equals(myMappings.get(pointer).getUrl())) {
                myMappings.remove(pointer);
                myMappings.put(pointer, manager.create(location, myProject, null));
                return;
            }
        }
    }
    if (location != null) {
        myMappings.put(manager.create(url, myProject, null), manager.create(location, myProject, null));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFilePointerManager(com.intellij.openapi.vfs.pointers.VirtualFilePointerManager) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 2 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class NoNamespaceConfigImpl method getMappedPointer.

private VirtualFilePointer getMappedPointer(@NotNull PsiFile file) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return null;
    final String url = virtualFile.getUrl();
    for (VirtualFilePointer pointer : myMappings.keySet()) {
        if (url.equals(pointer.getUrl())) {
            return myMappings.get(pointer);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 3 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class FileAssociationsManagerImpl method removeAssociations.

public void removeAssociations(PsiFile file) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return;
    for (VirtualFilePointer pointer : myAssociations.keySet()) {
        if (pointer.getUrl().equals(virtualFile.getUrl())) {
            myAssociations.remove(pointer);
            touch();
            return;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 4 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class FileAssociationsManagerImpl method getAssociationsFor.

public PsiFile[] getAssociationsFor(PsiFile file, FileType... fileTypes) {
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return PsiFile.EMPTY_ARRAY;
    for (VirtualFilePointer pointer : myAssociations.keySet()) {
        if (pointer.isValid() && pointer.getUrl().equals(virtualFile.getUrl())) {
            final VirtualFilePointerContainer container = myAssociations.get(pointer);
            if (container != null) {
                final VirtualFile[] files = container.getFiles();
                final Set<PsiFile> list = new HashSet<>();
                final PsiManager psiManager = PsiManager.getInstance(myProject);
                for (VirtualFile assoc : files) {
                    final PsiFile psiFile = psiManager.findFile(assoc);
                    if (psiFile != null && (fileTypes.length == 0 || matchesFileType(psiFile, fileTypes))) {
                        list.add(psiFile);
                    }
                }
                return PsiUtilCore.toPsiFileArray(list);
            } else {
                return PsiFile.EMPTY_ARRAY;
            }
        }
    }
    return PsiFile.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)

Example 5 with VirtualFilePointer

use of com.intellij.openapi.vfs.pointers.VirtualFilePointer in project intellij-community by JetBrains.

the class FileAssociationsManagerImpl method getAssociations.

public Map<VirtualFile, VirtualFile[]> getAssociations() {
    final HashMap<VirtualFile, VirtualFile[]> map = new LinkedHashMap<>();
    final Set<VirtualFilePointer> set = myAssociations.keySet();
    for (VirtualFilePointer pointer : set) {
        if (pointer.isValid()) {
            final VirtualFile file = pointer.getFile();
            map.put(file, myAssociations.get(pointer).getFiles());
        }
    }
    return map;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Aggregations

VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)66 MockVirtualFile (com.intellij.mock.MockVirtualFile)23 File (java.io.File)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 NotNull (org.jetbrains.annotations.NotNull)12 VirtualFilePointerContainer (com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)11 IOException (java.io.IOException)8 Disposable (com.intellij.openapi.Disposable)7 VirtualFilePointerListener (com.intellij.openapi.vfs.pointers.VirtualFilePointerListener)6 ArrayList (java.util.ArrayList)5 Element (org.jdom.Element)5 Nullable (org.jetbrains.annotations.Nullable)4 Job (com.intellij.concurrency.Job)3 FileEditorProvider (com.intellij.openapi.fileEditor.FileEditorProvider)3 FileEditorState (com.intellij.openapi.fileEditor.FileEditorState)3 VirtualFilePointerManager (com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)3 JobLauncher (com.intellij.concurrency.JobLauncher)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 PathManagerEx (com.intellij.openapi.application.ex.PathManagerEx)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2