use of com.intellij.openapi.roots.impl.ProjectRootManagerImpl 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));
}
use of com.intellij.openapi.roots.impl.ProjectRootManagerImpl in project intellij-community by JetBrains.
the class CoreProjectLoader method loadDirectoryProject.
private static void loadDirectoryProject(MockProject project, @NotNull VirtualFile dotIdea) throws IOException, JDOMException {
VirtualFile modulesXml = dotIdea.findChild("modules.xml");
if (modulesXml == null)
throw new FileNotFoundException("Missing 'modules.xml' in " + dotIdea.getPath());
TreeMap<String, Element> storageData = loadStorageFile(project, modulesXml);
final Element moduleManagerState = storageData.get("ProjectModuleManager");
if (moduleManagerState == null) {
throw new JDOMException("cannot find ProjectModuleManager state in modules.xml");
}
final CoreModuleManager moduleManager = (CoreModuleManager) ModuleManager.getInstance(project);
moduleManager.loadState(moduleManagerState);
VirtualFile miscXml = dotIdea.findChild("misc.xml");
if (miscXml != null) {
storageData = loadStorageFile(project, miscXml);
final Element projectRootManagerState = storageData.get("ProjectRootManager");
if (projectRootManagerState == null) {
throw new JDOMException("cannot find ProjectRootManager state in misc.xml");
}
((ProjectRootManagerImpl) ProjectRootManager.getInstance(project)).loadState(projectRootManagerState);
}
VirtualFile libraries = dotIdea.findChild("libraries");
if (libraries != null) {
Map<String, Element> data = DirectoryStorageUtil.loadFrom(libraries, PathMacroManager.getInstance(project));
Element libraryTable = DefaultStateSerializer.deserializeState(DirectoryStorageUtil.getCompositeState(data, new ProjectLibraryTable.LibraryStateSplitter()), Element.class, null);
((LibraryTableBase) ProjectLibraryTable.getInstance(project)).loadState(libraryTable);
}
moduleManager.loadModules();
project.projectOpened();
}
Aggregations