Java Code Examples for com.intellij.openapi.util.text.StringUtil#repeat()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#repeat() . 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: SymlinkHandlingTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testCircularLink() throws Exception {
  File upDir = createTestDir(myTempDir, "sub");
  File upLinkFile = createSymLink(upDir.getPath(), upDir.getPath() + "/up_link");
  VirtualFile upLinkVFile = refreshAndFind(upLinkFile);
  assertNotNull(upLinkVFile);
  assertTrue(upLinkVFile.is(VFileProperty.SYMLINK));
  assertTrue(upLinkVFile.isDirectory());
  assertPathsEqual(upDir.getPath(), upLinkVFile.getCanonicalPath());
  assertVisitedPaths(upDir.getPath(), upLinkVFile.getPath());

  File repeatedLinksFile = new File(upDir.getPath() + StringUtil.repeat(File.separator + upLinkFile.getName(), 4));
  assertTrue(repeatedLinksFile.getPath(), repeatedLinksFile.isDirectory());
  VirtualFile repeatedLinksVFile = refreshAndFind(repeatedLinksFile);
  assertNotNull(repeatedLinksFile.getPath(), repeatedLinksVFile);
  assertTrue(repeatedLinksVFile.is(VFileProperty.SYMLINK));
  assertTrue(repeatedLinksVFile.isDirectory());
  assertPathsEqual(upDir.getPath(), repeatedLinksVFile.getCanonicalPath());
  assertEquals(upLinkVFile.getCanonicalFile(), repeatedLinksVFile.getCanonicalFile());
}
 
Example 2
Source File: GetPathPerformanceTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testGetPath() throws IOException, InterruptedException {
  final File dir = FileUtil.createTempDirectory("GetPath","");
  dir.deleteOnExit();

  String path = dir.getPath() + StringUtil.repeat("/xxx", 50) + "/fff.txt";
  File ioFile = new File(path);
  boolean b = ioFile.getParentFile().mkdirs();
  assertTrue(b);
  boolean c = ioFile.createNewFile();
  assertTrue(c);
  final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(ioFile.getPath().replace(File.separatorChar, '/'));
  assertNotNull(file);

  PlatformTestUtil.startPerformanceTest("VF.getPath() performance failed", 4000, new ThrowableRunnable() {
    @Override
    public void run() {
      for (int i = 0; i < 1000000; ++i) {
        file.getPath();
      }
    }
  }).cpuBound().assertTiming();
}
 
Example 3
Source File: CommitPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static String getCommitterText(@Nullable VcsUser committer, @Nonnull String commitTimeText, int offset) {
  String alignment = "<br/>" + StringUtil.repeat("&nbsp;", offset);
  String gray = ColorUtil.toHex(JBColor.GRAY);

  String graySpan = "<span style='color:#" + gray + "'>";

  String text = alignment + graySpan + "committed";
  if (committer != null) {
    text += " by " + VcsUserUtil.getShortPresentation(committer);
    if (!committer.getEmail().isEmpty()) {
      text += "</span>" + getEmailText(committer) + graySpan;
    }
  }
  text += commitTimeText + "</span>";
  return text;
}
 
Example 4
Source File: PlaybackDebugger.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addInfo(String text, int line, Color fg, int depth) {
  if (text == null || text.length() == 0) return;

  String inset = StringUtil.repeat("   ", depth);

  Document doc = myLog.getDocument();
  SimpleAttributeSet attr = new SimpleAttributeSet();
  StyleConstants.setFontFamily(attr, UIManager.getFont("Label.font").getFontName());
  StyleConstants.setFontSize(attr, UIManager.getFont("Label.font").getSize());
  StyleConstants.setForeground(attr, fg);
  try {
    doc.insertString(doc.getLength(), inset + text + "\n", attr);
  }
  catch (BadLocationException e) {
    LOG.error(e);
  }
  scrollToLast();
}
 
Example 5
Source File: BuildQuoteHandler.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public CharSequence getClosingQuote(HighlighterIterator iterator, int offset) {
  char theQuote = iterator.getDocument().getCharsSequence().charAt(offset - 1);
  if (super.isOpeningQuote(iterator, offset - 1)) {
    return String.valueOf(theQuote);
  }
  if (super.isOpeningQuote(iterator, offset - 3)) {
    return StringUtil.repeat(String.valueOf(theQuote), 3);
  }
  return null;
}
 
Example 6
Source File: EnterInStringLiteralHandlerTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnterAtEOLString() {
    // 125 chars, longer than the default right margin
    String content = "\"" + StringUtil.repeat("a", 125) + "\"";
    myFixture.configureByText(BashFileType.BASH_FILE_TYPE, content);
    myFixture.getEditor().getCaretModel().moveToOffset(content.length());
    myFixture.type('\n');

    Assert.assertEquals("Expected that line continuation wasn't inserted at the end of a line",
            content + "\n", myFixture.getEditor().getDocument().getText());
}
 
Example 7
Source File: EnterInStringLiteralHandlerTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnterAtEOLCommand() {
    // 125 chars, longer than the default right margin
    String content = StringUtil.repeat("a", 125) + "\n";
    myFixture.configureByText(BashFileType.BASH_FILE_TYPE, content);
    myFixture.getEditor().getCaretModel().moveToOffset(content.length() - 1);
    myFixture.type('\n');

    Assert.assertEquals("Expected that line continuation isn't inserted at the end of a line",
            content + "\n", myFixture.getEditor().getDocument().getText());
}
 
Example 8
Source File: EnterInStringLiteralHandlerTest.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnterAtEOF() {
    // 125 chars, longer than the default right margin
    String content = StringUtil.repeat("a", 125);
    myFixture.configureByText(BashFileType.BASH_FILE_TYPE, content);
    myFixture.getEditor().getCaretModel().moveToOffset(content.length());
    myFixture.type('\n');

    Assert.assertEquals("Expected that line continuation isn't inserted at the end of a file",
            content + "\n", myFixture.getEditor().getDocument().getText());
}
 
Example 9
Source File: TestMessageBoxAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String wrap(String s, int r) {
  return r % 2 == 0 ? s : "<html><body><i>" + StringUtil.repeat(s + "<br>", 10) + "</i></body></html>";
}
 
Example 10
Source File: ArrangementEngine.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("AssignmentToForLoopParameter")
@Override
public void replace(@Nonnull ArrangementEntryWrapper<E> newWrapper,
                    @Nonnull ArrangementEntryWrapper<E> oldWrapper,
                    @Nullable ArrangementEntryWrapper<E> previous,
                    @Nullable ArrangementEntryWrapper<E> next,
                    @Nonnull Context<E> context)
{
  // Calculate blank lines before the arrangement.
  int blankLinesBefore = 0;
  TIntArrayList lineFeedOffsets = new TIntArrayList();
  int oldStartLine = context.document.getLineNumber(oldWrapper.getStartOffset());
  if (oldStartLine > 0) {
    int lastLineFeed = context.document.getLineStartOffset(oldStartLine) - 1;
    lineFeedOffsets.add(lastLineFeed);
    for (int i = lastLineFeed - 1 - myParentShift; i >= 0; i--) {
      i = CharArrayUtil.shiftBackward(myParentText, i, " \t");
      if (myParentText.charAt(i) == '\n') {
        blankLinesBefore++;
        lineFeedOffsets.add(i + myParentShift);
      }
      else {
        break;
      }
    }
  }

  ArrangementEntryWrapper<E> parentWrapper = oldWrapper.getParent();
  int desiredBlankLinesNumber = getBlankLines(context, parentWrapper, newWrapper, previous, next);
  if (desiredBlankLinesNumber == blankLinesBefore && newWrapper.equals(oldWrapper)) {
    return;
  }

  String newEntryText = myParentText.substring(newWrapper.getStartOffset() - myParentShift, newWrapper.getEndOffset() - myParentShift);
  int lineFeedsDiff = desiredBlankLinesNumber - blankLinesBefore;
  if (lineFeedsDiff == 0 || desiredBlankLinesNumber < 0) {
    context.addMoveInfo(newWrapper.getStartOffset() - myParentShift,
                        newWrapper.getEndOffset() - myParentShift,
                        oldWrapper.getStartOffset());
    context.document.replaceString(oldWrapper.getStartOffset(), oldWrapper.getEndOffset(), newEntryText);
    return;
  }

  if (lineFeedsDiff > 0) {
    // Insert necessary number of blank lines.
    StringBuilder buffer = new StringBuilder(StringUtil.repeat("\n", lineFeedsDiff));
    buffer.append(newEntryText);
    context.document.replaceString(oldWrapper.getStartOffset(), oldWrapper.getEndOffset(), buffer);
  }
  else {
    // Cut exceeding blank lines.
    int replacementStartOffset = lineFeedOffsets.get(-lineFeedsDiff) + 1;
    context.document.replaceString(replacementStartOffset, oldWrapper.getEndOffset(), newEntryText);
  }

  // Update wrapper ranges.
  ArrangementEntryWrapper<E> parent = oldWrapper.getParent();
  if (parent == null) {
    return;
  }

  Deque<ArrangementEntryWrapper<E>> parents = new ArrayDeque<ArrangementEntryWrapper<E>>();
  do {
    parents.add(parent);
    parent.setEndOffset(parent.getEndOffset() + lineFeedsDiff);
    parent = parent.getParent();
  }
  while (parent != null);


  while (!parents.isEmpty()) {

    for (ArrangementEntryWrapper<E> wrapper = parents.removeLast().getNext(); wrapper != null; wrapper = wrapper.getNext()) {
      wrapper.applyShift(lineFeedsDiff);
    }
  }
}