Search in sources :

Example 1 with VirtualFilePointerManager

use of com.intellij.openapi.vfs.pointers.VirtualFilePointerManager 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 VirtualFilePointerManager

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

the class InlineModuleDependencyAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    OrderEntry selectedEntry = myClasspathPanel.getSelectedEntry();
    if (!(selectedEntry instanceof ModuleOrderEntry))
        return;
    ModuleOrderEntry entryToInline = (ModuleOrderEntry) selectedEntry;
    Module module = entryToInline.getModule();
    if (module == null)
        return;
    ModifiableRootModel model = myClasspathPanel.getRootModel();
    int toInlineIndex = findModuleEntryIndex(model, module);
    if (toInlineIndex == -1)
        return;
    model.removeOrderEntry(entryToInline);
    RootModelImpl modelImpl;
    if (Proxy.isProxyClass(model.getClass())) {
        modelImpl = (RootModelImpl) ((ModuleEditor.ProxyDelegateAccessor) Proxy.getInvocationHandler(model)).getDelegate();
    } else {
        modelImpl = (RootModelImpl) model;
    }
    int addedCount = 0;
    ModuleRootModel otherModel = myClasspathPanel.getModuleConfigurationState().getModulesProvider().getRootModel(module);
    ProjectRootManagerImpl rootManager = ProjectRootManagerImpl.getInstanceImpl(myClasspathPanel.getProject());
    VirtualFilePointerManager virtualFilePointerManager = VirtualFilePointerManager.getInstance();
    for (OrderEntry entry : otherModel.getOrderEntries()) {
        if (entry instanceof LibraryOrderEntry || entry instanceof ModuleOrderEntry) {
            LOG.assertTrue(entry instanceof ClonableOrderEntry, entry);
            ExportableOrderEntry entryToCopy = (ExportableOrderEntry) entry;
            ExportableOrderEntry cloned = (ExportableOrderEntry) ((ClonableOrderEntry) entry).cloneEntry(modelImpl, rootManager, virtualFilePointerManager);
            cloned.setExported(entryToInline.isExported() && entryToCopy.isExported());
            cloned.setScope(OrderEntryUtil.intersectScopes(entryToInline.getScope(), entryToCopy.getScope()));
            model.addOrderEntry(cloned);
            addedCount++;
        }
    }
    OrderEntry[] oldEntries = model.getOrderEntries();
    OrderEntry[] newEntries = new OrderEntry[oldEntries.length];
    System.arraycopy(oldEntries, 0, newEntries, 0, toInlineIndex);
    System.arraycopy(oldEntries, oldEntries.length - addedCount, newEntries, toInlineIndex, addedCount);
    System.arraycopy(oldEntries, toInlineIndex, newEntries, toInlineIndex + addedCount, oldEntries.length - toInlineIndex - addedCount);
    model.rearrangeOrderEntries(newEntries);
    StructureConfigurableContext context = ProjectStructureConfigurable.getInstance(myClasspathPanel.getProject()).getContext();
    context.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(context, module));
}
Also used : RootModelImpl(com.intellij.openapi.roots.impl.RootModelImpl) ProjectRootManagerImpl(com.intellij.openapi.roots.impl.ProjectRootManagerImpl) ModuleProjectStructureElement(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement) ClonableOrderEntry(com.intellij.openapi.roots.impl.ClonableOrderEntry) ClonableOrderEntry(com.intellij.openapi.roots.impl.ClonableOrderEntry) VirtualFilePointerManager(com.intellij.openapi.vfs.pointers.VirtualFilePointerManager) StructureConfigurableContext(com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext) Module(com.intellij.openapi.module.Module)

Example 3 with VirtualFilePointerManager

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

the class VirtualFilePointerImpl method dispose.

public void dispose() {
    checkDisposed();
    if (myNode.incrementUsageCount(-1) == 0) {
        kill("URL when die: " + toString());
        VirtualFilePointerManager pointerManager = VirtualFilePointerManager.getInstance();
        if (pointerManager instanceof VirtualFilePointerManagerImpl) {
            // remove from the tree
            ((VirtualFilePointerManagerImpl) pointerManager).removeNode(myNode, myListener);
        }
        myNode = null;
    }
}
Also used : VirtualFilePointerManager(com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)

Example 4 with VirtualFilePointerManager

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

the class NoNamespaceConfigImpl method loadState.

@Override
public void loadState(Mappings state) {
    reset();
    final VirtualFilePointerManager manager = VirtualFilePointerManager.getInstance();
    final Map<String, String> map = state.myMappings;
    for (String file : map.keySet()) {
        myMappings.put(manager.create(file, myProject, null), manager.create(map.get(file), myProject, null));
    }
}
Also used : VirtualFilePointerManager(com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)

Aggregations

VirtualFilePointerManager (com.intellij.openapi.vfs.pointers.VirtualFilePointerManager)4 Module (com.intellij.openapi.module.Module)1 ClonableOrderEntry (com.intellij.openapi.roots.impl.ClonableOrderEntry)1 ProjectRootManagerImpl (com.intellij.openapi.roots.impl.ProjectRootManagerImpl)1 RootModelImpl (com.intellij.openapi.roots.impl.RootModelImpl)1 StructureConfigurableContext (com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext)1 ModuleProjectStructureElement (com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)1