Search in sources :

Example 21 with VirtualFilePointer

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

the class JpsLibraryDelegate method isValid.

@Override
public boolean isValid(@NotNull String url, @NotNull OrderRootType rootType) {
    final VirtualFilePointerContainer container = myRoots.get(rootType);
    if (container == null)
        return false;
    final VirtualFilePointer fp = container.findByUrl(url);
    return fp != null && fp.isValid();
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer)

Example 22 with VirtualFilePointer

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

the class JpsLibraryDelegate method getFiles.

@NotNull
@Override
public VirtualFile[] getFiles(@NotNull OrderRootType rootType) {
    final VirtualFilePointerContainer container = myRoots.get(rootType);
    if (container == null)
        return VirtualFile.EMPTY_ARRAY;
    final List<VirtualFile> expanded = new ArrayList<>();
    for (JpsLibraryRoot root : myJpsLibrary.getRoots(getJpsRootType(rootType))) {
        final VirtualFilePointer pointer = container.findByUrl(root.getUrl());
        if (pointer == null)
            continue;
        VirtualFile file = pointer.getFile();
        if (file == null)
            continue;
        if (file.isDirectory() && root.getInclusionOptions() != JpsLibraryRoot.InclusionOptions.ROOT_ITSELF) {
            LibraryImpl.collectJarFiles(file, expanded, root.getInclusionOptions() == JpsLibraryRoot.InclusionOptions.ARCHIVES_UNDER_ROOT_RECURSIVELY);
            continue;
        }
        expanded.add(file);
    }
    return VfsUtilCore.toVirtualFileArray(expanded);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) VirtualFilePointerContainer(com.intellij.openapi.vfs.pointers.VirtualFilePointerContainer) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with VirtualFilePointer

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

the class LibraryImpl method getInvalidRootUrls.

@Override
public List<String> getInvalidRootUrls(OrderRootType type) {
    if (myDisposed)
        return Collections.emptyList();
    final List<VirtualFilePointer> pointers = myRoots.get(type).getList();
    List<String> invalidPaths = null;
    for (VirtualFilePointer pointer : pointers) {
        if (!pointer.isValid()) {
            if (invalidPaths == null) {
                invalidPaths = new SmartList<>();
            }
            invalidPaths.add(pointer.getUrl());
        }
    }
    return ContainerUtil.notNullize(invalidPaths);
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 24 with VirtualFilePointer

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

the class FileOrDirectoryTreeNode method setUserObject.

@Override
public void setUserObject(final Object userObject) {
    final Object oldObject = getUserObject();
    try {
        super.setUserObject(userObject);
    } finally {
        if (oldObject instanceof VirtualFilePointer) {
            VirtualFilePointer pointer = (VirtualFilePointer) oldObject;
            Disposer.dispose((Disposable) pointer);
        }
    }
}
Also used : VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 25 with VirtualFilePointer

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

the class VirtualFilePointerManagerImpl method after.

@Override
public void after(@NotNull final List<? extends VFileEvent> events) {
    incModificationCount();
    for (FilePointerPartNode node : myNodesToUpdateUrl) {
        synchronized (this) {
            String urlBefore = node.myFileAndUrl.second;
            Pair<VirtualFile, String> after = node.update();
            assert after != null : "can't invalidate inside modification";
            String urlAfter = after.second;
            if (URL_COMPARATOR.compare(urlBefore, urlAfter) != 0 || !urlAfter.endsWith(node.part)) {
                List<VirtualFilePointerImpl> myPointers = new SmartList<>();
                node.addAllPointersTo(myPointers);
                // url has changed, reinsert
                int useCount = node.useCount;
                FilePointerPartNode root = node.remove();
                FilePointerPartNode newNode = root.findPointerOrCreate(VfsUtilCore.urlToPath(urlAfter), 0, after, myPointers.size());
                VirtualFilePointer existingPointer = newNode.getAnyPointer();
                if (existingPointer != null) {
                    // merge two pointers
                    for (FilePointerPartNode n = newNode; n != null; n = n.parent) {
                        n.pointersUnder += myPointers.size();
                    }
                }
                newNode.addAllPointersTo(myPointers);
                VirtualFilePointerImpl[] newMyPointers = myPointers.toArray(new VirtualFilePointerImpl[myPointers.size()]);
                newNode.associate(newMyPointers, after);
                newNode.incrementUsageCount(useCount);
            }
        }
    }
    VirtualFilePointer[] pointersToFireArray = toPointers(myNodesToFire);
    for (VirtualFilePointer pointer : pointersToFireArray) {
        ((VirtualFilePointerImpl) pointer).myNode.update();
    }
    for (EventDescriptor event : myEvents) {
        event.fireAfter();
    }
    if (pointersToFireArray.length != 0) {
        myBus.syncPublisher(VirtualFilePointerListener.TOPIC).validityChanged(pointersToFireArray);
    }
    myNodesToUpdateUrl = Collections.emptyList();
    myEvents = Collections.emptyList();
    myNodesToFire = Collections.emptyList();
    assertConsistency();
}
Also used : SmartList(com.intellij.util.SmartList) 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