Java 类com.intellij.openapi.util.Clock 实例源码

项目:intellij-ce-playground    文件:IdeaGateway.java   
@NotNull
public Pair<StoredContent, Long> acquireAndClearCurrentContent(@NotNull VirtualFile f, @Nullable Document d) {
  ContentAndTimestamps contentAndStamp = f.getUserData(SAVED_DOCUMENT_CONTENT_AND_STAMP_KEY);
  f.putUserData(SAVED_DOCUMENT_CONTENT_AND_STAMP_KEY, null);

  if (d != null && contentAndStamp != null) {
    // if previously stored content was not changed, return it
    if (d.getModificationStamp() == contentAndStamp.documentModificationStamp) {
      return Pair.create(contentAndStamp.content, contentAndStamp.registeredTimestamp);
    }
  }

  // release previously stored
  if (contentAndStamp != null) {
    contentAndStamp.content.release();
  }

  // take document's content if any
  if (d != null) {
    return Pair.create(StoredContent.acquireContent(bytesFromDocument(d)), Clock.getTime());
  }

  return Pair.create(StoredContent.acquireContent(f), f.getTimeStamp());
}
项目:intellij-ce-playground    文件:LocalHistoryStorage.java   
public int createNextRecord() throws IOException {
  synchronized (myLock) {
    LocalHistoryRecordsTable table = (LocalHistoryRecordsTable)myRecordsTable;
    int id = table.createNewRecord();
    int prev = table.getLastRecord();

    if (prev > 0) {
      table.setPrevRecord(id, prev);
      table.setNextRecord(prev, id);
    }
    else {
      table.setFirstRecord(id);
    }
    table.setLastRecord(id);

    table.setTimestamp(id, Clock.getTime());

    return id;
  }
}
项目:intellij-ce-playground    文件:ModifierKeyDoubleClickHandlerTest.java   
private void key(int repeat) {
  for (int i = 0; i < repeat; i++) {
    IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent,
                                                           KeyEvent.KEY_PRESSED,
                                                           Clock.getTime(),
                                                           InputEvent.SHIFT_MASK,
                                                           KeyEvent.VK_BACK_SPACE,
                                                           '\b'));
    IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent,
                                                           KeyEvent.KEY_TYPED,
                                                           Clock.getTime(),
                                                           InputEvent.SHIFT_MASK,
                                                           0,
                                                           '\b'));
  }
  IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent,
                                                         KeyEvent.KEY_RELEASED,
                                                         Clock.getTime(),
                                                         InputEvent.SHIFT_MASK,
                                                         KeyEvent.VK_BACK_SPACE,
                                                         '\b'));
}
项目:intellij-ce-playground    文件:IntegrationTestCase.java   
@Override
public void setUp() throws Exception {
  super.setUp();

  LocalHistoryImpl.getInstanceImpl().cleanupForNextTest();

  Clock.reset();
  Paths.useSystemCaseSensitivity();

  myGateway = new IdeaGateway();

  ApplicationManager.getApplication().runWriteAction(new RunnableAdapter() {
    @Override
    public void doRun() throws Exception {
      setUpInWriteAction();
    }
  });
}
项目:intellij-ce-playground    文件:RevisionsAndDiffsTest.java   
public void testIncludingCurrentVersionIntoRevisionsAfterPurge() throws Exception {
  Clock.setTime(10);
  VirtualFile f = createFile("file.txt", "content");
  loadContent(f);
  getVcs().getChangeListInTests().purgeObsolete(0);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(1, rr.size());

  Revision r = rr.get(0);
  assertNull(r.getLabel());
  assertNull(r.getChangeSetName());
  assertEquals(f.getTimeStamp(), r.getTimestamp());

  Entry e = r.findEntry();
  assertEquals("file.txt", e.getName());
  assertContent("content", e);
}
项目:intellij-ce-playground    文件:RevisionsAndDiffsTest.java   
public void testCurrentRevisionForDirectoryAfterPurge() throws Exception {
  Clock.setTime(10);
  VirtualFile f = createDirectory("dir");
  getVcs().getChangeListInTests().purgeObsolete(0);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(1, rr.size());

  Revision r = rr.get(0);
  assertNull(r.getLabel());
  assertNull(r.getChangeSetName());
  assertEquals(-1, r.getTimestamp()); // directory has no timestamp

  Entry e = r.findEntry();
  assertEquals("dir", e.getName());
}
项目:intellij-ce-playground    文件:RevisionsAndDiffsTest.java   
public void testTimestampForLastRevisionAfterPurge() throws IOException {
  Clock.setTime(10);
  VirtualFile f = createFile("file1.txt");

  Clock.setTime(20);
  setContent(f, "a");

  Clock.setTime(30);
  setContent(f, "b");

  getVcs().getChangeListInTests().purgeObsolete(15);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(30L, rr.get(1).getTimestamp());
  assertEquals(20L, rr.get(2).getTimestamp());
}
项目:intellij-ce-playground    文件:DateFormatUtilTest.java   
@Test
public void testTime() throws Exception {
  Clock.setTime(2004, Calendar.DECEMBER, 10, 17, 10, 15);

  if (SystemInfo.isMac) {
    assertEquals("17:10", DateFormatUtil.formatTime(Clock.getTime()));
    assertEquals("17:10:15", DateFormatUtil.formatTimeWithSeconds(Clock.getTime()));
  }
  else if (SystemInfo.isUnix) {
    assertEquals("5:10:15 PM", printTimeForLocale("en_US.UTF-8", Clock.getTime()));
    assertEquals("17:10:15", printTimeForLocale("de_DE.UTF-8", Clock.getTime()));
  }
  else if (SystemInfo.isWinVistaOrNewer) {
    GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    c.set(2004, Calendar.DECEMBER, 10, 17, 10, 15);
    assertEquals(printWindowsTime(c.getTimeInMillis()), DateFormatUtil.formatTimeWithSeconds(Clock.getTime()));
  }
  else {
    assertEquals(DateFormat.getTimeInstance(DateFormat.SHORT).format(Clock.getTime()),
                 DateFormatUtil.formatTime(Clock.getTime()));
    assertEquals(DateFormat.getTimeInstance(DateFormat.MEDIUM).format(Clock.getTime()),
                 DateFormatUtil.formatTimeWithSeconds(new Date(Clock.getTime())));
  }
}
项目:intellij-ce-playground    文件:CurrentDateMacro.java   
static String formatUserDefined(Expression[] params, ExpressionContext context, boolean date) {
  long time = Clock.getTime();
  if (params.length == 1) {
    Result format = params[0].calculateResult(context);
    if (format != null) {
      String pattern = format.toString();
      try {
        return new SimpleDateFormat(pattern).format(new Date(time));
      }
      catch (Exception e) {
        return "Problem when formatting date/time for pattern \"" + pattern + "\": " + e.getMessage();
      }
    }
  }
  return date ? DateFormatUtil.formatDate(time) : DateFormatUtil.formatTime(time);
}
项目:intellij-ce-playground    文件:AntBuildMessageView.java   
private String getFinishStatusText(boolean isAborted, long buildTimeInMilliseconds) {
  final String theDateAsString = DateFormatUtil.formatDateTime(Clock.getTime());
  final String formattedBuildTime = formatBuildTime(buildTimeInMilliseconds / 1000);
  if (isAborted) {
    return AntBundle.message("build.finished.status.ant.build.aborted", formattedBuildTime, theDateAsString);
  }
  final int errors = getErrorCount();
  final int warnings = getWarningCount();
  if (errors == 0 && warnings == 0) {
    return AntBundle.message("build.finished.status.ant.build.completed.successfully", formattedBuildTime, theDateAsString);
  }
  if (errors == 0) {
    return AntBundle.message("build.finished.status.ant.build.completed.with.warnings", warnings, formattedBuildTime, theDateAsString);
  }
  return AntBundle.message("build.finished.status.ant.build.completed.with.errors.warnings", errors, warnings, formattedBuildTime, theDateAsString);
}
项目:intellij-ce-playground    文件:GitPreservingProcess.java   
public GitPreservingProcess(@NotNull Project project,
                            @NotNull GitPlatformFacade facade,
                            @NotNull Git git,
                            @NotNull Collection<VirtualFile> rootsToSave,
                            @NotNull String operationTitle,
                            @NotNull String destinationName,
                            @NotNull GitVcsSettings.UpdateChangesPolicy saveMethod,
                            @NotNull ProgressIndicator indicator,
                            @NotNull Runnable operation) {
  myProject = project;
  myFacade = facade;
  myGit = git;
  myRootsToSave = rootsToSave;
  myOperationTitle = operationTitle;
  myDestinationName = destinationName;
  myProgressIndicator = indicator;
  myOperation = operation;
  myStashMessage = String.format("Uncommitted changes before %s at %s", StringUtil.capitalize(myOperationTitle),
                                 DateFormatUtil.formatDateTime(Clock.getTime()));
  mySaver = configureSaver(saveMethod);
}
项目:intellij-ce-playground    文件:HgAnnotationTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  Calendar calendar = Calendar.getInstance();
  calendar.set(2005, Calendar.DECEMBER, 24, 15, 10);
  Date time = calendar.getTime();
  Clock.setTime(time);
  cd(myRepository);
  String dateArg = " -d '" + DATE_FORMAT.format(time) + "'";
  echo(firstCreatedFile, "a\n");
  hg("commit -m modify -u '" + defaultAuthor + "'" + dateArg);
  echo(firstCreatedFile, "b\n");
  hg("commit -m modify1 -u " + author1 + dateArg);
  echo(firstCreatedFile, "c\n");
  hg("commit -m modify2 -u " + author2 + dateArg);
}
项目:tools-idea    文件:IdeaGateway.java   
@NotNull
public Pair<StoredContent, Long> acquireAndClearCurrentContent(@NotNull VirtualFile f, @Nullable Document d) {
  ContentAndTimestamps contentAndStamp = f.getUserData(SAVED_DOCUMENT_CONTENT_AND_STAMP_KEY);
  f.putUserData(SAVED_DOCUMENT_CONTENT_AND_STAMP_KEY, null);

  if (d != null && contentAndStamp != null) {
    // if previously stored content was not changed, return it
    if (d.getModificationStamp() == contentAndStamp.documentModificationStamp) {
      return Pair.create(contentAndStamp.content, contentAndStamp.registeredTimestamp);
    }
  }

  // release previously stored
  if (contentAndStamp != null) {
    contentAndStamp.content.release();
  }

  // take document's content if any
  if (d != null) {
    return Pair.create(StoredContent.acquireContent(bytesFromDocument(d)), Clock.getTime());
  }

  return Pair.create(StoredContent.acquireContent(f), f.getTimeStamp());
}
项目:tools-idea    文件:LocalHistoryStorage.java   
public int createNextRecord() throws IOException {
  synchronized (myLock) {
    LocalHistoryRecordsTable table = (LocalHistoryRecordsTable)myRecordsTable;
    int id = table.createNewRecord();
    int prev = table.getLastRecord();

    if (prev > 0) {
      table.setPrevRecord(id, prev);
      table.setNextRecord(prev, id);
    }
    else {
      table.setFirstRecord(id);
    }
    table.setLastRecord(id);

    table.setTimestamp(id, Clock.getTime());

    return id;
  }
}
项目:tools-idea    文件:RevisionsAndDiffsTest.java   
public void testIncludingCurrentVersionIntoRevisionsAfterPurge() throws Exception {
  Clock.setTime(10);
  VirtualFile f = createFile("file.txt", "content");
  getVcs().getChangeListInTests().purgeObsolete(0);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(1, rr.size());

  Revision r = rr.get(0);
  assertNull(r.getLabel());
  assertNull(r.getChangeSetName());
  assertEquals(f.getTimeStamp(), r.getTimestamp());

  Entry e = r.findEntry();
  assertEquals("file.txt", e.getName());
  assertContent("content", e);
}
项目:tools-idea    文件:RevisionsAndDiffsTest.java   
public void testCurrentRevisionForDirectoryAfterPurge() throws Exception {
  Clock.setTime(10);
  VirtualFile f = createDirectory("dir");
  getVcs().getChangeListInTests().purgeObsolete(0);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(1, rr.size());

  Revision r = rr.get(0);
  assertNull(r.getLabel());
  assertNull(r.getChangeSetName());
  assertEquals(-1, r.getTimestamp()); // directory has no timestamp

  Entry e = r.findEntry();
  assertEquals("dir", e.getName());
}
项目:tools-idea    文件:RevisionsAndDiffsTest.java   
public void testTimestampForLastRevisionAfterPurge() throws IOException {
  Clock.setTime(10);
  VirtualFile f = createFile("file1.txt");

  Clock.setTime(20);
  setContent(f, "a");

  Clock.setTime(30);
  setContent(f, "b");

  getVcs().getChangeListInTests().purgeObsolete(15);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(30L, rr.get(1).getTimestamp());
  assertEquals(20L, rr.get(2).getTimestamp());
}
项目:tools-idea    文件:DateFormatUtilTest.java   
public void testPrettyDateTime() throws ParseException {
  Clock.setTime(2004, 11, 10, 17, 0);

  doTestDateTime("Moments ago", "10.12.2004 16.59.31");
  doTestDateTime("A minute ago", "10.12.2004 16.59.29");
  doTestDateTime("5 minutes ago", "10.12.2004 16.55.00");
  doTestDateTime("1 hour ago", "10.12.2004 16.00.00");
  doTestDateTime("Today " + DateFormatUtil.formatTime(DATE_FORMAT.parse("10.12.2004 15.55.00")), "10.12.2004 15.55.00");
  doTestDateTime("Yesterday " + DateFormatUtil.formatTime(DATE_FORMAT.parse("09.12.2004 15.00.00")), "09.12.2004 15.00.00");

  doTestDateTime(DateFormatUtil.formatDateTime(DATE_FORMAT.parse("08.12.2004 15.00.00")), "08.12.2004 15.00.00");
  doTestDateTime(DateFormatUtil.formatDateTime(DATE_FORMAT.parse("07.12.2004 15.00.00")), "07.12.2004 15.00.00");

  doTestDateTime("Today " + DateFormatUtil.formatTime(DATE_FORMAT.parse("10.12.2004 19.00.00")), "10.12.2004 19.00.00");

  Clock.setTime(2004, 0, 1, 15, 53);
  doTestDateTime(DateFormatUtil.formatDateTime(DATE_FORMAT.parse("01.01.2003 15.53.00")), "01.01.2003 15.53.00");
  doTestDateTime("Yesterday " + DateFormatUtil.formatTime(DATE_FORMAT.parse("31.12.2003 15.00.00")), "31.12.2003 15.00.00");
}
项目:tools-idea    文件:CurrentDateMacro.java   
static String formatUserDefined(Expression[] params, ExpressionContext context, boolean date) {
  long time = Clock.getTime();
  if (params.length == 1) {
    Result format = params[0].calculateResult(context);
    if (format != null) {
      String pattern = format.toString();
      try {
        return new SimpleDateFormat(pattern).format(new Date(time));
      }
      catch (Exception e) {
        return "Problem when formatting date/time for pattern \"" + pattern + "\": " + e.getMessage();
      }
    }
  }
  return date ? DateFormatUtil.formatDate(time) : DateFormatUtil.formatTime(time);
}
项目:tools-idea    文件:AntBuildMessageView.java   
public String getFinishStatusText(boolean isAborted, long buildTimeInMilliseconds) {
  int errors = getErrorCount();
  int warnings = getWarningCount();
  final String theDateAsString = DateFormatUtil.formatDateTime(Clock.getTime());

  String formattedBuildTime = formatBuildTime(buildTimeInMilliseconds / 1000);

  if (isAborted) {
    return AntBundle.message("build.finished.status.ant.build.aborted", formattedBuildTime, theDateAsString);
  }
  else if (errors == 0 && warnings == 0) {
    return AntBundle.message("build.finished.status.ant.build.completed.successfully", formattedBuildTime, theDateAsString);
  }
  else if (errors == 0) {
    return AntBundle.message("build.finished.status.ant.build.completed.with.warnings", warnings, formattedBuildTime, theDateAsString);
  }
  else {
    return AntBundle
      .message("build.finished.status.ant.build.completed.with.errors.warnings", errors, warnings, formattedBuildTime, theDateAsString);
  }
}
项目:consulo-apache-ant    文件:AntBuildMessageView.java   
public String getFinishStatusText(boolean isAborted, long buildTimeInMilliseconds) {
  int errors = getErrorCount();
  int warnings = getWarningCount();
  final String theDateAsString = DateFormatUtil.formatDateTime(Clock.getTime());

  String formattedBuildTime = formatBuildTime(buildTimeInMilliseconds / 1000);

  if (isAborted) {
    return AntBundle.message("build.finished.status.ant.build.aborted", formattedBuildTime, theDateAsString);
  }
  else if (errors == 0 && warnings == 0) {
    return AntBundle.message("build.finished.status.ant.build.completed.successfully", formattedBuildTime, theDateAsString);
  }
  else if (errors == 0) {
    return AntBundle.message("build.finished.status.ant.build.completed.with.warnings", warnings, formattedBuildTime, theDateAsString);
  }
  else {
    return AntBundle
      .message("build.finished.status.ant.build.completed.with.errors.warnings", errors, warnings, formattedBuildTime, theDateAsString);
  }
}
项目:consulo    文件:IdeaGateway.java   
@Nonnull
public Pair<StoredContent, Long> acquireAndClearCurrentContent(@Nonnull VirtualFile f, @Nullable Document d) {
  ContentAndTimestamps contentAndStamp = f.getUserData(SAVED_DOCUMENT_CONTENT_AND_STAMP_KEY);
  f.putUserData(SAVED_DOCUMENT_CONTENT_AND_STAMP_KEY, null);

  if (d != null && contentAndStamp != null) {
    // if previously stored content was not changed, return it
    if (d.getModificationStamp() == contentAndStamp.documentModificationStamp) {
      return Pair.create(contentAndStamp.content, contentAndStamp.registeredTimestamp);
    }
  }

  // release previously stored
  if (contentAndStamp != null) {
    contentAndStamp.content.release();
  }

  // take document's content if any
  if (d != null) {
    return Pair.create(StoredContent.acquireContent(bytesFromDocument(d)), Clock.getTime());
  }

  return Pair.create(StoredContent.acquireContent(f), f.getTimeStamp());
}
项目:consulo    文件:LocalHistoryStorage.java   
public int createNextRecord() throws IOException {
  synchronized (myLock) {
    LocalHistoryRecordsTable table = (LocalHistoryRecordsTable)myRecordsTable;
    int id = table.createNewRecord();
    int prev = table.getLastRecord();

    if (prev > 0) {
      table.setPrevRecord(id, prev);
      table.setNextRecord(prev, id);
    }
    else {
      table.setFirstRecord(id);
    }
    table.setLastRecord(id);

    table.setTimestamp(id, Clock.getTime());

    return id;
  }
}
项目:consulo    文件:DateFormatUtilTest.java   
@Test
public void testTime() throws Exception {
  Clock.setTime(2004, Calendar.DECEMBER, 10, 17, 10, 15);

  if (SystemInfo.isMac) {
    assertEquals("17:10", DateFormatUtil.formatTime(Clock.getTime()));
    assertEquals("17:10:15", DateFormatUtil.formatTimeWithSeconds(Clock.getTime()));
  }
  else if (SystemInfo.isUnix) {
    assertEquals("5:10:15 PM", printTimeForLocale("en_US.UTF-8", Clock.getTime()));
    assertEquals("17:10:15", printTimeForLocale("de_DE.UTF-8", Clock.getTime()));
  }
  else if (SystemInfo.isWinVistaOrNewer) {
    GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    c.set(2004, Calendar.DECEMBER, 10, 17, 10, 15);
    assertEquals(printWindowsTime(c.getTimeInMillis()), DateFormatUtil.formatTimeWithSeconds(Clock.getTime()));
  }
  else {
    assertEquals(DateFormat.getTimeInstance(DateFormat.SHORT).format(Clock.getTime()),
                 DateFormatUtil.formatTime(Clock.getTime()));
    assertEquals(DateFormat.getTimeInstance(DateFormat.MEDIUM).format(Clock.getTime()),
                 DateFormatUtil.formatTimeWithSeconds(new Date(Clock.getTime())));
  }
}
项目:consulo    文件:RevisionsAndDiffsTest.java   
public void testIncludingCurrentVersionIntoRevisionsAfterPurge() throws Exception {
  Clock.setTime(10);
  VirtualFile f = createFile("file.txt", "content");
  getVcs().getChangeListInTests().purgeObsolete(0);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(1, rr.size());

  Revision r = rr.get(0);
  assertNull(r.getLabel());
  assertNull(r.getChangeSetName());
  assertEquals(f.getTimeStamp(), r.getTimestamp());

  Entry e = r.findEntry();
  assertEquals("file.txt", e.getName());
  assertContent("content", e);
}
项目:consulo    文件:RevisionsAndDiffsTest.java   
public void testCurrentRevisionForDirectoryAfterPurge() throws Exception {
  Clock.setTime(10);
  VirtualFile f = createDirectory("dir");
  getVcs().getChangeListInTests().purgeObsolete(0);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(1, rr.size());

  Revision r = rr.get(0);
  assertNull(r.getLabel());
  assertNull(r.getChangeSetName());
  assertEquals(-1, r.getTimestamp()); // directory has no timestamp

  Entry e = r.findEntry();
  assertEquals("dir", e.getName());
}
项目:consulo    文件:RevisionsAndDiffsTest.java   
public void testTimestampForLastRevisionAfterPurge() throws IOException {
  Clock.setTime(10);
  VirtualFile f = createFile("file1.txt");

  Clock.setTime(20);
  setContent(f, "a");

  Clock.setTime(30);
  setContent(f, "b");

  getVcs().getChangeListInTests().purgeObsolete(15);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(30L, rr.get(1).getTimestamp());
  assertEquals(20L, rr.get(2).getTimestamp());
}
项目:consulo    文件:CurrentDateMacro.java   
static String formatUserDefined(Expression[] params, ExpressionContext context, boolean date) {
  long time = Clock.getTime();
  if (params.length == 1) {
    Result format = params[0].calculateResult(context);
    if (format != null) {
      String pattern = format.toString();
      try {
        return new SimpleDateFormat(pattern).format(new Date(time));
      }
      catch (Exception e) {
        return "Problem when formatting date/time for pattern \"" + pattern + "\": " + e.getMessage();
      }
    }
  }
  return date ? DateFormatUtil.formatDate(time) : DateFormatUtil.formatTime(time);
}
项目:intellij-ce-playground    文件:PackageFileAction.java   
private static void setStatusText(Project project, List<VirtualFile> files) {
  if (!files.isEmpty()) {
    StringBuilder fileNames = new StringBuilder();
    for (VirtualFile file : files) {
      if (fileNames.length() != 0) fileNames.append(", ");
      fileNames.append("'").append(file.getName()).append("'");
    }
    String time = TIME_FORMAT.format(Clock.getTime());
    final String statusText = CompilerBundle.message("status.text.file.has.been.packaged", files.size(), fileNames, time);
    final StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
    if (statusBar != null) {
      statusBar.setInfo(statusText);
    }
  }
}
项目:intellij-ce-playground    文件:LocalHistoryImpl.java   
private void validateStorage() {
  if (ApplicationManager.getApplication().isInternal() && !ApplicationManager.getApplication().isUnitTestMode()) {
    LocalHistoryLog.LOG.info("Checking local history storage...");
    try {
      long before = Clock.getTime();
      myVcs.getChangeListInTests().getChangesInTests();
      LocalHistoryLog.LOG.info("Local history storage seems to be ok (took " + ((Clock.getTime() - before) / 1000) + " sec)");
    }
    catch (Exception e) {
      LocalHistoryLog.LOG.error(e);
    }
  }
}
项目:intellij-ce-playground    文件:ModifierKeyDoubleClickHandler.java   
@Override
public boolean dispatch(AWTEvent event) {
  if (event instanceof KeyEvent) {
    final KeyEvent keyEvent = (KeyEvent)event;
    final int keyCode = keyEvent.getKeyCode();

    if (keyCode == myModifierKeyCode) {
      if (hasOtherModifiers(keyEvent)) {
        resetState();
        return false;
      }
      if (myActionKeyCode == -1 && ourOtherKeyWasPressed.get() && Clock.getTime() - ourLastTimePressed.get() < 500) {
        resetState();
        return false;
      }
      ourOtherKeyWasPressed.set(false);
      if (ourPressed.first.get() && Clock.getTime() - ourLastTimePressed.get() > 500) {
        resetState();
      }
      handleModifier((KeyEvent)event);
      return false;
    } else if (ourPressed.first.get() && ourReleased.first.get() && ourPressed.second.get() && myActionKeyCode != -1) {
      if (keyCode == myActionKeyCode) {
        if (event.getID() == KeyEvent.KEY_PRESSED) {
          run(keyEvent);
        }
        return true;
      }
      return false;
    } else {
      ourLastTimePressed.set(Clock.getTime());
      ourOtherKeyWasPressed.set(true);
      if (keyCode == KeyEvent.VK_ESCAPE || keyCode == KeyEvent.VK_TAB)  {
        ourLastTimePressed.set(0);
      }
    }
    resetState();
  }
  return false;
}
项目:intellij-ce-playground    文件:ModifierKeyDoubleClickHandler.java   
private void handleModifier(KeyEvent event) {
  if (ourPressed.first.get() && Clock.getTime() - ourLastTimePressed.get() > 300) {
    resetState();
    return;
  }

  if (event.getID() == KeyEvent.KEY_PRESSED) {
    if (!ourPressed.first.get()) {
      resetState();
      ourPressed.first.set(true);
      ourLastTimePressed.set(Clock.getTime());
      return;
    } else {
      if (ourPressed.first.get() && ourReleased.first.get()) {
        ourPressed.second.set(true);
        ourLastTimePressed.set(Clock.getTime());
        return;
      }
    }
  } else if (event.getID() == KeyEvent.KEY_RELEASED) {
    if (ourPressed.first.get() && !ourReleased.first.get()) {
      ourReleased.first.set(true);
      ourLastTimePressed.set(Clock.getTime());
      return;
    } else if (ourPressed.first.get() && ourReleased.first.get() && ourPressed.second.get()) {
      resetState();
      if (myActionKeyCode == -1 && !isActionBound()) {
        run(event);
      }
      return;
    }
  }
  resetState();
}
项目:intellij-ce-playground    文件:ModifierKeyDoubleClickHandlerTest.java   
@Override
public void tearDown() throws Exception {
  ModifierKeyDoubleClickHandler.getInstance().unregisterAction(MY_SHIFT_SHIFT_KEY_ACTION);
  ModifierKeyDoubleClickHandler.getInstance().unregisterAction(MY_SHIFT_SHIFT_ACTION);
  KeymapManager.getInstance().getActiveKeymap().removeShortcut(MY_SHIFT_KEY_ACTION, SHIFT_KEY_SHORTCUT);
  ActionManager.getInstance().unregisterAction(MY_SHIFT_SHIFT_KEY_ACTION);
  ActionManager.getInstance().unregisterAction(MY_SHIFT_KEY_ACTION);
  ActionManager.getInstance().unregisterAction(MY_SHIFT_SHIFT_ACTION);
  Clock.reset();
  super.tearDown();
}
项目:intellij-ce-playground    文件:ModifierKeyDoubleClickHandlerTest.java   
private void press() {
  IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent,
                                                         KeyEvent.KEY_PRESSED,
                                                         Clock.getTime(),
                                                         InputEvent.SHIFT_MASK,
                                                         KeyEvent.VK_SHIFT,
                                                         KeyEvent.CHAR_UNDEFINED));
}
项目:intellij-ce-playground    文件:ModifierKeyDoubleClickHandlerTest.java   
private void release() {
  IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent,
                                                         KeyEvent.KEY_RELEASED,
                                                         Clock.getTime(),
                                                         0,
                                                         KeyEvent.VK_SHIFT,
                                                         KeyEvent.CHAR_UNDEFINED));
}
项目:intellij-ce-playground    文件:GettingContentAtDateTest.java   
public void testGettingFirstAvailableContentAfterPurge() throws Exception {
  Clock.setTime(1);
  setContent(f, "1", TIMESTAMP_INCREMENT);
  Clock.setTime(2);
  setContent(f, "2", TIMESTAMP_INCREMENT * 2);
  Clock.setTime(3);
  setContent(f, "3", TIMESTAMP_INCREMENT * 3);

  getVcs().getChangeListInTests().purgeObsolete(2);

  assertContentAt(TIMESTAMP_INCREMENT, null);
  assertContentAt(TIMESTAMP_INCREMENT * 2, "2");
  assertContentAt(TIMESTAMP_INCREMENT * 3, "3");
}
项目:intellij-ce-playground    文件:VisitingTest.java   
@Test
public void testPurgingDuringVisit() throws Exception {
  Clock.setTime(10);
  getVcs().beginChangeSet();
  createFile("f.txt");
  getVcs().endChangeSet(null);

  Clock.setTime(20);
  getVcs().beginChangeSet();
  createFile("dir");
  getVcs().endChangeSet(null);

  TestVisitor visitor = new TestVisitor();
  getVcs().accept(visitor);
  assertEquals("begin create end begin create end finished ", visitor.log);

  visitor = new TestVisitor() {
    @Override
    public void visit(CreateEntryChange c) throws StopVisitingException {
      super.visit(c);
      getVcs().getChangeListInTests().purgeObsolete(5);
    }
  };

  // processing full list in spite of purging
  assertVisitorLog("begin create end begin create end finished ", visitor);

  visitor.log = "";
  getVcs().getChangeListInTests().purgeObsolete(5);
  assertVisitorLog("begin create end finished ", visitor);
}
项目:intellij-ce-playground    文件:SelectionReverterTest.java   
public void testChangeSetName() throws IOException {
  long time = new Date(2001, 1, 11, 12, 30).getTime();
  Clock.setTime(time);

  f.setBinaryContent("one".getBytes());
  f.setBinaryContent("two".getBytes());

  revertToPreviousRevision(0, 0);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(5, rr.size());
  assertEquals("Reverted to " + DateFormatUtil.formatDateTime(time), rr.get(1).getChangeSetName());
}
项目:intellij-ce-playground    文件:RevisionsAndDiffsTest.java   
public void testIncludingVersionBeforeFirstChangeAfterPurge() throws IOException {
  Clock.setTime(10);
  VirtualFile f = createFile("file.txt", "one");
  loadContent(f);
  Clock.setTime(20);
  setContent(f, "two");

  getVcs().getChangeListInTests().purgeObsolete(5);

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(2, rr.size());

  assertContent("two", rr.get(0).findEntry());
  assertContent("one", rr.get(1).findEntry());
}
项目:intellij-ce-playground    文件:RevisionsAndDiffsTest.java   
public void testRevisionsTimestamp() throws IOException {
  Clock.setTime(10);
  VirtualFile f = createFile("file1.txt");

  Clock.setTime(20);
  setContent(f, "a");

  Clock.setTime(30);
  setContent(f, "b");

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(30L, rr.get(1).getTimestamp());
  assertEquals(20L, rr.get(2).getTimestamp());
  assertEquals(10L, rr.get(3).getTimestamp());
}