notifications for unknown macros
[fedora-idea.git] / platform / lang-impl / src / com / intellij / openapi / components / impl / stores / ProjectWithModulesStoreImpl.java
blob4aa23cb1e6c4fbddd38f392d286b69492e226cb9
1 package com.intellij.openapi.components.impl.stores;
3 import com.intellij.openapi.components.StateStorage;
4 import com.intellij.openapi.module.Module;
5 import com.intellij.openapi.module.ModuleManager;
6 import com.intellij.openapi.module.impl.ModuleImpl;
7 import com.intellij.openapi.project.ex.ProjectEx;
8 import com.intellij.openapi.util.Pair;
9 import com.intellij.openapi.vfs.VirtualFile;
10 import com.intellij.util.io.fs.IFile;
11 import org.jetbrains.annotations.Nullable;
13 import java.io.IOException;
14 import java.util.*;
16 /**
17 * @author yole
19 public class ProjectWithModulesStoreImpl extends ProjectStoreImpl {
20 public ProjectWithModulesStoreImpl(final ProjectEx project) {
21 super(project);
24 public void reinitComponents(final Set<String> componentNames, final boolean reloadData) {
25 super.reinitComponents(componentNames, reloadData);
27 for (Module module : getPersistentModules()) {
28 ((ModuleImpl)module).getStateStore().reinitComponents(componentNames, reloadData);
32 public boolean isReloadPossible(final Set<String> componentNames) {
33 if (!super.isReloadPossible(componentNames)) return false;
35 for (Module module : getPersistentModules()) {
36 if (!((ModuleImpl)module).getStateStore().isReloadPossible(componentNames)) return false;
39 return true;
42 protected Module[] getPersistentModules() {
43 ModuleManager moduleManager = ModuleManager.getInstance(myProject);
44 if (moduleManager == null) return Module.EMPTY_ARRAY;
46 return moduleManager.getModules();
49 protected SaveSessionImpl createSaveSession() throws StateStorage.StateStorageException {
50 return new ProjectWithModulesSaveSession();
53 private class ProjectWithModulesSaveSession extends ProjectSaveSession {
54 List<SaveSession> myModuleSaveSessions = new ArrayList<SaveSession>();
56 public ProjectWithModulesSaveSession() throws StateStorage.StateStorageException {
57 try {
58 for (Module module : getPersistentModules()) {
59 myModuleSaveSessions.add(((ModuleImpl)module).getStateStore().startSave());
62 catch (IOException e) {
63 throw new StateStorage.StateStorageException(e.getMessage());
67 public List<IFile> getAllStorageFiles(final boolean includingSubStructures) {
68 final List<IFile> result = super.getAllStorageFiles(includingSubStructures);
70 if (includingSubStructures) {
71 for (SaveSession moduleSaveSession : myModuleSaveSessions) {
72 result.addAll(moduleSaveSession.getAllStorageFiles(true));
76 return result;
79 @Nullable
80 public Set<String> analyzeExternalChanges(final Set<Pair<VirtualFile,StateStorage>> changedFiles) {
81 final Set<String> result = super.analyzeExternalChanges(changedFiles);
82 if (result == null) return null;
84 for (SaveSession moduleSaveSession : myModuleSaveSessions) {
85 final Set<String> s = moduleSaveSession.analyzeExternalChanges(changedFiles);
86 if (s == null) return null;
87 result.addAll(s);
90 return result;
93 public void finishSave() {
94 try {
95 Throwable first = null;
96 for (SaveSession moduleSaveSession : myModuleSaveSessions) {
97 try {
98 moduleSaveSession.finishSave();
100 catch(Throwable e) {
101 if (first == null) first = e;
105 if (first != null) {
106 throw new RuntimeException(first);
109 finally {
110 super.finishSave();
114 public void reset() {
115 try {
116 for (SaveSession moduleSaveSession : myModuleSaveSessions) {
117 moduleSaveSession.reset();
120 finally {
121 super.reset();
125 protected void beforeSave() throws IOException {
126 super.beforeSave();
127 for (SaveSession moduleSaveSession : myModuleSaveSessions) {
128 moduleSaveSession.save();
132 protected void collectSubfilesToSave(final List<IFile> result) throws IOException {
133 for (SaveSession moduleSaveSession : myModuleSaveSessions) {
134 final List<IFile> moduleFiles = moduleSaveSession.getAllStorageFilesToSave(true);
135 result.addAll(moduleFiles);