com.intellij.util.LocalTimeCounter Java Examples

The following examples show how to use com.intellij.util.LocalTimeCounter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemplateDataElementType.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: VFileContentChangeEvent.java    From consulo with Apache License 2.0 6 votes vote down vote up
public VFileContentChangeEvent(Object requestor,
                               @Nonnull VirtualFile file,
                               long oldModificationStamp,
                               long newModificationStamp,
                               long oldTimestamp,
                               long newTimestamp,
                               long oldLength,
                               long newLength,
                               boolean isFromRefresh) {
  super(requestor, isFromRefresh);
  myFile = file;
  myOldModificationStamp = oldModificationStamp;
  myNewModificationStamp = newModificationStamp == -1 ? LocalTimeCounter.currentTime() : newModificationStamp;
  myOldTimestamp = oldTimestamp;
  myNewTimestamp = newTimestamp;
  myOldLength = oldLength;
  myNewLength = newLength;
}
 
Example #3
Source File: FileDocumentManagerImplTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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 VFileContentChangeEvent(null, this, oldStamp, getModificationStamp(), true));
    }
  };
  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);
}
 
Example #4
Source File: WeaveDebuggerEditorsProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: VirtualFileDataImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
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);
}
 
Example #6
Source File: FileDocumentManagerImplTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
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 VFileContentChangeEvent(null, this, oldStamp, getModificationStamp(), true));
    }
  };

  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());
  assertTrue(Arrays.equals("old test".getBytes("UTF-8"), file.contentsToByteArray()));
  assertEquals(documentStamp, document.getModificationStamp());
}
 
Example #7
Source File: MuleDebuggerEditorsProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: HaxeFindUsagesTest.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public void compareExpectedUsages(Collection<UsageInfo> foundUsages) {

    assertNotNull(foundUsages);

    // Need to keep the ordering constant, so sort the output.
    String[] formattedUsages = new String[foundUsages.size()];
    int i = 0;
    for (UsageInfo usage : foundUsages) {
      formattedUsages[i++] = prettyUsageMessage(usage);
    }
    Arrays.sort(formattedUsages, new Comparator<String>() {
      @Override
      public int compare(String o1, String o2) {
        return o1.compareTo(o2);
      }
    });

    StringBuilder builder = new StringBuilder();
    for (String s : formattedUsages) {
      builder.append(s);
      builder.append('\n');
    }

    // Convert the output to a file.  MUST use an API that sets eventSystemEnabled==true, or the file won't open.
    PsiFile foundFile = PsiFileFactory.getInstance(myFixture.getProject())
      .createFileFromText("testResult", FileTypes.PLAIN_TEXT, builder.toString(),
                          LocalTimeCounter.currentTime(), true);
    VirtualFile vFile = foundFile.getViewProvider().getVirtualFile();

    myFixture.openFileInEditor(vFile); // Can't use foundFile.getVirtualFile(); it returns null.
    myFixture.checkResultByFile(getResultsPath(), false);
  }
 
Example #9
Source File: MockVirtualFile.java    From consulo with Apache License 2.0 5 votes vote down vote up
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));
  }
}
 
Example #10
Source File: LightVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LightVirtualFile(@NonNls @Nonnull String name, @Nonnull CharSequence content) {
  this(name, null, content, LocalTimeCounter.currentTime());
}
 
Example #11
Source File: CodeStyleAbstractPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected PsiFile createFileFromText(Project project, String text) {
  return PsiFileFactory.getInstance(project).createFileFromText(
          "a." + getFileExt(), getFileType(), text, LocalTimeCounter.currentTime(), true
  );
}
 
Example #12
Source File: PsiFileFactoryImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public PsiFile createFileFromText(@Nonnull String name, @Nonnull FileType fileType, @Nonnull CharSequence text) {
  return createFileFromText(name, fileType, text, LocalTimeCounter.currentTime(), false);
}
 
Example #13
Source File: DummyHolderViewProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DummyHolderViewProvider(@Nonnull PsiManager manager) {
  super(manager, new LightVirtualFile("DummyHolder", UnknownFileType.INSTANCE, ""), false);
  myModificationStamp = LocalTimeCounter.currentTime();
}
 
Example #14
Source File: AbstractFileViewProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void rootChanged(@Nonnull PsiFile psiFile) {
  if (psiFile instanceof PsiFileImpl && ((PsiFileImpl)psiFile).isContentsLoaded() && psiFile.isValid()) {
    setContent(new PsiFileContent(((PsiFileImpl)psiFile).calcTreeElement(), LocalTimeCounter.currentTime()));
  }
}
 
Example #15
Source File: NoSqlDatabaseObjectFile.java    From nosql4idea with Apache License 2.0 4 votes vote down vote up
protected NoSqlDatabaseObjectFile(Project project, ServerConfiguration configuration, String name) {
    this.project = project;
    this.configuration = configuration;
    this.name = name;
    this.myModStamp = LocalTimeCounter.currentTime();
}
 
Example #16
Source File: TempFileSystem.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected FSItem(final FSDir parent, final String name) {
  myParent = parent;
  myName = name;
  myTimestamp = LocalTimeCounter.currentTime();
  myWritable = true;
}
 
Example #17
Source File: LightVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setContent(Object requestor, @Nonnull CharSequence content, boolean fireEvent) {
  setContent(content);
  setModificationStamp(LocalTimeCounter.currentTime());
}
 
Example #18
Source File: LightVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LightVirtualFile(@Nonnull String name, final Language language, @Nonnull CharSequence text) {
  super(name, null, LocalTimeCounter.currentTime());
  setContent(text);
  setLanguage(language);
}
 
Example #19
Source File: LightVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public LightVirtualFile(@Nonnull String name, final FileType fileType, @Nonnull CharSequence text) {
  this(name, fileType, text, LocalTimeCounter.currentTime());
}
 
Example #20
Source File: BinaryLightVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setContent(Object requestor, byte[] content, boolean fireEvent) {
  setContent(content);
  setModificationStamp(LocalTimeCounter.currentTime());
}
 
Example #21
Source File: BinaryLightVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public BinaryLightVirtualFile(final String name, final FileType fileType, final byte[] content) {
  this(name, fileType, content, LocalTimeCounter.currentTime());
}
 
Example #22
Source File: BinaryLightVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
public BinaryLightVirtualFile(@NonNls String name, byte[] content) {
  this(name, null, content, LocalTimeCounter.currentTime());
}
 
Example #23
Source File: FormatterTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void doSanityTestForFile(final File subFile, final List<File> failedFiles, final boolean formatWithPsi)
  throws IOException, IncorrectOperationException {
  if (subFile.isFile() && subFile.getName().endsWith(getFileExtension())) {
    final byte[] bytes = FileUtil.loadFileBytes(subFile);
    final String text = new String(bytes);
    final String fileName = "before." + getFileExtension();
    final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, getFileType(fileName), StringUtil.convertLineSeparators(text), LocalTimeCounter.currentTime(), true);

    try {
      CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
        @Override
        public void run() {
          ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
              try {
                if (formatWithPsi) {
                  performFormatting(file);
                }
                else {
                  performFormattingWithDocument(file);
                }
              }
              catch (Throwable e) {
                //noinspection CallToPrintStackTrace
                e.printStackTrace();
                failedFiles.add(subFile);
              }
              //noinspection UseOfSystemOutOrSystemErr
              System.out.println(subFile.getPath() + ": finished");
            }
          });
        }
      }, "", null);
    }
    finally {
      final VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile != null) {
        ((UndoManagerImpl)UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(virtualFile);
        ((UndoManagerImpl)UndoManager.getGlobalInstance()).clearUndoRedoQueueInTests(virtualFile);
      }
    }
  }
}
 
Example #24
Source File: FormatterTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected PsiFile createFileFromText(String text, String fileName, final PsiFileFactory fileFactory) {
  return fileFactory.createFileFromText(fileName, getFileType(fileName), text, LocalTimeCounter.currentTime(), true, false);
}
 
Example #25
Source File: XQueryElementFactory.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public static XQueryFile createPhysicalFile(Project project, String text) {
    String name = "dummy.xq";
    return (XQueryFile) PsiFileFactory.getInstance(project).
            createFileFromText(name, XQueryFileType.INSTANCE, text, LocalTimeCounter.currentTime(), true);
}
 
Example #26
Source File: MockDocument.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void replaceString(int startOffset, int endOffset, @Nonnull CharSequence s) {
  myText.replace(startOffset, endOffset, s.toString());
  myModStamp = LocalTimeCounter.currentTime();
}
 
Example #27
Source File: LightPlatformTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static PsiFile createLightFile(@NonNls String fileName, String text) throws IncorrectOperationException {
  FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
  return PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, fileType, text, LocalTimeCounter.currentTime(), false, false);
}
 
Example #28
Source File: LightPlatformTestCase.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * Creates dummy source file. One is not placed under source root so some PSI functions like resolve to external classes
 * may not work. Though it works significantly faster and yet can be used if you need to create some PSI structures for
 * test purposes
 *
 * @param fileName - name of the file to create. Extension is used to choose what PSI should be created like java, jsp, aj, xml etc.
 * @param text     - file text.
 * @return dummy psi file.
 * @throws com.intellij.util.IncorrectOperationException
 */
protected static PsiFile createFile(@NonNls String fileName, @NonNls String text) throws IncorrectOperationException {
  FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
  return PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, fileType, text, LocalTimeCounter.currentTime(), true, false);
}