use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class TestFileStructure method createFile.
private PsiFile createFile(final Module module, final VirtualFile vDir, final String fileName, final String text) {
return new WriteAction<PsiFile>() {
@Override
protected void run(@NotNull Result<PsiFile> result) throws Throwable {
if (!ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(vDir)) {
PsiTestUtil.addSourceContentToRoots(module, vDir);
}
final VirtualFile vFile = vDir.createChildData(vDir, fileName);
VfsUtil.saveText(vFile, text);
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
final PsiFile file = PsiManager.getInstance(myProject).findFile(vFile);
assert (file != null);
result.setResult(file);
}
}.execute().getResultObject();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class BaseCompilerTestCase method doCreateRealModule.
@NotNull
@Override
protected Module doCreateRealModule(String moduleName) {
//todo[nik] reuse code from PlatformTestCase
final VirtualFile baseDir = myProject.getBaseDir();
Assert.assertNotNull(baseDir);
final File moduleFile = new File(baseDir.getPath().replace('/', File.separatorChar), moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
PlatformTestCase.myFilesToDelete.add(moduleFile);
return new WriteAction<Module>() {
@Override
protected void run(@NotNull Result<Module> result) throws Throwable {
Module module = ModuleManager.getInstance(myProject).newModule(FileUtil.toSystemIndependentName(moduleFile.getAbsolutePath()), getModuleType().getId());
module.getModuleFile();
result.setResult(module);
}
}.execute().getResultObject();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class BaseCompilerTestCase method addModule.
protected Module addModule(final String moduleName, @Nullable final VirtualFile sourceRoot, @Nullable final VirtualFile testRoot) {
return new WriteAction<Module>() {
@Override
protected void run(@NotNull final Result<Module> result) {
final Module module = createModule(moduleName);
if (sourceRoot != null) {
PsiTestUtil.addSourceContentToRoots(module, sourceRoot, false);
}
if (testRoot != null) {
PsiTestUtil.addSourceContentToRoots(module, testRoot, true);
}
ModuleRootModificationUtil.setModuleSdk(module, getTestProjectJdk());
result.setResult(module);
}
}.execute().getResultObject();
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class IdeaProjectModelModifier method addExternalLibraryDependency.
@Override
public Promise<Void> addExternalLibraryDependency(@NotNull final Collection<Module> modules, @NotNull final ExternalLibraryDescriptor descriptor, @NotNull final DependencyScope scope) {
List<String> defaultRoots = descriptor.getLibraryClassesRoots();
Module firstModule = ContainerUtil.getFirstItem(modules);
LOG.assertTrue(firstModule != null);
LocateLibraryDialog dialog = new LocateLibraryDialog(firstModule, defaultRoots, descriptor.getPresentableName());
List<String> classesRoots = dialog.showAndGetResult();
if (!classesRoots.isEmpty()) {
String libraryName = classesRoots.size() > 1 ? descriptor.getPresentableName() : null;
final List<String> urls = OrderEntryFix.refreshAndConvertToUrls(classesRoots);
if (modules.size() == 1) {
ModuleRootModificationUtil.addModuleLibrary(firstModule, libraryName, urls, Collections.emptyList(), scope);
} else {
new WriteAction() {
protected void run(@NotNull Result result) {
Library library = LibraryUtil.createLibrary(LibraryTablesRegistrar.getInstance().getLibraryTable(myProject), descriptor.getPresentableName());
Library.ModifiableModel model = library.getModifiableModel();
for (String url : urls) {
model.addRoot(url, OrderRootType.CLASSES);
}
model.commit();
for (Module module : modules) {
ModuleRootModificationUtil.addDependency(module, library, scope, false);
}
}
}.execute();
}
}
return Promises.resolvedPromise(null);
}
use of com.intellij.openapi.application.WriteAction in project intellij-community by JetBrains.
the class ArtifactsStructureConfigurableContextImpl method editLayout.
@Override
public void editLayout(@NotNull final Artifact artifact, final Runnable action) {
final Artifact originalArtifact = getOriginalArtifact(artifact);
new WriteAction() {
@Override
protected void run(@NotNull final Result result) {
final ModifiableArtifact modifiableArtifact = getOrCreateModifiableArtifactModel().getOrCreateModifiableArtifact(originalArtifact);
if (modifiableArtifact.getRootElement() == originalArtifact.getRootElement()) {
modifiableArtifact.setRootElement(getOrCreateModifiableRootElement(originalArtifact));
}
action.run();
}
}.execute();
myContext.getDaemonAnalyzer().queueUpdate(getOrCreateArtifactElement(originalArtifact));
}
Aggregations