當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiDocumentManager.getInstance方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiDocumentManager.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiDocumentManager.getInstance方法的具體用法?Java PsiDocumentManager.getInstance怎麽用?Java PsiDocumentManager.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiDocumentManager的用法示例。


在下文中一共展示了PsiDocumentManager.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: forcePsiPostprocessAndRestoreElement

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public static <T extends PsiElement> T forcePsiPostprocessAndRestoreElement(@NotNull T element,
                                                                            boolean useFileLanguage) {
  final PsiFile psiFile = element.getContainingFile();
  final Document document = psiFile.getViewProvider().getDocument();
  //if (document == null) return element;
  final Language language = useFileLanguage ? psiFile.getLanguage() : PsiUtilCore.getDialect(element);
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(psiFile.getProject());
  final RangeMarker rangeMarker = document.createRangeMarker(element.getTextRange());
  documentManager.doPostponedOperationsAndUnblockDocument(document);
  documentManager.commitDocument(document);

  T elementInRange = findElementInRange(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(),
                                        (Class<? extends T>)element.getClass(),
                                        language);
  rangeMarker.dispose();
  return elementInRange;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:CodeInsightUtilCore.java

示例2: resolveURI

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public static String resolveURI(PsiFile descriptorFile, String s) {
    final PsiFile file = XmlUtil.findXmlFile(descriptorFile, s);

    if (file != null) {
      final VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile != null) {
        final PsiDocumentManager dm = PsiDocumentManager.getInstance(file.getProject());
        final Document d = dm.getCachedDocument(file);
        if (d != null) {
          // TODO: fix. write action + saving -> deadlock
//          dm.commitDocument(d);
//          FileDocumentManager.getInstance().saveDocument(d);
        }
        s = reallyFixIDEAUrl(virtualFile.getUrl());
      }
    }
    return s;
  }
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:RngParser.java

示例3: addOrReplaceSelectionForEditor

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
protected final void addOrReplaceSelectionForEditor(final String selection, Editor editor) {
  final Project project = searchContext.getProject();
  UIUtil.setContent(editor, selection, 0, -1, project);
  final Document document = editor.getDocument();
  editor.getSelectionModel().setSelection(0, document.getTextLength());
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  documentManager.commitDocument(document);
  final PsiFile file = documentManager.getPsiFile(document);
  if (file == null) return;

  new WriteCommandAction(project, file) {
    @Override protected void run(@NotNull Result result) throws Throwable {
      CodeStyleManager.getInstance(project).adjustLineIndent(file, new TextRange(0, document.getTextLength()));
    }
  }.execute();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:SearchDialog.java

示例4: testXmlDeclDtd

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public void testXmlDeclDtd() throws Exception {
  PsiFile file = createFile("x.xml", "<!DOCTYPE name [\n" +
                                     "  <!ELEMENT name (" + marker+ "a b c d" + marker+ ")>\n" +
                                     "  <!ELEMENT name2 (" + marker+ "%entity;" + marker+ ")>\n" +
                                     "]>\n" +
                                     "<name></name>");

  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
  Document document = documentManager.getDocument(file);

  removeGarbage(document);

  documentManager.commitAllDocuments();
  String myFullDataPath = getTestDataPath() + "psi/";
  ParsingTestCase.doCheckResult(myFullDataPath, file, true, "testXmlDeclDtd", false, false);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:XmlReparseTest.java

示例5: iterateOverCarets

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
private static void iterateOverCarets(@NotNull final Project project,
                               @NotNull final Editor hostEditor,
                               @NotNull final MultiCaretCodeInsightActionHandler handler) {
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final PsiFile psiFile = documentManager.getCachedPsiFile(hostEditor.getDocument());
  documentManager.commitAllDocuments();

  hostEditor.getCaretModel().runForEachCaret(new CaretAction() {
    @Override
    public void perform(Caret caret) {
      Editor editor = hostEditor;
      if (psiFile != null) {
        Caret injectedCaret = InjectedLanguageUtil.getCaretForInjectedLanguageNoCommit(caret, psiFile);
        if (injectedCaret != null) {
          caret = injectedCaret;
          editor = caret.getEditor();
        }
      }
      final PsiFile file = PsiUtilBase.getPsiFileInEditor(caret, project);
      if (file != null) {
        handler.invoke(project, editor, caret, file);
      }
    }
  });
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:MultiCaretCodeInsightAction.java

示例6: reinitDocumentIndentOptions

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
private void reinitDocumentIndentOptions() {
  if (myEditor == null) return;
  final Project project = myEditor.getProject();
  final DocumentEx document = myEditor.getDocument();

  if (project == null || project.isDisposed()) return;

  final PsiDocumentManager psiManager = PsiDocumentManager.getInstance(project);
  final PsiFile file = psiManager.getPsiFile(document);
  if (file == null) return;

  CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
  CommonCodeStyleSettings.IndentOptions options = settings.getIndentOptionsByFile(file);

  if (CodeStyleSettings.isRecalculateForCommittedDocument(options)) {
    PsiDocumentManager.getInstance(project).performForCommittedDocument(document, new Runnable() {
      @Override
      public void run() {
        CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
      }
    });
  }
  else {
    CodeStyleSettingsManager.updateDocumentIndentOptions(project, document);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:SettingsImpl.java

示例7: indentBlock

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
static void indentBlock(Project project, Editor editor, final int startOffset, final int endOffset, int originalCaretCol) {
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  documentManager.commitAllDocuments();
  final Document document = editor.getDocument();
  PsiFile file = documentManager.getPsiFile(document);
  if (file == null) {
    return;
  }

  if (LanguageFormatting.INSTANCE.forContext(file) != null) {
    indentBlockWithFormatter(project, document, startOffset, endOffset, file);
  }
  else {
    indentPlainTextBlock(document, startOffset, endOffset, originalCaretCol);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:PasteHandler.java

示例8: isEnabled

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@Override
public boolean isEnabled(Editor editor, DataContext dataContext) {
  if (editor.isViewer() || editor.isOneLineMode()) return false;
  final Project project = editor.getProject();
  if (project == null || project.isDisposed()) return false;
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document document = editor.getDocument();
  documentManager.commitDocument(document);
  PsiFile psiFile = documentManager.getPsiFile(document);
  PsiFile file = getRoot(psiFile, editor);
  if (file == null) return false;
  final MoverWrapper mover = getSuitableMover(editor, file);
  if (mover == null || mover.getInfo().toMove2 == null) return false;
  final int maxLine = editor.offsetToLogicalPosition(editor.getDocument().getTextLength()).line;
  final LineRange range = mover.getInfo().toMove;
  if (range.startLine == 0 && !isDown) return false;

  return range.endLine <= maxLine || !isDown;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:BaseMoveHandler.java

示例9: createProperty

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public static void createProperty(final Project project,
                                  final Collection<PropertiesFile> propertiesFiles,
                                  final String key,
                                  final String value) throws IncorrectOperationException {
  for (PropertiesFile file : propertiesFiles) {
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    documentManager.commitDocument(documentManager.getDocument(file.getContainingFile()));

    IProperty existingProperty = file.findPropertyByKey(key);
    if (existingProperty == null) {
      file.addProperty(key, value);
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:15,代碼來源:I18nUtil.java

示例10: actionPerformed

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getProject();
  if (project == null) {
    return;
  }
  
  final Editor editor = e.getData(CommonDataKeys.EDITOR);
  if (editor == null) {
    return;
  }
  
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  Document document = editor.getDocument();
  documentManager.commitDocument(document);
  
  final PsiFile file = documentManager.getPsiFile(document);
  if (file == null) {
    return;
  }

  SelectionModel model = editor.getSelectionModel();
  if (model.hasSelection()) {
    new RearrangeCodeProcessor(file, model).run();
  }
  else {
    new RearrangeCodeProcessor(file).run();
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:RearrangeCodeAction.java

示例11: buildLiveRearrangerData

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
/**
 * must be called from within an IDEA read-action thread.
 *
 * @param project
 * @param document
 * @param psiFile
 */
void buildLiveRearrangerData(final Project project,
                             final Document document,
                             final PsiFile psiFile,
                             final int cursorOffset)
{
    /**
     * Per instructions from IntelliJ, we have to commit any changes to the document to the Psi
     * tree.
     */
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    documentManager.commitDocument(document);
    final RearrangerSettings settings    = new RearrangerSettings(); // use default settings with no rules
    settings.setAskBeforeRearranging(true);
    final Runnable task = new Runnable()
    {
        public void run()
        {
            logger.debug("liveRearrangeDocument task started");
            liveRearrangeDocument(project, psiFile, settings, document, cursorOffset);
        }
    };

    Thread t = new Thread(new Runnable()
    {
        public void run()
        {
            logger.debug("started thread " + Thread.currentThread().getName());
            final Application application = ApplicationManager.getApplication();
            application.runReadAction(new Runnable() {
                public void run() {
                    logger.debug("enter application.runReadAction() on thread " + Thread.currentThread().getName());
                    task.run();
                    logger.debug("exit application.runReadAction() on thread " + Thread.currentThread().getName());
            }});
        }
    }, "Live Rearranger parser");
    t.start();
    logger.debug("exit buildLiveRearrangerData on thread " + Thread.currentThread().getName());
}
 
開發者ID:DaveKriewall,項目名稱:Rearranger,代碼行數:47,代碼來源:RearrangementResult31.java

示例12: autoPopupParameterInfo

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public void autoPopupParameterInfo(@NotNull final Editor editor, @Nullable final PsiElement highlightedMethod){
  if (ApplicationManager.getApplication().isUnitTestMode()) return;
  if (DumbService.isDumb(myProject)) return;
  if (PowerSaveMode.isEnabled()) return;

  ApplicationManager.getApplication().assertIsDispatchThread();
  final CodeInsightSettings settings = CodeInsightSettings.getInstance();
  if (settings.AUTO_POPUP_PARAMETER_INFO) {
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
    PsiFile file = documentManager.getPsiFile(editor.getDocument());
    if (file == null) return;

    if (!documentManager.isUncommited(editor.getDocument())) {
      file = documentManager.getPsiFile(InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file).getDocument());
      if (file == null) return;
    }

    final PsiFile file1 = file;
    final Runnable request = new Runnable(){
      @Override
      public void run(){
        if (myProject.isDisposed() || DumbService.isDumb(myProject)) return;
        documentManager.commitAllDocuments();
        if (editor.isDisposed() || !editor.getComponent().isShowing()) return;
        int lbraceOffset = editor.getCaretModel().getOffset() - 1;
        try {
          ShowParameterInfoHandler.invoke(myProject, editor, file1, lbraceOffset, highlightedMethod);
        }
        catch (IndexNotReadyException ignored) { //anything can happen on alarm
        }
      }
    };

    addRequest(request, settings.PARAMETER_INFO_DELAY);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:37,代碼來源:AutoPopupController.java

示例13: getInjectedEditor

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public static Editor getInjectedEditor(@NotNull Project project, final Editor editor, boolean commit) {
  Editor injectedEditor = editor;
  if (editor != null) {
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    PsiFile psiFile = documentManager.getCachedPsiFile(editor.getDocument());
    if (psiFile != null) {
      if (commit) documentManager.commitAllDocuments();
      injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, psiFile);
    }
  }
  return injectedEditor;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:13,代碼來源:BaseCodeInsightAction.java

示例14: testNestedEditValueText

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public void testNestedEditValueText() throws Exception {
  resetScanCounter();

  VirtualFile file1 = myFixture.copyFileToProject(VALUES1, "res/values/myvalues.xml");
  PsiFile psiFile1 = PsiManager.getInstance(getProject()).findFile(file1);
  assertNotNull(psiFile1);

  ResourceFolderRepository resources = createRepository();
  assertNotNull(resources);

  List<ResourceItem> labelList = resources.getResourceItem(ResourceType.STRING, "title_template_step");
  assertNotNull(labelList);
  assertEquals(1, labelList.size());
  ResourceItem label = labelList.get(0);
  ResourceValue resourceValue = label.getResourceValue(false);
  assertNotNull(resourceValue);
  assertEquals("Step ${step_number}: Lorem Ipsum", resourceValue.getValue());

  long generation = resources.getModificationCount();
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
  final Document document = documentManager.getDocument(psiFile1);
  assertNotNull(document);

  // Edit value should cause update
  final int textOffset = document.getText().indexOf("Lorem");
  WriteCommandAction.runWriteCommandAction(null, new Runnable() {
    @Override
    public void run() {
      document.insertString(textOffset + 1, "l");
      documentManager.commitDocument(document);
    }
  });
  assertTrue(generation < resources.getModificationCount());
  resourceValue = label.getResourceValue(false);
  assertNotNull(resourceValue);
  assertEquals("Step ${step_number}: Llorem Ipsum", resourceValue.getValue());

  // Shouldn't have done any full file rescans during the above edits
  ensureIncremental();
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:41,代碼來源:ResourceFolderRepositoryTest.java

示例15: asyncCommitDocuments

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@NotNull
public static ActionCallback asyncCommitDocuments(@NotNull Project project) {
  if (project.isDisposed()) return ActionCallback.DONE;
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  if (!documentManager.hasUncommitedDocuments()) {
    return ActionCallback.DONE;
  }
  final ActionCallback callback = new ActionCallback();
  documentManager.performWhenAllCommitted(callback.createSetDoneRunnable());
  return callback;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:12,代碼來源:AbstractTreeStructure.java


注:本文中的com.intellij.psi.PsiDocumentManager.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。