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


Java PsiDocumentManager.getPsiFile方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: getPsiFileForPsiDependentIndex

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
public PsiFile getPsiFileForPsiDependentIndex() {
  Document document = FileDocumentManager.getInstance().getCachedDocument(getFile());
  PsiFile psi = null;
  if (document != null) {
    PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(getProject());
    if (psiDocumentManager.isUncommited(document)) {
      PsiFile existingPsi = psiDocumentManager.getPsiFile(document);
      if(existingPsi != null) {
        psi = existingPsi;
      }
    }
  }
  if (psi == null) {
    psi = getPsiFile();
  }
  return psi;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:FileContentImpl.java

示例4: 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

示例5: 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

示例6: getCustomFoldingDescriptors

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@NotNull
private static Collection<FoldingDescriptor> getCustomFoldingDescriptors(@NotNull Editor editor, @NotNull Project project) {
  Set<FoldingDescriptor> foldingDescriptors = new HashSet<FoldingDescriptor>();
  final Document document = editor.getDocument();
  PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  PsiFile file = documentManager != null ? documentManager.getPsiFile(document) : null;
  if (file != null) {
    final FileViewProvider viewProvider = file.getViewProvider();
    for (final Language language : viewProvider.getLanguages()) {
      final PsiFile psi = viewProvider.getPsi(language);
      final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
      if (psi != null) {
        for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, false)) {
          CustomFoldingBuilder customFoldingBuilder = getCustomFoldingBuilder(foldingBuilder, descriptor);
          if (customFoldingBuilder != null) {
            if (customFoldingBuilder.isCustomRegionStart(descriptor.getElement())) {
              foldingDescriptors.add(descriptor);
            }
          }
        }
      }
    }
  }
  return foldingDescriptors;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:GotoCustomRegionAction.java

示例7: insert

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
private static void insert(final String fqn, final PsiElement element, final Editor editor, final QualifiedNameProvider provider) {
  final Project project = editor.getProject();
  if (project == null) return;

  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  documentManager.commitDocument(editor.getDocument());

  final PsiFile file = documentManager.getPsiFile(editor.getDocument());
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          Document document = editor.getDocument();
          documentManager.doPostponedOperationsAndUnblockDocument(document);
          documentManager.commitDocument(document);
          EditorModificationUtil.deleteSelectedText(editor);
          provider.insertQualifiedName(fqn, element, editor, project);
        }
      });
    }
  }, IdeBundle.message("command.pasting.reference"), null);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:PasteReferenceProvider.java

示例8: getDocumentLanguage

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@Nullable
private static Language getDocumentLanguage(@Nullable Project project, @NotNull Document document) {
   if (project != null) {
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    PsiFile file = documentManager.getPsiFile(document);
    if (file != null) return file.getLanguage();
  }
  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:10,代碼來源:SettingsImpl.java

示例9: updateDocumentIndentOptions

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
/**
 * Updates document's indent options from indent options providers.
 * <p><b>Note:</b> Calling this method directly when there is an editor associated with the document may cause the editor work
 * incorrectly. To keep consistency with the editor call <code>EditorEx.reinitSettings()</code> instead.
 * @param project  The project of the document.
 * @param document The document to update indent options for.
 */
public static void updateDocumentIndentOptions(@NotNull Project project, @NotNull Document document) {
  if (!project.isDisposed()) {
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    if (documentManager != null) {
      PsiFile file = documentManager.getPsiFile(document);
      if (file != null) {
        CommonCodeStyleSettings.IndentOptions indentOptions = getSettings(project).getIndentOptionsByFile(file, null, true, null);
        indentOptions.associateWithDocument(document);
      }
    }
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:CodeStyleSettingsManager.java

示例10: 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

示例11: buildInitialFoldings

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@Nullable
@Override
public CodeFoldingState buildInitialFoldings(@NotNull final Document document) {
  if (myProject.isDisposed()) {
    return null;
  }
  ApplicationManager.getApplication().assertReadAccessAllowed();
  PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(myProject);
  if (psiDocumentManager.isUncommited(document)) {
    // skip building foldings for uncommitted document, CodeFoldingPass invoked by daemon will do it later
    return null;
  }
  //Do not save/restore folding for code fragments
  final PsiFile file = psiDocumentManager.getPsiFile(document);
  if (file == null || !file.isValid() || !file.getViewProvider().isPhysical() && !ApplicationManager.getApplication().isUnitTestMode()) {
    return null;
  }


  final FoldingUpdate.FoldingMap foldingMap = FoldingUpdate.getFoldingsFor(file, document, true);

  return new CodeFoldingState() {
    @Override
    public void setToEditor(@NotNull final Editor editor) {
      ApplicationManagerEx.getApplicationEx().assertIsDispatchThread();
      if (myProject.isDisposed() || editor.isDisposed()) return;
      final FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel();
      if (!foldingModel.isFoldingEnabled()) return;
      if (isFoldingsInitializedInEditor(editor)) return;
      if (DumbService.isDumb(myProject) && !FoldingUpdate.supportsDumbModeFolding(editor)) return;

      foldingModel.runBatchFoldingOperationDoNotCollapseCaret(new UpdateFoldRegionsOperation(myProject, editor, file, foldingMap, YES, false));
      initFolding(editor);
    }
  };
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:37,代碼來源:CodeFoldingManagerImpl.java

示例12: getPsiElementsAt

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@NotNull
private static Collection<PsiElement> getPsiElementsAt(Point point, Editor editor) {
  if (editor.isDisposed()) {
    return Collections.emptySet();
  }

  Project project = editor.getProject();
  if (project == null || project.isDisposed()) {
    return Collections.emptySet();
  }

  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document document = editor.getDocument();
  PsiFile psiFile = documentManager.getPsiFile(document);
  if (psiFile == null || psiFile instanceof PsiCompiledElement || !psiFile.isValid()) {
    return Collections.emptySet();
  }

  final Set<PsiElement> elements = Collections.newSetFromMap(new WeakHashMap<PsiElement, Boolean>());
  final int offset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(point));
  if (documentManager.isCommitted(document)) {
    ContainerUtil.addIfNotNull(elements, InjectedLanguageUtil.findElementAtNoCommit(psiFile, offset));
  }
  for (PsiFile file : psiFile.getViewProvider().getAllFiles()) {
    ContainerUtil.addIfNotNull(elements, file.findElementAt(offset));
  }

  return elements;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:30,代碼來源:ImageOrColorPreviewManager.java

示例13: 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

示例14: isEnabled

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
protected boolean isEnabled(AnActionEvent event, boolean checkAvailable) {
    final Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) {
        // no active project
        return false;
    }

    Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
    if (editor == null) {
        FileEditorManager fem = FileEditorManager.getInstance(project);
        editor = fem.getSelectedTextEditor();
    }
    if (editor == null) {
        return false;
    }

    // do we have an xml file?
    final PsiDocumentManager cem = PsiDocumentManager.getInstance(project);
    final PsiFile psiFile = cem.getPsiFile(editor.getDocument());
    // this is also true for DTD documents...
    if (!(psiFile instanceof XmlFile)) {
        return false;
    } else if (psiFile.getLanguage() == StdFileTypes.DTD.getLanguage()) {
        return false;
    }

    return !checkAvailable || isEnabledAt((XmlFile)psiFile, editor.getCaretModel().getOffset());
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:29,代碼來源:XPathAction.java

示例15: actionPerformed

import com.intellij.psi.PsiDocumentManager; //導入方法依賴的package包/類
@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) {
        // no active project
        LOG.debug("No project");
        return;
    }

    Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
    if (editor == null) {
        FileEditorManager fem = FileEditorManager.getInstance(project);
        editor = fem.getSelectedTextEditor();
    }
    if (editor == null) {
        // no editor available
        LOG.debug("No editor");
        return;
    }

    // do we have an xml file?
    final PsiDocumentManager pdm = PsiDocumentManager.getInstance(project);
    final PsiFile psiFile = pdm.getPsiFile(editor.getDocument());
    if (!(psiFile instanceof XmlFile)) {
        // not xml
        LOG.debug("No XML-File: " + psiFile);
        return;
    }

    // make sure PSI is in sync with document
    pdm.commitDocument(editor.getDocument());

    execute(editor);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:35,代碼來源:XPathEvalAction.java


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