Search in sources :

Example 61 with WriteAction

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 62 with WriteAction

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) WriteAction(com.intellij.openapi.application.WriteAction) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with WriteAction

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();
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result)

Example 64 with WriteAction

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);
}
Also used : LocateLibraryDialog(com.intellij.codeInsight.daemon.impl.quickfix.LocateLibraryDialog) WriteAction(com.intellij.openapi.application.WriteAction) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) Result(com.intellij.openapi.application.Result)

Example 65 with WriteAction

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));
}
Also used : WriteAction(com.intellij.openapi.application.WriteAction) Result(com.intellij.openapi.application.Result)

Aggregations

Result (com.intellij.openapi.application.Result)85 WriteAction (com.intellij.openapi.application.WriteAction)85 NotNull (org.jetbrains.annotations.NotNull)38 VirtualFile (com.intellij.openapi.vfs.VirtualFile)37 File (java.io.File)20 IOException (java.io.IOException)16 Module (com.intellij.openapi.module.Module)10 PsiFile (com.intellij.psi.PsiFile)7 Sdk (com.intellij.openapi.projectRoots.Sdk)5 RunResult (com.intellij.openapi.application.RunResult)4 Document (com.intellij.openapi.editor.Document)4 Project (com.intellij.openapi.project.Project)4 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)4 Library (com.intellij.openapi.roots.libraries.Library)4 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)4 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FacetManager (com.intellij.facet.FacetManager)2 ProjectFacetManager (com.intellij.facet.ProjectFacetManager)2