Java 类com.intellij.openapi.application.WriteAction 实例源码

项目:TS-IJ    文件:TSPluginComponent.java   
@Override
public void projectOpened() {
    try {
        WriteAction.run(new ThrowableRunnable<Throwable>() {
            @Override
            public void run() throws Throwable {
                String ignoredFiles = FileTypeManager.getInstance().getIgnoredFilesList();
                if (ignoredFiles.length() == 0) {
                    ignoredFiles = "*.dso";
                } else {
                    ignoredFiles = ignoredFiles + ";*.dso";
                }
                FileTypeManager.getInstance().setIgnoredFilesList(ignoredFiles);
            }
        });
    } catch (Throwable ignored) {

    }
}
项目:hybris-integration-intellij-idea-plugin    文件:DefaultMavenConfigurator.java   
private void moveMavenModulesToGroup(
    final Project project,
    final List<Module> mavenModules,
    final String[] rootGroup
) {
    AccessToken token = null;
    final ModifiableModuleModel modifiableModuleModel;
    try {
        token = ApplicationManager.getApplication().acquireReadActionLock();
        modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel();

        for (Module module : mavenModules) {
            module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.MAVEN.name());
            final String[] groupPath = modifiableModuleModel.getModuleGroupPath(module);
            modifiableModuleModel.setModuleGroupPath(module, ArrayUtils.addAll(rootGroup, groupPath));
        }
    } finally {
        if (token != null) {
            token.finish();
        }
    }
    ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModuleModel::commit));
}
项目:educational-plugin    文件:PyStudyDirectoryProjectGenerator.java   
private static Sdk addDetectedSdk(@NotNull Sdk sdk, @NotNull Project project) {
  final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
  final String name = sdk.getName();
  VirtualFile sdkHome = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByPath(name));
  sdk = SdkConfigurationUtil.createAndAddSDK(sdkHome.getPath(), PythonSdkType.getInstance());
  if (sdk != null) {
    PythonSdkUpdater.updateOrShowError(sdk, null, project, null);
  }

  model.addSdk(sdk);
  try {
    model.apply();
  }
  catch (ConfigurationException exception) {
    LOG.error("Error adding detected python interpreter " + exception.getMessage());
  }
  return sdk;
}
项目:intellij-ce-playground    文件:ModuleTestCase.java   
protected Module loadModule(@NotNull String modulePath) {
  String normalizedPath = FileUtil.toSystemIndependentName(modulePath);
  LocalFileSystem.getInstance().refreshAndFindFileByPath(normalizedPath);

  ModuleManager moduleManager = ModuleManager.getInstance(myProject);
  Module module;
  AccessToken token = WriteAction.start();
  try {
    module = moduleManager.loadModule(normalizedPath);
  }
  catch (Exception e) {
    LOG.error(e);
    return null;
  }
  finally {
    token.finish();
  }

  myModulesToDispose.add(module);
  return module;
}
项目:intellij-ce-playground    文件:GriffonFramework.java   
@Override
public void updateProjectStructure(@NotNull final Module module) {
  if (!MvcModuleStructureUtil.isEnabledStructureUpdate()) return;

  final VirtualFile root = findAppRoot(module);
  if (root == null) return;

  AccessToken token = WriteAction.start();
  try {
    MvcModuleStructureUtil.updateModuleStructure(module, createProjectStructure(module, false), root);

    if (hasSupport(module)) {
      MvcModuleStructureUtil.updateAuxiliaryPluginsModuleRoots(module, this);
      MvcModuleStructureUtil.updateGlobalPluginModule(module.getProject(), this);
    }
  }
  finally {
    token.finish();
  }

  final Project project = module.getProject();
  ChangeListManager.getInstance(project).addFilesToIgnore(IgnoredBeanFactory.ignoreUnderDirectory(getUserHomeGriffon(), project));
}
项目:intellij-ce-playground    文件:PsiTestCase.java   
@NotNull
protected PsiFile createFile(@NotNull final Module module, @NotNull final VirtualFile vDir, @NotNull final String fileName, @NotNull final String text) throws IOException {
  return new WriteAction<PsiFile>() {
    @Override
    protected void run(@NotNull Result<PsiFile> result) throws Throwable {
      if (!ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(vDir)) {
        addSourceContentToRoots(module, vDir);
      }

      final VirtualFile vFile = vDir.createChildData(vDir, fileName);
      VfsUtil.saveText(vFile, text);
      assertNotNull(vFile);
      final PsiFile file = myPsiManager.findFile(vFile);
      assertNotNull(file);
      result.setResult(file);
    }
  }.execute().getResultObject();
}
项目:intellij-ce-playground    文件:FindJarFix.java   
private void downloadJar(String jarUrl, String jarName) {
  final Project project = myModule.getProject();
  final String dirPath = PropertiesComponent.getInstance(project).getValue("findjar.last.used.dir");
  VirtualFile toSelect = dirPath == null ? null : LocalFileSystem.getInstance().findFileByIoFile(new File(dirPath));
  final VirtualFile file = FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), project, toSelect);
  if (file != null) {
    PropertiesComponent.getInstance(project).setValue("findjar.last.used.dir", file.getPath());
    final DownloadableFileService downloader = DownloadableFileService.getInstance();
    final DownloadableFileDescription description = downloader.createFileDescription(jarUrl, jarName);
    final List<VirtualFile> jars =
      downloader.createDownloader(Arrays.asList(description), jarName)
                .downloadFilesWithProgress(file.getPath(), project, myEditorComponent);
    if (jars != null && jars.size() == 1) {
      AccessToken token = WriteAction.start();
      try {
        OrderEntryFix.addJarToRoots(jars.get(0).getPresentableUrl(), myModule, myRef);
      }
      finally {
        token.finish();
      }
    }
  }
}
项目:intellij-ce-playground    文件:CreateNewLibraryAction.java   
@Nullable
public static Library createLibrary(@Nullable final LibraryType type, @NotNull final JComponent parentComponent,
                                    @NotNull final Project project, @NotNull final LibrariesModifiableModel modifiableModel) {
  final NewLibraryConfiguration configuration = createNewLibraryConfiguration(type, parentComponent, project);
  if (configuration == null) return null;
  final LibraryType<?> libraryType = configuration.getLibraryType();
  final Library library = modifiableModel.createLibrary(
    LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()),
    libraryType != null ? libraryType.getKind() : null);

  final NewLibraryEditor editor = new NewLibraryEditor(libraryType, configuration.getProperties());
  configuration.addRoots(editor);
  final Library.ModifiableModel model = library.getModifiableModel();
  editor.applyTo((LibraryEx.ModifiableModelEx)model);
  AccessToken token = WriteAction.start();
  try {
    model.commit();
  }
  finally {
    token.finish();
  }
  return library;
}
项目:intellij-ce-playground    文件:ArtifactsStructureConfigurable.java   
@Override
public void apply() throws ConfigurationException {
  myPackagingEditorContext.saveEditorSettings();
  checkForEmptyAndDuplicatedNames("Artifact", CommonBundle.getErrorTitle(), ArtifactConfigurableBase.class);
  super.apply();

  myPackagingEditorContext.getManifestFilesInfo().saveManifestFiles();
  final ModifiableArtifactModel modifiableModel = myPackagingEditorContext.getActualModifiableModel();
  if (modifiableModel != null) {
    new WriteAction() {
      @Override
      protected void run(@NotNull final Result result) {
        modifiableModel.commit();
      }
    }.execute();
    myPackagingEditorContext.resetModifiableModel();
  }


  reset(); // TODO: fix to not reset on apply!
}
项目:intellij-ce-playground    文件:AddFrameworkSupportDialog.java   
protected void doOKAction() {
  if (myAddSupportPanel.hasSelectedFrameworks()) {
    if (!myAddSupportPanel.downloadLibraries()) {
      int answer = Messages.showYesNoDialog(myAddSupportPanel.getMainPanel(),
                                            ProjectBundle.message("warning.message.some.required.libraries.wasn.t.downloaded"),
                                            CommonBundle.getWarningTitle(), Messages.getWarningIcon());
      if (answer != Messages.YES) {
        return;
      }
    }

    DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, new Runnable() {
      @Override
      public void run() {
        new WriteAction() {
          protected void run(@NotNull final Result result) {
            ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
            myAddSupportPanel.addSupport(myModule, model);
            model.commit();
          }
        }.execute();
      }
    });
  }
  super.doOKAction();
}
项目:intellij-ce-playground    文件:PackagingElementsTestCase.java   
static Library addProjectLibrary(final Project project, final @Nullable Module module, final String name, final DependencyScope scope,
                                 final VirtualFile[] jars) {
  return new WriteAction<Library>() {
    @Override
    protected void run(@NotNull final Result<Library> result) {
      final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(project).createLibrary(name);
      final Library.ModifiableModel libraryModel = library.getModifiableModel();
      for (VirtualFile jar : jars) {
        libraryModel.addRoot(jar, OrderRootType.CLASSES);
      }
      libraryModel.commit();
      if (module != null) {
        ModuleRootModificationUtil.addDependency(module, library, scope, false);
      }
      result.setResult(library);
    }
  }.execute().getResultObject();
}
项目:intellij-ce-playground    文件:BaseCompilerTestCase.java   
protected void copyToProject(String relativePath) {
  File dir = PathManagerEx.findFileUnderProjectHome(relativePath, getClass());
  final File target = new File(FileUtil.toSystemDependentName(getProjectBasePath()));
  try {
    FileUtil.copyDir(dir, target);
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
  new WriteAction() {
    @Override
    protected void run(@NotNull final Result result) {
      VirtualFile virtualDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(target);
      assertNotNull(target.getAbsolutePath() + " not found", virtualDir);
      virtualDir.refresh(false, true);
    }
  }.execute();
}
项目:intellij-ce-playground    文件:BaseCompilerTestCase.java   
protected Module addModule(final String moduleName, final @Nullable VirtualFile sourceRoot, final @Nullable 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();
}
项目:intellij-ce-playground    文件:BaseCompilerTestCase.java   
@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();
}
项目:intellij-ce-playground    文件:LibraryTableBase.java   
@Override
public void loadState(final Element element) {
  try {
    if (myFirstLoad) {
      myModel.readExternal(element);
    }
    else {
      LibraryModel model = new LibraryModel(myModel);
      AccessToken token = WriteAction.start();
      try {
        model.readExternal(element);
        commit(model);
      }
      finally {
        token.finish();
      }
    }

    myFirstLoad = false;
  }
  catch (InvalidDataException e) {
    throw new RuntimeException(e);
  }
}
项目:intellij-ce-playground    文件:ExternalSystemTestCase.java   
protected VirtualFile createConfigFile(final VirtualFile dir, String config) throws IOException {
  final String configFileName = getExternalSystemConfigFileName();
  VirtualFile f = dir.findChild(configFileName);
  if (f == null) {
    f = new WriteAction<VirtualFile>() {
      @Override
      protected void run(@NotNull Result<VirtualFile> result) throws Throwable {
        VirtualFile res = dir.createChildData(null, configFileName);
        result.setResult(res);
      }
    }.execute().getResultObject();
    myAllConfigs.add(f);
  }
  setFileContent(f, config, true);
  return f;
}
项目:intellij-ce-playground    文件:AbstractAttachSourceProvider.java   
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  ActionCallback callback = new ActionCallback();
  callback.setDone();

  if (!mySrcFile.isValid()) return callback;

  if (myLibrary != getLibraryFromOrderEntriesList(orderEntriesContainingFile)) return callback;

  AccessToken accessToken = WriteAction.start();
  try {
    addSourceFile(mySrcFile, myLibrary);
  }
  finally {
    accessToken.finish();
  }

  return callback;
}
项目:intellij-ce-playground    文件:ResourceFilteringTest.java   
public void testDoNotFilterButCopyBigFiles() throws Exception {
  assertEquals(FileTypeManager.getInstance().getFileTypeByFileName("file.xyz"), FileTypes.UNKNOWN);

  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      createProjectSubFile("resources/file.xyz").setBinaryContent(new byte[1024 * 1024 * 20]);
    }
  }.execute().throwException();

  importProject("<groupId>test</groupId>" +
                "<artifactId>project</artifactId>" +
                "<version>1</version>" +

                "<build>" +
                "  <resources>" +
                "    <resource>" +
                "      <directory>resources</directory>" +
                "      <filtering>true</filtering>" +
                "    </resource>" +
                "  </resources>" +
                "</build>");
  compileModules("project");

  assertNotNull(myProjectPom.getParent().findFileByRelativePath("target/classes/file.xyz"));
}
项目:intellij-ce-playground    文件:PlatformTestCase.java   
protected static Module doCreateRealModuleIn(String moduleName, final Project project, final ModuleType moduleType) {
  final VirtualFile baseDir = project.getBaseDir();
  assertNotNull(baseDir);
  final File moduleFile = new File(FileUtil.toSystemDependentName(baseDir.getPath()), moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
  FileUtil.createIfDoesntExist(moduleFile);
  myFilesToDelete.add(moduleFile);
  return new WriteAction<Module>() {
    @Override
    protected void run(@NotNull Result<Module> result) throws Throwable {
      VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
      assertNotNull(virtualFile);
      Module module = ModuleManager.getInstance(project).newModule(virtualFile.getPath(), moduleType.getId());
      module.getModuleFile();
      result.setResult(module);
    }
  }.execute().getResultObject();
}
项目:intellij-ce-playground    文件:TestFileStructure.java   
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();
}
项目:intellij-ce-playground    文件:NonProjectFileAccessTest.java   
public void testClearingInfoForDeletedFiles() throws Exception {
  final VirtualFile nonProjectFile1 = createNonProjectFile();
  final VirtualFile nonProjectFile2 = createNonProjectFile();

  typeAndCheck(nonProjectFile1, false);
  typeAndCheck(nonProjectFile2, false);

  assertNotNull(NonProjectFileWritingAccessProvider.getAccessStatus(getProject(), nonProjectFile1));
  assertNotNull(NonProjectFileWritingAccessProvider.getAccessStatus(getProject(), nonProjectFile2));

  new WriteAction<Object>() {
    @Override
    protected void run(@NotNull Result<Object> result) throws Throwable {
      nonProjectFile1.delete(this);
    }
  }.execute();

  assertNull(NonProjectFileWritingAccessProvider.getAccessStatus(getProject(), nonProjectFile1));
  assertNotNull(NonProjectFileWritingAccessProvider.getAccessStatus(getProject(), nonProjectFile2));
}
项目:intellij-ce-playground    文件:LocalFileSystemTest.java   
public void testCaseInsensitiveRename() throws IOException {
  File file = createTempFile("file.txt", "");
  File home = file.getParentFile();
  assertOrderedEquals(Collections.singletonList("file.txt"), home.list());

  final VirtualFile vFile = myFS.refreshAndFindFileByIoFile(file);
  assertNotNull(vFile);
  new WriteAction<Void>() {
    @Override
    protected void run(@NotNull Result<Void> result) throws Throwable {
      vFile.rename(LocalFileSystemTest.class, "FILE.txt");
    }
  }.execute();
  assertEquals("FILE.txt", vFile.getName());
  assertOrderedEquals(Collections.singletonList("FILE.txt"), home.list());
}
项目:intellij-ce-playground    文件:LocalFileSystemTest.java   
public void testInvalidFileName() {
  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      VirtualFile tempDir = myFS.refreshAndFindFileByIoFile(createTempDirectory());
      assertNotNull(tempDir);
      try {
        tempDir.createChildData(this, "a/b");
        fail("invalid file name should have been rejected");
      }
      catch (IOException e) {
        assertEquals(VfsBundle.message("file.invalid.name.error", "a/b"), e.getMessage());
      }
    }
  }.execute();
}
项目:intellij-ce-playground    文件:LocalFileSystemTest.java   
public void testDuplicateViaRename() {
  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      VirtualFile tempDir = myFS.refreshAndFindFileByIoFile(createTempDirectory());
      assertNotNull(tempDir);

      VirtualFile file1 = tempDir.createChildData(this, "a.txt");
      FileUtil.delete(VfsUtilCore.virtualToIoFile(file1));

      VirtualFile file2 = tempDir.createChildData(this, "b.txt");
      try {
        file2.rename(this, "a.txt");
        fail("duplicate file name should have been rejected");
      }
      catch (IOException e) {
        assertEquals(VfsBundle.message("vfs.target.already.exists.error", file1.getPath()), e.getMessage());
      }
    }
  }.execute();
}
项目:intellij-ce-playground    文件:InvalidProjectImportingTest.java   
public void testUnknownProblemWithEmptyFile() throws Exception {
  createProjectPom("");
  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      myProjectPom.setBinaryContent(new byte[0]);
    }
  }.execute().throwException();

  importProject();

  assertModules("project");

  MavenProject root = getRootProjects().get(0);
  assertProblems(root, "'pom.xml' has syntax errors");
}
项目:intellij-ce-playground    文件:MavenExecutionTest.java   
public void testExternalExecutor() throws Exception {
  if (!hasMavenInstallation()) return;

  VfsUtil.saveText(createProjectSubFile("src/main/java/A.java"), "public class A {}");
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  new WriteAction<Object>() {
    @Override
    protected void run(@NotNull Result<Object> objectResult) throws Throwable {
      createProjectPom("<groupId>test</groupId>" +
                       "<artifactId>project</artifactId>" +
                       "<version>1</version>");
    }
  }.execute();

  assertFalse(new File(getProjectPath(), "target").exists());

  execute(new MavenRunnerParameters(true, getProjectPath(), Arrays.asList("compile"), Collections.<String>emptyList()));

  assertTrue(new File(getProjectPath(), "target").exists());
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTreeChangesUpdatesTest.java   
public void testMoveFile() throws Exception {
  new WriteAction<Object>() {
    @Override
    protected void run(@NotNull Result<Object> result) throws Throwable {
      final VirtualFile dir1 = getProject().getBaseDir().createChildDirectory(this, "dir1");
      final VirtualFile dir2 = getProject().getBaseDir().createChildDirectory(this, "dir2");
      VirtualFile child = dir1.createChildData(this, "child");

      long outOfCodeBlockCount = myTracker.getOutOfCodeBlockModificationCount();
      child.move(this, dir2);
      assertFalse(myTracker.getOutOfCodeBlockModificationCount() == outOfCodeBlockCount);

      outOfCodeBlockCount = myTracker.getOutOfCodeBlockModificationCount();
      child.move(this, dir1);
      assertFalse(myTracker.getOutOfCodeBlockModificationCount() == outOfCodeBlockCount);
    }
  }.execute();
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTreeChangesUpdatesTest.java   
public void testMoveDir() throws Exception {
  new WriteAction<Object>() {
    @Override
    protected void run(@NotNull Result<Object> result) throws Throwable {
      final VirtualFile dir1 = getProject().getBaseDir().createChildDirectory(this, "dir1");
      final VirtualFile dir2 = getProject().getBaseDir().createChildDirectory(this, "dir2");
      VirtualFile child = dir1.createChildDirectory(this, "child");

      long outOfCodeBlockCount = myTracker.getOutOfCodeBlockModificationCount();
      child.move(this, dir2);
      assertFalse(myTracker.getOutOfCodeBlockModificationCount() == outOfCodeBlockCount);

      outOfCodeBlockCount = myTracker.getOutOfCodeBlockModificationCount();
      child.move(this, dir1);
      assertFalse(myTracker.getOutOfCodeBlockModificationCount() == outOfCodeBlockCount);
    }
  }.execute();
}
项目:intellij-ce-playground    文件:XDebuggerTestUtil.java   
public static <T extends XBreakpointType> XBreakpoint addBreakpoint(@NotNull final Project project,
                                                                    @NotNull final Class<T> exceptionType,
                                                                    @NotNull final XBreakpointProperties properties) {
  final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
  XBreakpointType[] types = XBreakpointUtil.getBreakpointTypes();
  final Ref<XBreakpoint> breakpoint = Ref.create(null);
  for (XBreakpointType type : types) {
    if (exceptionType.isInstance(type)) {
      final T breakpointType = exceptionType.cast(type);
      new WriteAction() {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
          breakpoint.set(breakpointManager.addBreakpoint(breakpointType, properties));
        }
      }.execute();
      break;
    }
  }
  return breakpoint.get();
}
项目:intellij-ce-playground    文件:XDebuggerTestUtil.java   
public static void setBreakpointCondition(Project project, int line, final String condition) {
  XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
  for (XBreakpoint breakpoint : getBreakpoints(breakpointManager)) {
    if (breakpoint instanceof XLineBreakpoint) {
      final XLineBreakpoint lineBreakpoint = (XLineBreakpoint)breakpoint;

      if (lineBreakpoint.getLine() == line) {
        new WriteAction() {
          @Override
          protected void run(@NotNull Result result) throws Throwable {
            lineBreakpoint.setCondition(condition);
          }
        }.execute();
      }
    }
  }
}
项目:intellij-ce-playground    文件:XDebuggerTestUtil.java   
public static void setBreakpointLogExpression(Project project, int line, final String logExpression) {
  XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
  for (XBreakpoint breakpoint : getBreakpoints(breakpointManager)) {
    if (breakpoint instanceof XLineBreakpoint) {
      final XLineBreakpoint lineBreakpoint = (XLineBreakpoint)breakpoint;

      if (lineBreakpoint.getLine() == line) {
        new WriteAction() {
          @Override
          protected void run(@NotNull Result result) throws Throwable {
            lineBreakpoint.setLogExpression(logExpression);
            lineBreakpoint.setLogMessage(true);
          }
        }.execute();
      }
    }
  }
}
项目:intellij-ce-playground    文件:PsiAwareTextEditorProvider.java   
@Override
protected void setStateImpl(final Project project, final Editor editor, final TextEditorState state) {
  super.setStateImpl(project, editor, state);
  // Folding
  final CodeFoldingState foldState = state.getFoldingState();
  if (project != null && foldState != null) {
    new WriteAction() {
      @Override
      protected void run(@NotNull Result result) throws Throwable {
        PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
        editor.getFoldingModel().runBatchFoldingOperation(
          new Runnable() {
            @Override
            public void run() {
              CodeFoldingManager.getInstance(project).restoreFoldingState(editor, foldState);
            }
          }
        );
      }
    }.execute();
  }
}
项目:intellij-ce-playground    文件:ImportModuleFromImlFileAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
  final Project project = getEventProject(e);
  if (files == null || project == null) return;

  try {
    final ModifiableModuleModel model = ModuleManager.getInstance(project).getModifiableModel();
    for (VirtualFile file : files) {
      model.loadModule(file.getPath());
    }

    AccessToken token = WriteAction.start();
    try {
      model.commit();
    }
    finally {
      token.finish();
    }
  }
  catch (Exception ex) {
    LOG.info(ex);
    Messages.showErrorDialog(project, "Cannot import module: " + ex.getMessage(), CommonBundle.getErrorTitle());
  }
}
项目:intellij-ce-playground    文件:HighlightingTestBase.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  final IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();

  myTestFixture = createFixture(factory);

  myTestFixture.setTestDataPath(getTestDataBasePath() + getTestDataPath());

  Class<? extends LocalInspectionTool>[] inspectionClasses = new DefaultInspectionProvider().getInspectionClasses();
  if (getName().contains("Inspection")) {
    inspectionClasses = ArrayUtil.mergeArrays(inspectionClasses, ApplicationLoader.getInspectionClasses());
  }

  myTestFixture.setUp();

  myTestFixture.enableInspections(inspectionClasses);

  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      ResourceUtil.copyFiles(HighlightingTestBase.this);
      init();
    }
  }.execute().throwException();
}
项目:intellij-ce-playground    文件:GradleImportingTestCase.java   
@Override
public void setUp() throws Exception {
  myJdkHome = IdeaTestUtil.requireRealJdkHome();
  super.setUp();
  assumeThat(gradleVersion, versionMatcherRule.getMatcher());
  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
      if (oldJdk != null) {
        ProjectJdkTable.getInstance().removeJdk(oldJdk);
      }
      VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
      Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
      assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
      ProjectJdkTable.getInstance().addJdk(jdk);
    }
  }.execute();
  myProjectSettings = new GradleProjectSettings();
  GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx64m -XX:MaxPermSize=64m");
  System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
  configureWrapper();
}
项目:intellij-ce-playground    文件:GradleImportingTestCase.java   
@Override
public void tearDown() throws Exception {
  if (myJdkHome == null) {
    //super.setUp() wasn't called
    return;
  }

  try {
    new WriteAction() {
      @Override
      protected void run(@NotNull Result result) throws Throwable {
        Sdk old = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
        if (old != null) {
          SdkConfigurationUtil.removeSdk(old);
        }
      }
    }.execute();
    Messages.setTestDialog(TestDialog.DEFAULT);
    FileUtil.delete(BuildManager.getInstance().getBuildSystemDirectory());
  }
  finally {
    super.tearDown();
  }
}
项目:intellij-ce-playground    文件:AppEngineSupportProvider.java   
private static Library addProjectLibrary(final Module module, final String name, final List<String> jarDirectories, final VirtualFile[] sources) {
  return new WriteAction<Library>() {
    protected void run(@NotNull final Result<Library> result) {
      final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(module.getProject());
      Library library = libraryTable.getLibraryByName(name);
      if (library == null) {
        library = libraryTable.createLibrary(name);
        final Library.ModifiableModel model = library.getModifiableModel();
        for (String path : jarDirectories) {
          String url = VfsUtilCore.pathToUrl(path);
          VirtualFileManager.getInstance().refreshAndFindFileByUrl(url);
          model.addJarDirectory(url, false);
        }
        for (VirtualFile sourceRoot : sources) {
          model.addRoot(sourceRoot, OrderRootType.SOURCES);
        }
        model.commit();
      }
      result.setResult(library);
    }
  }.execute().getResultObject();
}
项目:intellij-ce-playground    文件:EclipseEmlTest.java   
private static Module doLoadModule(@NotNull String path, @NotNull Project project) throws IOException, JDOMException, InvalidDataException {
  Module module;
  AccessToken token = WriteAction.start();
  try {
    module = ModuleManager.getInstance(project).newModule(path + '/' + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA.getId());
  }
  finally {
    token.finish();
  }

  replaceRoot(path, EclipseXml.DOT_CLASSPATH_EXT, project);

  ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
  new EclipseClasspathConverter(module).readClasspath(rootModel);
  token = WriteAction.start();
  try {
    rootModel.commit();
  }
  finally {
    token.finish();
  }
  return module;
}
项目:intellij-ce-playground    文件:EclipseClasspathStorageProvider.java   
@Override
public void moduleRenamed(@NotNull Module module, @NotNull String oldName, @NotNull String newName) {
  try {
    CachedXmlDocumentSet fileSet = getFileCache(module);
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(ModuleUtilCore.getModuleDirPath(module));
    VirtualFile source = root == null ? null : root.findChild(oldName + EclipseXml.IDEA_SETTINGS_POSTFIX);
    if (source != null && source.isValid()) {
      AccessToken token = WriteAction.start();
      try {
        source.rename(this, newName + EclipseXml.IDEA_SETTINGS_POSTFIX);
      }
      finally {
        token.finish();
      }
    }

    DotProjectFileHelper.saveDotProjectFile(module, fileSet.getParent(EclipseXml.PROJECT_FILE));
    fileSet.unregister(oldName + EclipseXml.IDEA_SETTINGS_POSTFIX);
    fileSet.register(newName + EclipseXml.IDEA_SETTINGS_POSTFIX, ModuleUtilCore.getModuleDirPath(module));
  }
  catch (IOException e) {
    EclipseClasspathWriter.LOG.warn(e);
  }
}
项目:intellij-ce-playground    文件:CompilerTester.java   
public void setFileText(final PsiFile file, final String text) throws IOException {
  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      final VirtualFile virtualFile = file.getVirtualFile();
      VfsUtil.saveText(ObjectUtils.assertNotNull(virtualFile), text);
    }
  }.execute().throwException();
  touch(file.getVirtualFile());
}