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


Java LineTokenizer类代码示例

本文整理汇总了Java中com.intellij.openapi.util.text.LineTokenizer的典型用法代码示例。如果您正苦于以下问题:Java LineTokenizer类的具体用法?Java LineTokenizer怎么用?Java LineTokenizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getPreferredSize

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
public Dimension getPreferredSize(JComponent c) {
  FontMetrics metrics = c.getFontMetrics(c.getFont());
  String tipText = ((JToolTip)c).getTipText();
  if (tipText == null) {
    tipText = "";
  }
  int maxWidth = 0;
  myLines.clear();

  final String[] lines = LineTokenizer.tokenize(tipText.toCharArray(), false);
  for (String line : lines) {
    myLines.add(line);
    int width = SwingUtilities.computeStringWidth(metrics, line);
    if (width > maxWidth) {
      maxWidth = width;
    }
  }

  int height = metrics.getHeight() * ((lines.length < 1)? 1 : lines.length);
  return new Dimension(maxWidth + 6, height + 4);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:MultiLineTooltipUI.java

示例2: getPreferredSize

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
@Override
public Dimension getPreferredSize() {
  if (myPreferredSize == null) {
    int maxLineLength = 0;
    int linesCount = 0;

    for (LineTokenizer lt = new LineTokenizer(myRawText); !lt.atEnd(); lt.advance()) {
      maxLineLength = Math.max(maxLineLength, lt.getLength());
      linesCount++;
    }

    FontMetrics fontMetrics = ((EditorImpl)getEditor()).getFontMetrics(myTextAttributes != null ? myTextAttributes.getFontType() : Font.PLAIN);
    int preferredHeight = getEditor().getLineHeight() * Math.max(1, linesCount);
    int preferredWidth = fontMetrics.charWidth('m') * maxLineLength;

    Insets insets = getInsets();
    if (insets != null) {
      preferredHeight += insets.top + insets.bottom;
      preferredWidth += insets.left + insets.right;
    }

    myPreferredSize = new Dimension(preferredWidth, preferredHeight);
  }
  return myPreferredSize;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:EditorTextFieldCellRenderer.java

示例3: appendAbbreviated

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
private static void appendAbbreviated(StringBuilder to, String text, int start, int end,
                                      FontMetrics metrics, int maxWidth, boolean replaceLineTerminators) {
  int abbreviationLength = abbreviationLength(text, start, end, metrics, maxWidth, replaceLineTerminators);

  if (!replaceLineTerminators) {
    to.append(text, start, start + abbreviationLength);
  }
  else {
    CharSequenceSubSequence subSeq = new CharSequenceSubSequence(text, start, start + abbreviationLength);
    for (LineTokenizer lt = new LineTokenizer(subSeq); !lt.atEnd(); lt.advance()) {
      to.append(subSeq, lt.getOffset(), lt.getOffset() + lt.getLength());
      if (lt.getLineSeparatorLength() > 0) {
        to.append(RETURN_SYMBOL);
      }
    }
  }

  if (abbreviationLength != end - start) {
    to.append(ABBREVIATION_SUFFIX);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:EditorTextFieldCellRenderer.java

示例4: abbreviationLength

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
private static int abbreviationLength(String text, int start, int end, FontMetrics metrics, int maxWidth, boolean replaceSeparators) {
  if (metrics.charWidth('m') * (end - start) <= maxWidth) return end - start;

  int abbrWidth = metrics.charWidth(ABBREVIATION_SUFFIX);
  int abbrLength = 0;

  CharSequenceSubSequence subSeq = new CharSequenceSubSequence(text, start, end);
  for (LineTokenizer lt = new LineTokenizer(subSeq); !lt.atEnd(); lt.advance()) {
    for (int i = 0; i < lt.getLength(); i++, abbrLength++) {
      abbrWidth += metrics.charWidth(subSeq.charAt(lt.getOffset() + i));
      if (abbrWidth >= maxWidth) return abbrLength;
    }
    if (replaceSeparators && lt.getLineSeparatorLength() != 0) {
      abbrWidth += metrics.charWidth(RETURN_SYMBOL);
      if (abbrWidth >= maxWidth) return abbrLength;
      abbrLength += lt.getLineSeparatorLength();
    }
  }

  return abbrLength;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:EditorTextFieldCellRenderer.java

示例5: extractFromSitePy

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
/**
 * Extracts paths from site.py generated by buildout 1.5+
 *
 * @param vFile path to site.py
 * @return extracted paths
 */
public static List<String> extractFromSitePy(VirtualFile vFile) throws IOException {
  List<String> result = new ArrayList<String>();
  String text = VfsUtil.loadText(vFile);
  String[] lines = LineTokenizer.tokenize(text, false);
  int index = 0;
  while (index < lines.length && !lines[index].startsWith("def addsitepackages(")) {
    index++;
  }
  while (index < lines.length && !lines[index].trim().startsWith("buildout_paths = [")) {
    index++;
  }
  index++;
  while (index < lines.length && !lines[index].trim().equals("]")) {
    String line = lines[index].trim();
    if (line.endsWith(",")) {
      line = line.substring(0, line.length() - 1);
    }
    if (line.startsWith("'") && line.endsWith("'")) {
      result.add(StringUtil.unescapeStringCharacters(line.substring(1, line.length() - 1)));
    }
    index++;
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:BuildoutFacet.java

示例6: expand

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
                                   int totalIterations, String surroundedText,
                                   CustomTemplateCallback callback,
                                   boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
  if (surroundedText == null) {
    return myOperand.expand(numberInIteration, totalIterations, null, callback, insertSurroundedTextAtTheEnd, parent);
  }
  String[] lines = LineTokenizer.tokenize(surroundedText, false);
  List<GenerationNode> result = new ArrayList<GenerationNode>();
  for (int i = 0; i < lines.length; i++) {
    result.addAll(myOperand.expand(i, lines.length, lines[i].trim(), callback, insertSurroundedTextAtTheEnd, parent));
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:UnaryMulOperationNode.java

示例7: readPackedBranches

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
@NotNull
private Map<String, String> readPackedBranches() {
  if (!myPackedRefsFile.exists()) {
    return Collections.emptyMap();
  }
  try {
    String content = DvcsUtil.tryLoadFile(myPackedRefsFile);
    return ContainerUtil.map2MapNotNull(LineTokenizer.tokenize(content, false), new Function<String, Pair<String, String>>() {
      @Override
      public Pair<String, String> fun(String line) {
        return parsePackedRefsLine(line);
      }
    });
  }
  catch (RepoStateException e) {
    return Collections.emptyMap();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:GitRepositoryReader.java

示例8: expand

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
@NotNull
@Override
public List<GenerationNode> expand(int numberInIteration,
                                   int totalIterations, String surroundedText,
                                   CustomTemplateCallback callback,
                                   boolean insertSurroundedTextAtTheEnd, GenerationNode parent) {
  if (surroundedText == null) {
    return myOperand.expand(numberInIteration, totalIterations, surroundedText, callback, insertSurroundedTextAtTheEnd, parent);
  }
  String[] lines = LineTokenizer.tokenize(surroundedText, false);
  List<GenerationNode> result = new ArrayList<GenerationNode>();
  for (int i = 0; i < lines.length; i++) {
    result.addAll(myOperand.expand(i, lines.length, lines[i].trim(), callback, insertSurroundedTextAtTheEnd, parent));
  }
  return result;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:UnaryMulOperationNode.java

示例9: appendAbbreviated

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
private static void appendAbbreviated(StringBuilder to, String text, int start, int end, FontMetrics metrics, int maxWidth, boolean replaceLineTerminators) {
  int abbreviationLength = abbreviationLength(text, start, end, metrics, maxWidth, replaceLineTerminators);

  if (!replaceLineTerminators) {
    to.append(text, start, start + abbreviationLength);
  }
  else {
    CharSequenceSubSequence subSeq = new CharSequenceSubSequence(text, start, start + abbreviationLength);
    for (LineTokenizer lt = new LineTokenizer(subSeq); !lt.atEnd(); lt.advance()) {
      to.append(subSeq, lt.getOffset(), lt.getOffset() + lt.getLength());
      if (lt.getLineSeparatorLength() > 0) {
        to.append(RETURN_SYMBOL);
      }
    }
  }

  if (abbreviationLength != end - start) {
    to.append(ABBREVIATION_SUFFIX);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:21,代码来源:EditorTextFieldCellRenderer.java

示例10: preprocessOnPaste

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
@NotNull
@Override
public String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor
  final int selectionStart = selectionModel.getSelectionStart();
  final int selectionEnd = selectionModel.getSelectionEnd();
  PsiElement token = findLiteralTokenType(file, selectionStart, selectionEnd);
  if (token == null) {
    return text;
  }

  if (isStringLiteral(token)) {
    StringBuilder buffer = new StringBuilder(text.length());
    @NonNls String breaker = getLineBreaker(token);
    final String[] lines = LineTokenizer.tokenize(text.toCharArray(), false, true);
    for (int i = 0; i < lines.length; i++) {
      buffer.append(escapeCharCharacters(lines[i], token));
      if (i != lines.length - 1) {
        buffer.append(breaker);
      }
      else if (text.endsWith("\n")) {
        buffer.append("\\n");
      }
    }
    text = buffer.toString();
  }
  else if (isCharLiteral(token)) {
    return escapeCharCharacters(text, token);
  }
  return text;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:StringLiteralCopyPasteProcessor.java

示例11: stripSpaces

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
private static String stripSpaces(String text) {
  String[] lines = LineTokenizer.tokenize(text.toCharArray(), false);
  StringBuilder buf = new StringBuilder(text.length());
  for (int i = 0; i < lines.length; i++) {
    if (i > 0) buf.append('\n');
    buf.append(rTrim(lines[i]));
  }
  return buf.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:CommentFormatter.java

示例12: updateText

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
private void updateText(Rectangle clip) {
  FontMetrics fontMetrics = ((EditorImpl)getEditor()).getFontMetrics(myTextAttributes != null ? myTextAttributes.getFontType() : Font.PLAIN);
  Insets insets = getInsets();
  int maxLineWidth = getWidth() - (insets != null ? insets.left + insets.right : 0);

  myDocumentTextBuilder.setLength(0);

  boolean singleLineMode = getHeight() / (float)getEditor().getLineHeight() < 1.1f;
  if (singleLineMode) {
    appendAbbreviated(myDocumentTextBuilder, myRawText, 0, myRawText.length(), fontMetrics, maxLineWidth, true);
  }
  else {
    int lineHeight = getEditor().getLineHeight();
    int firstVisibleLine = clip.y / lineHeight;
    float visibleLinesCountFractional = clip.height / (float)lineHeight;
    int linesToAppend = 1 + (int)visibleLinesCountFractional;

    LineTokenizer lt = new LineTokenizer(myRawText);
    for (int line = 0; !lt.atEnd() && line < firstVisibleLine; lt.advance(), line++) {
      myDocumentTextBuilder.append('\n');
    }

    for (int line = 0; !lt.atEnd() && line < linesToAppend; lt.advance(), line++) {
      int start = lt.getOffset();
      int end = start + lt.getLength();
      appendAbbreviated(myDocumentTextBuilder, myRawText, start, end, fontMetrics, maxLineWidth, false);
      if (lt.getLineSeparatorLength() > 0) {
        myDocumentTextBuilder.append('\n');
      }
    }
  }

  setTextToEditor(myDocumentTextBuilder.toString());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:EditorTextFieldCellRenderer.java

示例13: createLineSet

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
private static LineSet createLineSet(CharSequence text, boolean markModified) {
  TIntArrayList starts = new TIntArrayList();
  TByteArrayList flags = new TByteArrayList();

  LineTokenizer lineTokenizer = new LineTokenizer(text);
  while (!lineTokenizer.atEnd()) {
    starts.add(lineTokenizer.getOffset());
    flags.add((byte) (lineTokenizer.getLineSeparatorLength() | (markModified ? MODIFIED_MASK : 0)));
    lineTokenizer.advance();
  }
  return new LineSet(starts.toNativeArray(), flags.toNativeArray(), text.length());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:LineSet.java

示例14: GenericPatchApplier

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
public GenericPatchApplier(final CharSequence text, List<PatchHunk> hunks) {
  debug("GenericPatchApplier created, hunks: " + hunks.size());
  myLines = new ArrayList<String>();
  Collections.addAll(myLines, LineTokenizer.tokenize(text, false));
  myHunks = hunks;
  myTransformations = new TreeMap<TextRange, MyAppliedData>(new Comparator<TextRange>() {
    @Override
    public int compare(TextRange o1, TextRange o2) {
      return new Integer(o1.getStartOffset()).compareTo(new Integer(o2.getStartOffset()));
    }
  });
  myNotExact = new ArrayList<SplitHunk>();
  myNotBound = new ArrayList<SplitHunk>();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:GenericPatchApplier.java

示例15: removeCommonIndentation

import com.intellij.openapi.util.text.LineTokenizer; //导入依赖的package包/类
public static String[] removeCommonIndentation(@NotNull final String docstring) {
  // detect common indentation
  final String[] lines = LineTokenizer.tokenize(docstring, false);
  boolean isFirst = true;
  int cutWidth = Integer.MAX_VALUE;
  int firstIndentedLine = 0;
  for (String frag : lines) {
    if (frag.length() == 0) continue;
    int padWidth = 0;
    final Matcher matcher = ourSpacesPattern.matcher(frag);
    if (matcher.find()) {
      padWidth = matcher.end();
    }
    if (isFirst) {
      isFirst = false;
      if (padWidth == 0) {    // first line may have zero padding
        firstIndentedLine = 1;
        continue;
      }
    }
    if (padWidth < cutWidth) cutWidth = padWidth;
  }
  // remove common indentation
  if (cutWidth > 0 && cutWidth < Integer.MAX_VALUE) {
    for (int i = firstIndentedLine; i < lines.length; i += 1) {
      if (lines[i].length() >= cutWidth) {
        lines[i] = lines[i].substring(cutWidth);
      }
    }
  }
  final List<String> result = new ArrayList<String>();
  for (String line : lines) {
    if (line.startsWith(PyConsoleUtil.ORDINARY_PROMPT)) break;
    result.add(line);
  }
  return ArrayUtil.toStringArray(result);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:PyDocumentationBuilder.java


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