@Override
  public void actionPerformed(AnActionEvent e) {
    Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    assert project != null;

    ProjectUtil.closeAndDispose(project);
    WelcomeFrame.showIfNoProjectOpened();
  }
  public void testExternalFileModificationWhileProjectClosed() throws Exception {
    VirtualFile root = ProjectRootManager.getInstance(myProject).getContentRoots()[0];

    PsiClass objectClass =
        myJavaFacade.findClass(
            CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
    assertNotNull(objectClass);
    checkUsages(objectClass, new String[] {});
    FileBasedIndex.getInstance()
        .getContainingFiles(
            TodoIndex.NAME,
            new TodoIndexEntry("todo", true),
            GlobalSearchScope.allScope(getProject()));

    final String projectLocation = myProject.getPresentableUrl();
    assert projectLocation != null : myProject;
    PlatformTestUtil.saveProject(myProject);
    final VirtualFile content = ModuleRootManager.getInstance(getModule()).getContentRoots()[0];
    Project project = myProject;
    ProjectUtil.closeAndDispose(project);
    InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project);

    assertTrue("Project was not disposed", myProject.isDisposed());
    myModule = null;

    final File file = new File(root.getPath(), "1.java");
    assertTrue(file.exists());

    FileUtil.writeToFile(file, "class A{ Object o;}".getBytes(CharsetToolkit.UTF8_CHARSET));
    root.refresh(false, true);

    LocalFileSystem.getInstance().refresh(false);

    myProject = ProjectManager.getInstance().loadAndOpenProject(projectLocation);
    InjectedLanguageManagerImpl.pushInjectors(getProject());

    setUpModule();
    setUpJdk();
    ProjectManagerEx.getInstanceEx().openTestProject(myProject);
    UIUtil.dispatchAllInvocationEvents(); // startup activities

    runStartupActivities();
    PsiTestUtil.addSourceContentToRoots(getModule(), content);

    assertNotNull(myProject);
    myPsiManager = (PsiManagerImpl) PsiManager.getInstance(myProject);
    myJavaFacade = JavaPsiFacadeEx.getInstanceEx(myProject);

    objectClass =
        myJavaFacade.findClass(
            CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
    assertNotNull(objectClass);
    checkUsages(objectClass, new String[] {"1.java"});
  }
Exemplo n.º 3
0
  @Override
  protected void doOKAction() {
    super.doOKAction();

    if (myCurrentProject != null) {
      int exitCode =
          Messages.showDialog(
              IdeBundle.message("prompt.open.project.in.new.frame"),
              IdeBundle.message("title.open.project"),
              new String[] {
                IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe")
              },
              1,
              Messages.getQuestionIcon());
      if (exitCode == 1) {
        ProjectUtil.closeAndDispose(myCurrentProject);
      }
    }

    final ProjectOptions myOptions = new ProjectOptions();
    myOptions.setProjectName(myProjectName.getText());
    myOptions.setProjectPath(myProjectPath.getPath());
    myOptions.setCreateNewLanguage(false);
    myOptions.setCreateNewSolution(false);
    myOptions.setStorageScheme(myProjectFormatPanel.isDefault());

    // invoke later is for plugins to be ready
    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                try {
                  ProjectFactory factory = new ProjectFactory(myCurrentProject, myOptions);
                  Project project = factory.createProject();
                  myCurrentTemplateItem
                      .getTemplateFiller()
                      .fillProjectWithModules(project.getComponent(MPSProject.class));
                  factory.activate();
                } catch (ProjectNotCreatedException e) {
                  Messages.showErrorDialog(getContentPane(), e.getMessage());
                }
              }
            });
  }
  public void testDocumentFromAlienProjectDoesNotEndsUpInMyUncommittedList() throws Exception {
    PsiFile file = getPsiManager().findFile(createFile());

    final Document document = getPsiDocumentManager().getDocument(file);

    File temp = createTempDirectory();
    final Project alienProject =
        createProject(new File(temp, "alien.ipr"), DebugUtil.currentStackTrace());
    boolean succ2 = ProjectManagerEx.getInstanceEx().openProject(alienProject);
    assertTrue(succ2);

    try {
      PsiManager alienManager = PsiManager.getInstance(alienProject);
      final String alienText = "alien";

      LightVirtualFile alienVirt = new LightVirtualFile("foo.java", alienText);
      final PsiFile alienFile = alienManager.findFile(alienVirt);
      final PsiDocumentManagerImpl alienDocManager =
          (PsiDocumentManagerImpl) PsiDocumentManager.getInstance(alienProject);
      final Document alienDocument = alienDocManager.getDocument(alienFile);
      // alienDocument.putUserData(CACHED_VIEW_PROVIDER, new MockFileViewProvider(alienFile));
      assertEquals(0, alienDocManager.getUncommittedDocuments().length);
      assertEquals(0, getPsiDocumentManager().getUncommittedDocuments().length);

      ApplicationManager.getApplication()
          .runWriteAction(
              new Runnable() {
                public void run() {
                  getPsiDocumentManager()
                      .documentChanged(
                          new DocumentEventImpl(
                              alienDocument,
                              0,
                              "",
                              "",
                              alienDocument.getModificationStamp(),
                              false));
                  assertEquals(0, getPsiDocumentManager().getUncommittedDocuments().length);
                  assertEquals(0, alienDocManager.getUncommittedDocuments().length);

                  alienDocManager.documentChanged(
                      new DocumentEventImpl(
                          alienDocument, 0, "", "", alienDocument.getModificationStamp(), false));
                  assertEquals(0, getPsiDocumentManager().getUncommittedDocuments().length);
                  assertEquals(1, alienDocManager.getUncommittedDocuments().length);

                  getPsiDocumentManager()
                      .documentChanged(
                          new DocumentEventImpl(
                              document, 0, "", "", document.getModificationStamp(), false));
                  assertEquals(1, getPsiDocumentManager().getUncommittedDocuments().length);
                  assertEquals(1, alienDocManager.getUncommittedDocuments().length);

                  alienDocManager.documentChanged(
                      new DocumentEventImpl(
                          document, 0, "", "", document.getModificationStamp(), false));
                  assertEquals(1, getPsiDocumentManager().getUncommittedDocuments().length);
                  assertEquals(1, alienDocManager.getUncommittedDocuments().length);
                }
              });
    } finally {
      ProjectUtil.closeAndDispose(alienProject);
    }
  }