当前位置: 首页>>代码示例>>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;未经允许,请勿转载。