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); } }
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; }
private static boolean collectPatternMatches(IndexPattern indexPattern, CharSequence chars, int commentStart, int commentEnd, PsiFile file, TextRange range, Processor<IndexPatternOccurrence> consumer, TIntArrayList matches ) { Pattern pattern = indexPattern.getPattern(); if (pattern != null) { ProgressManager.checkCanceled(); CharSequence input = new CharSequenceSubSequence(chars, commentStart, commentEnd); Matcher matcher = pattern.matcher(input); while (true) { //long time1 = System.currentTimeMillis(); boolean found = matcher.find(); //long time2 = System.currentTimeMillis(); //System.out.println("scanned text of length " + (lexer.getTokenEnd() - lexer.getTokenStart() + " in " + (time2 - time1) + " ms")); if (!found) break; int start = matcher.start() + commentStart; int end = matcher.end() + commentStart; if (start != end) { if ((range == null || range.getStartOffset() <= start && end <= range.getEndOffset()) && matches.indexOf(start) == -1) { matches.add(start); if (!consumer.process(new IndexPatternOccurrenceImpl(file, start, end, indexPattern))) { return false; } } } ProgressManager.checkCanceled(); } } return true; }
@Override public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int state) { if (myAlreadyInitializedHighlighter) { this.buffer = buffer; start = startOffset; end = endOffset; } else { myHighlighter.setText(new CharSequenceSubSequence(this.buffer = buffer, start = startOffset, end = endOffset)); } iterator = myHighlighter.createIterator(0); }
@Override public void start(CharSequence buffer, int startOffset, int endOffset, int state) { if (myAlreadyInitializedHighlighter) { this.buffer = buffer; start = startOffset; end = endOffset; } else { myHighlighter.setText(new CharSequenceSubSequence(this.buffer = buffer, start = startOffset, end = endOffset)); } iterator = myHighlighter.createIterator(0); }
private static boolean collectPatternMatches(IndexPattern indexPattern, CharSequence chars, int commentStart, int commentEnd, PsiFile file, TextRange range, Processor<IndexPatternOccurrence> consumer) { Pattern pattern = indexPattern.getPattern(); if (pattern != null) { ProgressManager.checkCanceled(); CharSequence input = new CharSequenceSubSequence(chars, commentStart, commentEnd); Matcher matcher = pattern.matcher(input); while (true) { //long time1 = System.currentTimeMillis(); boolean found = matcher.find(); //long time2 = System.currentTimeMillis(); //System.out.println("scanned text of length " + (lexer.getTokenEnd() - lexer.getTokenStart() + " in " + (time2 - time1) + " ms")); if (!found) break; int start = matcher.start() + commentStart; int end = matcher.end() + commentStart; if (start != end) { if (range == null || range.getStartOffset() <= start && end <= range.getEndOffset()) { if (!consumer.process(new IndexPatternOccurrenceImpl(file, start, end, indexPattern))) { return false; } } } ProgressManager.checkCanceled(); } } return true; }
@Override public void start(@Nonnull CharSequence buffer, int startOffset, int endOffset, int state) { if (myAlreadyInitializedHighlighter) { this.buffer = buffer; start = startOffset; end = endOffset; } else { myHighlighter.setText(new CharSequenceSubSequence(this.buffer = buffer, start = startOffset, end = endOffset)); } iterator = myHighlighter.createIterator(0); }
@Override public PsiFile createFileFromText(FileType fileType, final String fileName, CharSequence chars, int startOffset, int endOffset) { LOG.assertTrue(!fileType.isBinary()); final CharSequence text = startOffset == 0 && endOffset == chars.length() ? chars : new CharSequenceSubSequence(chars, startOffset, endOffset); return createFileFromText(fileName, fileType, text); }
@Override public PsiFile createFileFromText(FileType fileType, final String fileName, CharSequence chars, int startOffset, int endOffset) { LOG.assertTrue(!fileType.isBinary()); final CharSequence text = startOffset == 0 && endOffset == chars.length()?chars:new CharSequenceSubSequence(chars, startOffset, endOffset); return createFileFromText(fileName, fileType, text); }
@NotNull @Override public CharSequence intern(@NotNull final CharSequence baseText, final int startOffset, final int endOffset) { if (endOffset - startOffset == baseText.length()) return baseText; return intern(new CharSequenceSubSequence(baseText, startOffset, endOffset)); }