public void testDoNotRemoveMavenProjectsOnReparse() throws Exception {
    // this pom file doesn't belong to any of the modules, this is won't be processed
    // by MavenProjectProjectsManager and won't occur in its projects list.
    importProject(
        "<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");

    final StringBuilder log = new StringBuilder();
    myProjectsManager.performScheduledImportInTests();
    myProjectsManager.addProjectsTreeListener(
        new MavenProjectsTree.ListenerAdapter() {
          @Override
          public void projectsUpdated(
              List<Pair<MavenProject, MavenProjectChanges>> updated, List<MavenProject> deleted) {
            for (Pair<MavenProject, MavenProjectChanges> each : updated) {
              log.append("updated: " + each.first.getDisplayName() + " ");
            }
            for (MavenProject each : deleted) {
              log.append("deleted: " + each.getDisplayName() + " ");
            }
          }
        });

    FileContentUtil.reparseFiles(myProject, myProjectsManager.getProjectsFiles(), true);
    myProjectsManager.waitForReadingCompletion();

    assertTrue(log.toString(), log.length() == 0);
  }
 public void apply() {
   final List<BaseInjection> injectionList = getInjectionList(injectionInfos);
   cfg.replaceInjections(injectionList, originalInjections, true);
   originalInjections.clear();
   originalInjections.addAll(injectionList);
   sortInjections(originalInjections);
   FileContentUtil.reparseOpenedFiles();
 }
  public static void invokeImpl(
      Project project, Editor editor, final PsiFile file, Injectable injectable) {
    final PsiLanguageInjectionHost host = findInjectionHost(editor, file);
    if (host == null) return;
    if (defaultFunctionalityWorked(host, injectable.getId())) return;

    try {
      host.putUserData(FIX_KEY, null);
      Language language = injectable.toLanguage();
      for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
        if (support.isApplicableTo(host) && support.addInjectionInPlace(language, host)) {
          return;
        }
      }
      if (TemporaryPlacesRegistry.getInstance(project)
          .getLanguageInjectionSupport()
          .addInjectionInPlace(language, host)) {
        final Processor<PsiLanguageInjectionHost> data = host.getUserData(FIX_KEY);
        String text =
            StringUtil.escapeXml(language.getDisplayName()) + " was temporarily injected.";
        if (data != null) {
          if (!ApplicationManager.getApplication().isUnitTestMode()) {
            final SmartPsiElementPointer<PsiLanguageInjectionHost> pointer =
                SmartPointerManager.getInstance(project).createSmartPsiElementPointer(host);
            final TextRange range = host.getTextRange();
            HintManager.getInstance()
                .showQuestionHint(
                    editor,
                    text
                        + "<br>Do you want to insert annotation? "
                        + KeymapUtil.getFirstKeyboardShortcutText(
                            ActionManager.getInstance()
                                .getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS)),
                    range.getStartOffset(),
                    range.getEndOffset(),
                    new QuestionAction() {
                      @Override
                      public boolean execute() {
                        return data.process(pointer.getElement());
                      }
                    });
          }
        } else {
          HintManager.getInstance().showInformationHint(editor, text);
        }
      }
    } finally {
      if (injectable.getLanguage() != null) { // no need for reference injection
        FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
      } else {
        ((PsiModificationTrackerImpl) PsiManager.getInstance(project).getModificationTracker())
            .incCounter();
        DaemonCodeAnalyzer.getInstance(project).restart();
      }
    }
  }
예제 #4
0
 public void replaceInjections(
     final List<? extends BaseInjection> newInjections,
     final List<? extends BaseInjection> originalInjections) {
   for (BaseInjection injection : originalInjections) {
     myInjections.get(injection.getSupportId()).remove(injection);
   }
   for (BaseInjection injection : newInjections) {
     injection.initializePlaces(true);
     myInjections.get(injection.getSupportId()).add(injection);
   }
   configurationModified();
   for (Project project : ProjectManager.getInstance().getOpenProjects()) {
     FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
   }
 }
 private static void invokeImpl(Project project, Editor editor, PsiFile file, String languageId) {
   final PsiLanguageInjectionHost host = findInjectionHost(editor, file);
   if (host == null) return;
   if (defaultFunctionalityWorked(host, languageId)) return;
   final Language language = InjectedLanguage.findLanguageById(languageId);
   try {
     for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
       if (support.addInjectionInPlace(language, host)) return;
     }
     TemporaryPlacesRegistry.getInstance(project)
         .getLanguageInjectionSupport()
         .addInjectionInPlace(language, host);
   } finally {
     FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
   }
 }
 private static void invokeImpl(Project project, Editor editor, PsiFile file) {
   final PsiFile psiFile =
       InjectedLanguageUtil.findInjectedPsiNoCommit(file, editor.getCaretModel().getOffset());
   if (psiFile == null) return;
   final PsiLanguageInjectionHost host =
       InjectedLanguageManager.getInstance(project).getInjectionHost(psiFile);
   if (host == null) return;
   final LanguageInjectionSupport support =
       psiFile.getUserData(LanguageInjectionSupport.INJECTOR_SUPPORT);
   if (support == null) return;
   try {
     if (!support.removeInjectionInPlace(host)) {
       defaultFunctionalityWorked(host);
     }
   } finally {
     FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
   }
 }
 @Override
 public void invoke(@NotNull final Project project, Editor editor, final PsiFile file)
     throws IncorrectOperationException {
   UIUtil.invokeLaterIfNeeded(
       () -> {
         List<VirtualFile> sources = getLibrarySourceFiles();
         final VirtualFile fileRequestor = PsiUtilCore.getVirtualFile(file);
         DialogWrapper dialog =
             new ChooseScopeAndCreateLibraryDialog(
                 project,
                 JstdLibraryUtil.LIBRARY_NAME,
                 sources,
                 new ScriptingFrameworkDescriptor(JstdLibraryUtil.LIBRARY_NAME, "1.3.5"),
                 fileRequestor,
                 false);
         boolean done = dialog.showAndGet();
         if (done) {
           FileContentUtil.reparseFiles(project, Collections.singletonList(fileRequestor), true);
         }
       });
 }
 private void reparsePsiFile() {
   myVirtualFile.setContent(myEditorDocument, myEditorDocument.getText(), false);
   FileContentUtil.reparseFiles(
       myProject, Collections.<VirtualFile>singletonList(myVirtualFile), false);
   myFile = ObjectUtils.assertNotNull(PsiManager.getInstance(myProject).findFile(myVirtualFile));
 }