Java 类com.intellij.util.LocalTimeCounter 实例源码

项目:intellij-ce-playground    文件:FileDocumentManagerImplTest.java   
@SuppressWarnings("UnusedDeclaration")
public void _testContentChanged_reloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "zzz");
  file.setContent(null, "xxx", false);

  myReloadFromDisk = Boolean.TRUE;
  myDocumentManager.saveAllDocuments();
  long fileStamp = file.getModificationStamp();

  assertEquals("xxx", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertEquals(file.getModificationStamp(), fileStamp);
  assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
}
项目:intellij-ce-playground    文件:XmlStructuralSearchProfile.java   
@NotNull
@Override
public PsiElement[] createPatternTree(@NotNull String text,
                                      @NotNull PatternTreeContext context,
                                      @NotNull FileType fileType,
                                      @Nullable Language language,
                                      String contextName, @Nullable String extension,
                                      @NotNull Project project,
                                      boolean physical) {
  final String ext = extension != null ? extension : fileType.getDefaultExtension();
  String text1 = context == PatternTreeContext.File ? text : "<QQQ>" + text + "</QQQ>";
  final PsiFile fileFromText = PsiFileFactory.getInstance(project)
    .createFileFromText("dummy." + ext, fileType, text1, LocalTimeCounter.currentTime(), physical, true);

  final XmlDocument document = HtmlUtil.getRealXmlDocument(((XmlFile)fileFromText).getDocument());
  if (context == PatternTreeContext.File) {
    return new PsiElement[]{document};
  }

  return document.getRootTag().getValue().getChildren();
}
项目:intellij-ce-playground    文件:StructuralSearchProfile.java   
@NotNull
public PsiElement[] createPatternTree(@NotNull String text,
                                      @NotNull PatternTreeContext context,
                                      @NotNull FileType fileType,
                                      @Nullable Language language,
                                      @Nullable String contextName,
                                      @Nullable String extension,
                                      @NotNull Project project,
                                      boolean physical) {
  final String ext = extension != null ? extension : fileType.getDefaultExtension();
  final String name = "__dummy." + ext;
  final PsiFileFactory factory = PsiFileFactory.getInstance(project);

  final PsiFile file = language == null
                       ? factory.createFileFromText(name, fileType, text, LocalTimeCounter.currentTime(), physical, true)
                       : factory.createFileFromText(name, language, text, physical, true);

  return file != null ? file.getChildren() : PsiElement.EMPTY_ARRAY;
}
项目:intellij-ce-playground    文件:TemplateDataElementType.java   
protected PsiFile createFromText(final Language language, CharSequence text, PsiManager manager) {
  @NonNls
  final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), text, LocalTimeCounter.currentTime());

  FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {
    @Override
    @NotNull
    public Language getBaseLanguage() {
      return language;
    }
  };

  // Since we're already inside a template language PSI that was built regardless of the file size (for whatever reason), 
  // there should also be no file size checks for template data files.
  SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);

  return viewProvider.getPsi(language);
}
项目:intellij-ce-playground    文件:GenerationNode.java   
private static int gotoChild(Project project, CharSequence text, int offset, int start, int end) {
  PsiFile file = PsiFileFactory.getInstance(project)
    .createFileFromText("dummy.xml", StdFileTypes.XML, text, LocalTimeCounter.currentTime(), false);

  PsiElement element = file.findElementAt(offset);
  if (offset < end && element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_END_TAG_START) {
    return offset;
  }

  int newOffset = -1;
  XmlTag tag = PsiTreeUtil.findElementOfClassAtRange(file, start, end, XmlTag.class);
  if (tag != null) {
    for (PsiElement child : tag.getChildren()) {
      if (child instanceof XmlToken && ((XmlToken)child).getTokenType() == XmlTokenType.XML_END_TAG_START) {
        newOffset = child.getTextOffset();
      }
    }
  }

  if (newOffset >= 0) {
    return newOffset;
  }

  return offset;
}
项目:intellij-ce-playground    文件:TemplateToken.java   
@NotNull
private static XmlFile parseXmlFileInTemplate(@NotNull TemplateImpl template, @NotNull CustomTemplateCallback callback,
                                              @NotNull Map<String, String> attributes) {
  XmlTag dummyRootTag = null;
  String templateString = template.getString();
  final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
  if (!containsAttrsVar(template)) {
    XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.html", HTMLLanguage.INSTANCE, templateString, false, true);
    dummyRootTag = dummyFile.getRootTag();
    if (dummyRootTag != null) {
      addMissingAttributes(dummyRootTag, attributes);
    }
  }

  templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
  XmlFile xmlFile =
    (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
  VirtualFile vFile = xmlFile.getVirtualFile();
  if (vFile != null) {
    vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
  }
  return xmlFile;
}
项目:eddy    文件:LightDocument.java   
@Override
public void insertString(int offset, @NotNull CharSequence s) {
  if (offset < 0) throw new IndexOutOfBoundsException("Wrong offset: " + offset);
  if (offset > getTextLength()) {
    throw new IndexOutOfBoundsException(
      "Wrong offset: " + offset + "; documentLength: " + getTextLength() + "; " + s.subSequence(Math.max(0, s.length() - 20), s.length())
    );
  }
  assertValidSeparators(s);

  if (!isWritable()) throw new ReadOnlyModificationException(this);
  if (s.length() == 0) return;

  updateText(myText.insert(offset, ImmutableText.valueOf(s)), offset, null, s, false, LocalTimeCounter.currentTime());
  trimToSize();
}
项目:eddy    文件:LightDocument.java   
@Override
public void setText(@NotNull final CharSequence text) {
  Runnable runnable = new Runnable() {
    @Override
    public void run() {
      replaceString(0, getTextLength(), text, LocalTimeCounter.currentTime(), true);
    }
  };
  if (CommandProcessor.getInstance().isUndoTransparentActionInProgress()) {
    runnable.run();
  }
  else {
    CommandProcessor.getInstance().executeCommand(null, runnable, "", DocCommandGroupId.noneGroupId(this));
  }

  clearLineModificationFlags();
}
项目:tools-idea    文件:VirtualFileSystemEntry.java   
public VirtualFileSystemEntry(@NotNull String name, VirtualDirectoryImpl parent, int id, @PersistentFS.Attributes int attributes) {
  myParent = parent;
  myId = id;

  storeName(name);

  if (parent != null && parent != VirtualDirectoryImpl.NULL_VIRTUAL_FILE) {
    setFlagInt(IS_SYMLINK_FLAG, PersistentFS.isSymLink(attributes));
    setFlagInt(IS_SPECIAL_FLAG, PersistentFS.isSpecialFile(attributes));
    updateLinkStatus();
  }

  setFlagInt(IS_WRITABLE_FLAG, PersistentFS.isWritable(attributes));
  setFlagInt(IS_HIDDEN_FLAG, PersistentFS.isHidden(attributes));

  setModificationStamp(LocalTimeCounter.currentTime());
}
项目:tools-idea    文件:CharArrayTest.java   
private void init(int size) {
  myArray = new CharArray(size, new char[0], 0) {
    @NotNull
    @Override
    protected DocumentEvent beforeChangedUpdate(int offset, CharSequence oldString, CharSequence newString,
                                                boolean wholeTextReplaced) {
      return new DocumentEventImpl(myDocument, offset, oldString, newString, LocalTimeCounter.currentTime(), wholeTextReplaced);
    }

    @Override
    protected void afterChangedUpdate(@NotNull DocumentEvent event, long newModificationStamp) {
    }

    @Override
    protected void assertWriteAccess() {
    }

    @Override
    protected void assertReadAccess() {
    }
  };
}
项目:tools-idea    文件:DocumentImpl.java   
@Override
public void setText(@NotNull final CharSequence text) {
  Runnable runnable = new Runnable() {
    @Override
    public void run() {
      replaceString(0, getTextLength(), text, LocalTimeCounter.currentTime(), true);
    }
  };
  if (CommandProcessor.getInstance().isUndoTransparentActionInProgress()) {
    runnable.run();
  }
  else {
    CommandProcessor.getInstance().executeCommand(null, runnable, "", DocCommandGroupId.noneGroupId(this));
  }

  clearLineModificationFlags();
}
项目:tools-idea    文件:GenerationNode.java   
private static int gotoChild(Project project, CharSequence text, int offset, int start, int end) {
  PsiFile file = PsiFileFactory.getInstance(project)
    .createFileFromText("dummy.xml", StdFileTypes.XML, text, LocalTimeCounter.currentTime(), false);

  PsiElement element = file.findElementAt(offset);
  if (offset < end && element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_END_TAG_START) {
    return offset;
  }

  int newOffset = -1;
  XmlTag tag = PsiTreeUtil.findElementOfClassAtRange(file, start, end, XmlTag.class);
  if (tag != null) {
    for (PsiElement child : tag.getChildren()) {
      if (child instanceof XmlToken && ((XmlToken)child).getTokenType() == XmlTokenType.XML_END_TAG_START) {
        newOffset = child.getTextOffset();
      }
    }
  }

  if (newOffset >= 0) {
    return newOffset;
  }

  return offset;
}
项目:tools-idea    文件:TemplateToken.java   
@NotNull
private static XmlFile parseXmlFileInTemplate(TemplateImpl template,
                                              CustomTemplateCallback callback,
                                              List<Pair<String, String>> attributes) {
  XmlTag dummyRootTag = null;
  String templateString = template.getString();
  final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
  if (!containsAttrsVar(template)) {
    XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString);
    dummyRootTag = dummyFile.getRootTag();
    if (dummyRootTag != null) {
      addMissingAttributes(dummyRootTag, attributes);
    }
  }

  templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
  XmlFile xmlFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
  VirtualFile vFile = xmlFile.getVirtualFile();
  if (vFile != null) {
    vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
  }
  return xmlFile;
}
项目:consulo    文件:FileDocumentManagerImplTest.java   
@SuppressWarnings("UnusedDeclaration")
public void _testContentChanged_reloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "zzz");
  file.setContent(null, "xxx", false);

  myReloadFromDisk = Boolean.TRUE;
  myDocumentManager.saveAllDocuments();
  long fileStamp = file.getModificationStamp();

  assertEquals("xxx", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertEquals(file.getModificationStamp(), fileStamp);
  assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
}
项目:consulo    文件:TemplateDataElementType.java   
protected PsiFile createPsiFileFromSource(final Language language, CharSequence sourceCode, PsiManager manager) {
  @NonNls final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), sourceCode, LocalTimeCounter.currentTime());

  FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {
    @Override
    @Nonnull
    public Language getBaseLanguage() {
      return language;
    }
  };

  // Since we're already inside a template language PSI that was built regardless of the file size (for whatever reason),
  // there should also be no file size checks for template data files.
  SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);

  return viewProvider.getPsi(language);
}
项目:mule-intellij-plugins    文件:MuleDebuggerEditorsProvider.java   
@NotNull
@Override
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition xSourcePosition, @NotNull EvaluationMode evaluationMode)
{

    final PsiFile psiFile = PsiFileFactory.getInstance(project)
                                          .createFileFromText("muleExpr." + getFileType().getDefaultExtension(), getFileType(), text, LocalTimeCounter.currentTime(), true);
    return PsiDocumentManager.getInstance(project).getDocument(psiFile);
}
项目:mule-intellij-plugins    文件:WeaveDebuggerEditorsProvider.java   
@NotNull
@Override
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition xSourcePosition, @NotNull EvaluationMode evaluationMode) {

    final PsiFile psiFile = PsiFileFactory.getInstance(project)
            .createFileFromText("muleExpr." + getFileType().getDefaultExtension(), getFileType(), text, LocalTimeCounter.currentTime(), true);
    return PsiDocumentManager.getInstance(project).getDocument(psiFile);
}
项目:lua-for-idea    文件:TestUtils.java   
public static PsiFile createPseudoPhysicalFile(final Project project,
                                               final String fileName,
                                               final String text) throws IncorrectOperationException {
  return PsiFileFactory.getInstance(project)
      .createFileFromText(fileName, FileTypeManager.getInstance().getFileTypeByFileName(fileName), text,
          LocalTimeCounter.currentTime(), true);
}
项目:deltahex-intellij-plugin    文件:DeltaHexFileEditor.java   
private void notifyModified() {
    boolean modified = undoHandler.getCommandPosition() != undoHandler.getSyncPoint();
    if (modified != this.modified) {
        this.modified = modified;
        // TODO: Trying to force "modified behavior"
        Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
        if (document instanceof DocumentEx) {
            ((DocumentEx) document).setModificationStamp(LocalTimeCounter.currentTime());
        }
        propertyChangeSupport.firePropertyChange(FileEditor.PROP_MODIFIED, !modified, modified);
        VirtualFileManager.getInstance().notifyPropertyChanged(virtualFile, FileEditor.PROP_MODIFIED, !modified, modified);
    }
    saveFileButton.setEnabled(modified);
}
项目:intellij-ce-playground    文件:JavaLanguageCodeStyleSettingsProvider.java   
@Override
public PsiFile createFileFromText(final Project project, final String text) {
  final PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(
    "sample.java", StdFileTypes.JAVA, text, LocalTimeCounter.currentTime(), true, false
  );
  file.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST);
  return file;
}
项目:intellij-ce-playground    文件:VFileContentChangeEvent.java   
public VFileContentChangeEvent(final Object requestor,
                               @NotNull final VirtualFile file,
                               final long oldModificationStamp,
                               final long newModificationStamp,
                               final boolean isFromRefresh) {
  super(requestor, isFromRefresh);
  myFile = file;
  myOldModificationStamp = oldModificationStamp;
  myNewModificationStamp = newModificationStamp == -1 ? LocalTimeCounter.currentTime() : newModificationStamp;
}
项目:intellij-ce-playground    文件:MockVirtualFile.java   
public void setContent(@Nullable Object requestor, String content, boolean fireEvent) {
  long oldStamp = myModStamp;
  myText = content;
  if (fireEvent) {
    myModStamp = LocalTimeCounter.currentTime();
    myListener.contentsChanged(new VirtualFileEvent(requestor, this, null, oldStamp, myModStamp));
  }
}
项目:intellij-ce-playground    文件:VirtualFileDataImpl.java   
@Override
@NotNull
public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, long newTimeStamp) throws IOException {
  return VfsUtilCore.outputStreamAddingBOM(new ByteArrayOutputStream() {
    @Override
    public void close() {
      final DummyFileSystem fs = (DummyFileSystem)getFileSystem();
      fs.fireBeforeContentsChange(requestor, VirtualFileDataImpl.this);
      final long oldModStamp = myModificationStamp;
      myContents = toByteArray();
      myModificationStamp = newModificationStamp >= 0 ? newModificationStamp : LocalTimeCounter.currentTime();
      fs.fireContentsChanged(requestor, VirtualFileDataImpl.this, oldModStamp);
    }
  },this);
}
项目:intellij-ce-playground    文件:FileDocumentManagerImplTest.java   
public void testContentChanged_doNotReloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file =
  new MockVirtualFile("test.txt", "test") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };

  myReloadFromDisk = Boolean.FALSE;
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "old ");
    }
  });

  long documentStamp = document.getModificationStamp();

  file.setContent(null, "xxx", false);

  myDocumentManager.saveAllDocuments();

  assertEquals("old test", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertEquals("old test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
  assertEquals(documentStamp, document.getModificationStamp());
}
项目:intellij-ce-playground    文件:StructuralSearchProfile.java   
private static PsiFile createFileFragment(SearchContext searchContext, FileType fileType, Language dialect, String text) {
  final String name = "__dummy." + fileType.getDefaultExtension();
  final PsiFileFactory factory = PsiFileFactory.getInstance(searchContext.getProject());

  return dialect == null ?
         factory.createFileFromText(name, fileType, text, LocalTimeCounter.currentTime(), true, true) :
         factory.createFileFromText(name, dialect, text, true, true);
}
项目:intellij-ce-playground    文件:SingleRootFileViewProvider.java   
public void beforeDocumentChanged(@Nullable PsiFile psiCause) {
  PsiFile psiFile = psiCause != null ? psiCause : getPsi(getBaseLanguage());
  if (psiFile instanceof PsiFileImpl && myContent instanceof VirtualFileContent) {
    setContent(new PsiFileContent((PsiFileImpl)psiFile, psiCause == null ? getModificationStamp() : LocalTimeCounter.currentTime()));
    checkLengthConsistency();
  }
}
项目:intellij-ce-playground    文件:CustomAntElementsRegistry.java   
public static PsiFile loadContentAsFile(Project project, InputStream stream, LanguageFileType fileType) throws IOException {
  final StringBuilder builder = new StringBuilder();
  try {
    int nextByte;
    while ((nextByte = stream.read()) >= 0) {
      builder.append((char)nextByte);
    }
  }
  finally {
    stream.close();
  }
  final PsiFileFactory factory = PsiFileFactory.getInstance(project);
  return factory.createFileFromText("_ant_dummy__." + fileType.getDefaultExtension(), fileType, builder, LocalTimeCounter.currentTime(), false, false);
}
项目:intellij-ce-playground    文件:TestUtils.java   
public static PsiFile createPseudoPhysicalFile(final Project project, final String fileName, final String text) throws IncorrectOperationException {
  return PsiFileFactory.getInstance(project).createFileFromText(
      fileName,
      FileTypeManager.getInstance().getFileTypeByFileName(fileName),
      text,
      LocalTimeCounter.currentTime(),
      true);
}
项目:intellij-ce-playground    文件:GenerateTemplateConfigurable.java   
public GenerateTemplateConfigurable(TemplateResource template, Map<String, PsiType> contextMap, Project project, boolean multipleFields) {
  this.template = template;
  final EditorFactory factory = EditorFactory.getInstance();
  Document doc = factory.createDocument(template.getTemplate());
  final FileType ftl = FileTypeManager.getInstance().findFileTypeByName("VTL");
  if (project != null && ftl != null) {
    final PsiFile file = PsiFileFactory.getInstance(project)
        .createFileFromText(template.getFileName(), ftl, template.getTemplate(), LocalTimeCounter.currentTime(), true);
    if (!template.isDefault()) {
      final HashMap<String, PsiType> map = new LinkedHashMap<String, PsiType>();
      map.put("java_version", PsiType.INT);
      map.put("class", TemplatesManager.createElementType(project, ClassElement.class));
      if (multipleFields) {
        map.put("fields", TemplatesManager.createFieldListElementType(project));
      } 
      else {
        map.put("field", TemplatesManager.createElementType(project, FieldElement.class));
      }
      map.put("helper", TemplatesManager.createElementType(project, GenerationHelper.class));
      map.put("settings", PsiType.NULL);
      map.putAll(contextMap);
      availableImplicits.addAll(map.keySet());
      file.getViewProvider().putUserData(TemplatesManager.TEMPLATE_IMPLICITS, map);
    }
    final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
    if (document != null) {
      doc = document;
    }
  }
  myEditor = factory.createEditor(doc, project, ftl != null ? ftl : FileTypes.PLAIN_TEXT, template.isDefault());
}
项目:eddy    文件:LightDocument.java   
@Override
public void deleteString(int startOffset, int endOffset) {
  assertBounds(startOffset, endOffset);

  if (!isWritable()) throw new ReadOnlyModificationException(this);
  if (startOffset == endOffset) return;

  CharSequence sToDelete = myText.subSequence(startOffset, endOffset);

  updateText(myText.delete(startOffset, endOffset), startOffset, sToDelete, null, false, LocalTimeCounter.currentTime());
}
项目:tools-idea    文件:JavaLanguageCodeStyleSettingsProvider.java   
@Override
public PsiFile createFileFromText(final Project project, final String text) {
  final PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(
    "sample.java", StdFileTypes.JAVA, text, LocalTimeCounter.currentTime(), true, false
  );
  file.putUserData(PsiUtil.FILE_LANGUAGE_LEVEL_KEY, LanguageLevel.HIGHEST);
  return file;
}
项目:tools-idea    文件:VFileContentChangeEvent.java   
public VFileContentChangeEvent(final Object requestor,
                               @NotNull final VirtualFile file,
                               final long oldModificationStamp,
                               final long newModificationStamp,
                               final boolean isFromRefresh) {
  super(requestor, isFromRefresh);
  myFile = file;
  myOldModificationStamp = oldModificationStamp;
  myNewModificationStamp = newModificationStamp == -1 ? LocalTimeCounter.currentTime() : newModificationStamp;
}
项目:tools-idea    文件:MockVirtualFile.java   
public void setContent(@Nullable Object requestor, String content, boolean fireEvent) {
  long oldStamp = myModStamp;
  myText = content;
  if (fireEvent) {
    myModStamp = LocalTimeCounter.currentTime();
    myListener.contentsChanged(new VirtualFileEvent(requestor, this, null, oldStamp, myModStamp));
  }
}
项目:tools-idea    文件:VirtualFileDataImpl.java   
@Override
@NotNull
public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, long newTimeStamp) throws IOException {
  return VfsUtilCore.outputStreamAddingBOM(new ByteArrayOutputStream() {
    @Override
    public void close() {
      final DummyFileSystem fs = (DummyFileSystem)getFileSystem();
      fs.fireBeforeContentsChange(requestor, VirtualFileDataImpl.this);
      final long oldModStamp = myModificationStamp;
      myContents = toByteArray();
      myModificationStamp = newModificationStamp >= 0 ? newModificationStamp : LocalTimeCounter.currentTime();
      fs.fireContentsChanged(requestor, VirtualFileDataImpl.this, oldModStamp);
    }
  },this);
}
项目:tools-idea    文件:FileDocumentManagerImplTest.java   
@SuppressWarnings("UnusedDeclaration")
public void _testContentChanged_reloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "zzz");
  file.setContent(null, "xxx", false);

  myDocumentManager.myReloadFromDisk = Boolean.TRUE;
  try {
    myDocumentManager.saveAllDocuments();
    long fileStamp = file.getModificationStamp();

    assertEquals("xxx", document.getText());
    assertEquals(file.getModificationStamp(), document.getModificationStamp());
    assertEquals(file.getModificationStamp(), fileStamp);
    assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
  }
  finally {
    myDocumentManager.myReloadFromDisk = null;
  }
}
项目:tools-idea    文件:FileDocumentManagerImplTest.java   
public void testContentChanged_doNotReloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VirtualFileEvent(null, this, null, oldStamp, getModificationStamp()));
    }
  };

  myDocumentManager.myReloadFromDisk = Boolean.FALSE;
  try {
    Document document = myDocumentManager.getDocument(file);
    assertNotNull(file.toString(), document);
    document.insertString(0, "old ");
    long documentStamp = document.getModificationStamp();

    file.setContent(null, "xxx", false);

    myDocumentManager.saveAllDocuments();

    assertEquals("old test", document.getText());
    assertEquals(file.getModificationStamp(), document.getModificationStamp());
    assertTrue(Arrays.equals("old test".getBytes("UTF-8"), file.contentsToByteArray()));
    assertEquals(documentStamp, document.getModificationStamp());
  }
  finally {
    myDocumentManager.myReloadFromDisk = null;
  }
}
项目:tools-idea    文件:DocumentImpl.java   
public DocumentImpl(@NotNull CharSequence chars, boolean forUseInNonAWTThread) {
  assertValidSeparators(chars);
  myText = new MyCharArray(CharArrayUtil.fromSequence(chars), chars.length());
  myLineSet.documentCreated(this);
  setCyclicBufferSize(0);
  setModificationStamp(LocalTimeCounter.currentTime());
  myAssertThreading = !forUseInNonAWTThread;
}
项目:tools-idea    文件:CharArray.java   
public void remove(int startIndex, int endIndex, @NotNull CharSequence toDelete) {
  DocumentEvent event = startChange(startIndex, toDelete, null, false);
  startIndex += myStart;
  endIndex += myStart;
  doRemove(startIndex, endIndex);
  afterChangedUpdate(event, LocalTimeCounter.currentTime());
  assertConsistency();
}
项目:tools-idea    文件:CharArray.java   
public void insert(@NotNull CharSequence s, int startIndex) {
  DocumentEvent event = startChange(startIndex, null, s, false);
  startIndex += myStart;
  doInsert(s, startIndex);

  afterChangedUpdate(event, LocalTimeCounter.currentTime());
  trimToSize();
  assertConsistency();
}
项目:tools-idea    文件:TemplateDataElementType.java   
protected PsiFile createFromText(final Language language, CharSequence text, PsiManager manager) {
  @NonNls
  final LightVirtualFile virtualFile = new LightVirtualFile("foo", createTemplateFakeFileType(language), text, LocalTimeCounter.currentTime());

  FileViewProvider viewProvider = new SingleRootFileViewProvider(manager, virtualFile, false) {
    @Override
    @NotNull
    public Language getBaseLanguage() {
      return language;
    }
  };

  return viewProvider.getPsi(language);
}