当前位置: 首页>>代码示例>>Java>>正文


Java FileDocumentManager.getDocument方法代码示例

本文整理汇总了Java中com.intellij.openapi.fileEditor.FileDocumentManager.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java FileDocumentManager.getDocument方法的具体用法?Java FileDocumentManager.getDocument怎么用?Java FileDocumentManager.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.fileEditor.FileDocumentManager的用法示例。


在下文中一共展示了FileDocumentManager.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveFiles

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
protected void saveFiles(PhpClass currentTestClass, Project project) {
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();

    Document documentTestClass = fileDocumentManager.getDocument(currentTestClass.getContainingFile().getVirtualFile());
    if (documentTestClass != null) {
        fileDocumentManager.saveDocument(documentTestClass);
    }

    PhpClass currentTestedClass = Utils.locateTestedClass(project, currentTestClass);
    if (currentTestedClass != null) {
        Document documentTestedClass = fileDocumentManager.getDocument(currentTestedClass.getContainingFile().getVirtualFile());
        if (documentTestedClass != null) {
            fileDocumentManager.saveDocument(documentTestedClass);
        }
    }
}
 
开发者ID:atoum,项目名称:phpstorm-plugin,代码行数:17,代码来源:Run.java

示例2: setupFileEditorAndDocument

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@NotNull
private static Document setupFileEditorAndDocument(@NotNull String fileName, @NotNull String fileText) throws IOException {
  EncodingProjectManager.getInstance(getProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
  EncodingProjectManager.getInstance(ProjectManager.getInstance().getDefaultProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
  PostprocessReformattingAspect.getInstance(ourProject).doPostponedFormatting();
  deleteVFile();
  myVFile = getSourceRoot().createChildData(null, fileName);
  VfsUtil.saveText(myVFile, fileText);
  final FileDocumentManager manager = FileDocumentManager.getInstance();
  final Document document = manager.getDocument(myVFile);
  assertNotNull("Can't create document for '" + fileName + "'", document);
  manager.reloadFromDisk(document);
  document.insertString(0, " ");
  document.deleteString(0, 1);
  myFile = getPsiManager().findFile(myVFile);
  assertNotNull("Can't create PsiFile for '" + fileName + "'. Unknown file type most probably.", myFile);
  assertTrue(myFile.isPhysical());
  myEditor = createEditor(myVFile);
  myVFile.setCharset(CharsetToolkit.UTF8_CHARSET);

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  return document;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:LightPlatformCodeInsightTestCase.java

示例3: createPopup

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Nullable
public ListPopup createPopup(@NotNull DataContext dataContext) {
  final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
  if (virtualFile == null) return null;
  boolean enabled = checkEnabled(virtualFile);
  if (!enabled) return null;
  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  FileDocumentManager documentManager = FileDocumentManager.getInstance();
  final Document document = documentManager.getDocument(virtualFile);
  if (!allowDirectories && virtualFile.isDirectory() || document == null && !virtualFile.isDirectory()) return null;

  final byte[] bytes;
  try {
    bytes = virtualFile.isDirectory() ? null : virtualFile.contentsToByteArray();
  }
  catch (IOException e) {
    return null;
  }
  DefaultActionGroup group = createActionGroup(virtualFile, editor, document, bytes, null);

  return JBPopupFactory.getInstance().createActionGroupPopup(getTemplatePresentation().getText(),
    group, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ChangeFileEncodingAction.java

示例4: execute

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Override
protected void execute(@NotNull Project project) {
  FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
  final Document document = fileDocumentManager.getDocument(myConfigToCorrect);
  if (document == null) {
    return;
  }
  boolean updated = GradleUtil.updateGradleDependencyVersion(project, document, APPENGINE_PLUGIN_NAME, new Computable<String>() {
    @Override
    public String compute() {
      ExternalRepository repository = ServiceManager.getService(ExternalRepository.class);
      FullRevision latest = repository.getLatest(APPENGINE_PLUGIN_GROUP_ID, APPENGINE_PLUGIN_ARTIFACT_ID);
      return latest == null ? DEFAULT_APPENGINE_PLUGIN_VERSION : latest.toString();
    }
  });
  if (updated) {
    GradleProjectImporter.getInstance().requestProjectSync(project, null);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:UpgradeAppenginePluginVersionHyperlink.java

示例5: save

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static void save(VirtualFile file, String content)
{
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    Document document = fileDocumentManager.getDocument(file);
    if (document != null)
    {
        document.setText(content);
        fileDocumentManager.saveDocument(document);
    }
}
 
开发者ID:miche-atucha,项目名称:deps-checker,代码行数:11,代码来源:VirtualFileHelper.java

示例6: getCopyWithAnswers

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
static Pair<VirtualFile, TaskFile> getCopyWithAnswers(@NotNull final VirtualFile taskDir,
                                                              @NotNull final VirtualFile file,
                                                              @NotNull final TaskFile source) {
  try {
    VirtualFile answerFile = file.copy(taskDir, taskDir, file.getNameWithoutExtension() + EduNames.ANSWERS_POSTFIX + "." + file.getExtension());
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    final Document document = documentManager.getDocument(answerFile);
    if (document != null) {
      TaskFile answerTaskFile = source.getTask().copy().getTaskFile(StudyUtils.pathRelativeToTask(file));
      if (answerTaskFile == null) {
        return null;
      }
      EduDocumentListener listener = new EduDocumentListener(answerTaskFile);
      document.addDocumentListener(listener);
      for (AnswerPlaceholder answerPlaceholder : answerTaskFile.getActivePlaceholders()) {
        final int start = answerPlaceholder.getOffset();
        final int end = start + answerPlaceholder.getRealLength();
        final String text = answerPlaceholder.getPossibleAnswer();
        document.replaceString(start, end, text);
      }
      ApplicationManager.getApplication().runWriteAction(() -> documentManager.saveDocument(document));
      return Pair.create(answerFile, answerTaskFile);
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  return null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:30,代码来源:PyStudySmartChecker.java

示例7: createRequest

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Nullable
protected DiffRequest createRequest(Project project, DiffElement element) throws IOException {
  final T src = getValue();
  final Object trg = element.getValue();
  if (src instanceof VirtualFile && trg instanceof VirtualFile
      && ((VirtualFile)src).getFileType().isBinary()
      && ((VirtualFile)trg).getFileType().isBinary()) {
    return createRequestForBinaries(project, ((VirtualFile)src), ((VirtualFile)trg));
  }
  if (src instanceof VirtualFile) {
    if (((VirtualFile)src).getFileType().isBinary()) return null;
    if (trg instanceof VirtualFile) {
      if (((VirtualFile)trg).getFileType().isBinary()) return null;
      final FileDocumentManager mgr = FileDocumentManager.getInstance();
      if (mgr.getDocument((VirtualFile)src) != null && mgr.getDocument((VirtualFile)trg) != null) {
        return SimpleDiffRequest.compareFiles((VirtualFile)src, (VirtualFile)trg, project == null ? ProjectManager.getInstance().getDefaultProject() : project);
      }
    }
  }
  final DiffContent srcContent = createDiffContent();
  final DiffContent trgContent = element.createDiffContent();

  if (srcContent != null && trgContent != null) {
    final SimpleDiffRequest request = new SimpleDiffRequest(project, "");
    request.setContents(srcContent, trgContent);
    return request;
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:DiffElement.java

示例8: saveOrReload

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
private static void saveOrReload(VirtualFile file, @NotNull Collection<VFilePropertyChangeEvent> events) {
  if (file == null || file.isDirectory() || !file.isValid()) {
    return;
  }

  FileDocumentManager documentManager = FileDocumentManager.getInstance();
  if (documentManager.isFileModified(file)) {
    Document document = documentManager.getDocument(file);
    if (document != null) {
      documentManager.saveDocumentAsIs(document); // this can be called e.g. in context of undo, so we shouldn't modify document
    }
  }

  events.add(new VFilePropertyChangeEvent(FORCE_RELOAD_REQUESTOR, file, VirtualFile.PROP_NAME, file.getName(), file.getName(), false));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:FileContentUtilCore.java

示例9: assertFilesEqual

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static void assertFilesEqual(VirtualFile fileAfter, VirtualFile fileBefore) throws IOException {
  try {
    assertJarFilesEqual(VfsUtilCore.virtualToIoFile(fileAfter), VfsUtilCore.virtualToIoFile(fileBefore));
  }
  catch (IOException e) {
    FileDocumentManager manager = FileDocumentManager.getInstance();

    Document docBefore = manager.getDocument(fileBefore);
    boolean canLoadBeforeText = !fileBefore.getFileType().isBinary() || fileBefore.getFileType() == FileTypes.UNKNOWN;
    String textB = docBefore != null
                   ? docBefore.getText()
                   : !canLoadBeforeText
                     ? null
                     : LoadTextUtil.getTextByBinaryPresentation(fileBefore.contentsToByteArray(false), fileBefore).toString();

    Document docAfter = manager.getDocument(fileAfter);
    boolean canLoadAfterText = !fileBefore.getFileType().isBinary() || fileBefore.getFileType() == FileTypes.UNKNOWN;
    String textA = docAfter != null
                   ? docAfter.getText()
                   : !canLoadAfterText
                     ? null
                     : LoadTextUtil.getTextByBinaryPresentation(fileAfter.contentsToByteArray(false), fileAfter).toString();

    if (textA != null && textB != null) {
      assertEquals(fileAfter.getPath(), textA, textB);
    }
    else {
      Assert.assertArrayEquals(fileAfter.getPath(), fileAfter.contentsToByteArray(), fileBefore.contentsToByteArray());
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:PlatformTestUtil.java

示例10: checkEnabled

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
private boolean checkEnabled(@NotNull VirtualFile virtualFile) {
  if (allowDirectories && virtualFile.isDirectory()) return true;
  FileDocumentManager documentManager = FileDocumentManager.getInstance();
  Document document = documentManager.getDocument(virtualFile);
  if (document == null) return false;

  return EncodingUtil.checkCanConvert(virtualFile) == null || EncodingUtil.checkCanReload(virtualFile).second == null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ChangeFileEncodingAction.java

示例11: checkCanReload

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@NotNull
// returns existing charset (null means N/A), failReason: null means enabled, notnull means disabled and contains error message
public static Pair<Charset, String> checkCanReload(@NotNull VirtualFile virtualFile) {
  if (virtualFile.isDirectory()) {
    return Pair.create(null, "file is a directory");
  }
  FileDocumentManager documentManager = FileDocumentManager.getInstance();
  Document document = documentManager.getDocument(virtualFile);
  if (document == null) return Pair.create(null, "binary file");
  Charset charsetFromContent = ((EncodingManagerImpl)EncodingManager.getInstance()).computeCharsetFromContent(virtualFile);
  Charset existing = charsetFromContent;
  String failReason = LoadTextUtil.wasCharsetDetectedFromBytes(virtualFile);
  if (failReason != null) {
    // no point changing encoding if it was auto-detected
    existing = virtualFile.getCharset();
  }
  else if (charsetFromContent != null) {
    failReason = "hard coded in text";
  }
  else {
    Pair<Charset, String> fileTypeCheck = checkHardcodedCharsetFileType(virtualFile);
    if (fileTypeCheck.second != null) {
      failReason = fileTypeCheck.second;
      existing = fileTypeCheck.first;
    }
  }
  if (failReason != null) {
    return Pair.create(existing, failReason);
  }
  return Pair.create(virtualFile.getCharset(), null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:EncodingUtil.java

示例12: createHeavyEditor

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@NotNull
private static Editor createHeavyEditor(@NotNull String name, @NotNull String text) throws IOException {
  VirtualFile myVFile = getSourceRoot().createChildData(null, name);
  VfsUtil.saveText(myVFile, text);
  final FileDocumentManager manager = FileDocumentManager.getInstance();
  final Document document = manager.getDocument(myVFile);
  manager.reloadFromDisk(document);
  Editor editor = createEditor(myVFile);
  EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(document);
  EditorTestUtil.setCaretsAndSelection(editor, caretsState);
  return editor;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:TrailingSpacesStripperTest.java

示例13: getCopyWithAnswers

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
private VirtualFile getCopyWithAnswers(@NotNull final VirtualFile taskDir,
                                       @NotNull final VirtualFile file,
                                       @NotNull final TaskFile source,
                                       @NotNull final TaskFile target) {
  VirtualFile copy = null;
  try {

    copy = file.copy(this, taskDir, file.getNameWithoutExtension() + ANSWERS_POSTFIX + "." + file.getExtension());
    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    final Document document = documentManager.getDocument(copy);
    if (document != null) {
      TaskFile.copy(source, target);
      EduDocumentListener listener = new EduDocumentListener(target);
      document.addDocumentListener(listener);
      for (AnswerPlaceholder answerPlaceholder : target.getAnswerPlaceholders()) {
        if (!answerPlaceholder.isValid(document)) {
          continue;
        }
        final int start = answerPlaceholder.getRealStartOffset(document);
        final int end = start + answerPlaceholder.getLength();
        final String text = answerPlaceholder.getPossibleAnswer();
        document.replaceString(start, end, text);
      }
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        @Override
        public void run() {
          documentManager.saveDocument(document);
        }
      });
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  return copy;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:StudyCheckAction.java

示例14: saveFiles

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
public static void saveFiles(VirtualFile... files) {
  // ensure the validation/conversion runs on the current content
  final FileDocumentManager mgr = FileDocumentManager.getInstance();
  for (VirtualFile f : files) {
    final Document document = mgr.getDocument(f);
    if (document != null) {
      mgr.saveDocument(document);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:ValidateAction.java

示例15: buildSourceBinding

import com.intellij.openapi.fileEditor.FileDocumentManager; //导入方法依赖的package包/类
@Nullable
public static GradleEditorSourceBinding buildSourceBinding(@NotNull Location location, @NotNull Project project) {
  FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
  Document document = fileDocumentManager.getDocument(location.file);
  if (document == null) {
    LOG.warn(String.format("Can't obtain a document for file %s for processing location '%s'",
                           location.file, location));
    return null;
  }
  RangeMarker rangeMarker = document.createRangeMarker(location.range);
  return new GradleEditorSourceBinding(project, location.file, rangeMarker);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:GradleEditorModelUtil.java


注:本文中的com.intellij.openapi.fileEditor.FileDocumentManager.getDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。