Search in sources :

Example 1 with CharSequenceSubSequence

use of com.intellij.util.text.CharSequenceSubSequence in project intellij-community by JetBrains.

the class IndexPatternSearcher method collectPatternMatches.

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();
            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;
}
Also used : CharSequenceSubSequence(com.intellij.util.text.CharSequenceSubSequence) IndexPattern(com.intellij.psi.search.IndexPattern) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Example 2 with CharSequenceSubSequence

use of com.intellij.util.text.CharSequenceSubSequence in project intellij-community by JetBrains.

the class ComparisonManagerImpl method processAdjoining.

@NotNull
private static List<LineFragment> processAdjoining(@NotNull List<LineFragment> fragments, @NotNull CharSequence text1, @NotNull CharSequence text2, @NotNull ComparisonPolicy policy, boolean squash, boolean trim) {
    int start = 0;
    int end = fragments.size();
    // TODO: trim empty leading/trailing lines
    if (trim && policy == ComparisonPolicy.IGNORE_WHITESPACES) {
        while (start < end) {
            LineFragment fragment = fragments.get(start);
            CharSequenceSubSequence sequence1 = new CharSequenceSubSequence(text1, fragment.getStartOffset1(), fragment.getEndOffset1());
            CharSequenceSubSequence sequence2 = new CharSequenceSubSequence(text2, fragment.getStartOffset2(), fragment.getEndOffset2());
            if ((fragment.getInnerFragments() == null || !fragment.getInnerFragments().isEmpty()) && !StringUtil.equalsIgnoreWhitespaces(sequence1, sequence2)) {
                break;
            }
            start++;
        }
        while (start < end) {
            LineFragment fragment = fragments.get(end - 1);
            CharSequenceSubSequence sequence1 = new CharSequenceSubSequence(text1, fragment.getStartOffset1(), fragment.getEndOffset1());
            CharSequenceSubSequence sequence2 = new CharSequenceSubSequence(text2, fragment.getStartOffset2(), fragment.getEndOffset2());
            if ((fragment.getInnerFragments() == null || !fragment.getInnerFragments().isEmpty()) && !StringUtil.equalsIgnoreWhitespaces(sequence1, sequence2)) {
                break;
            }
            end--;
        }
    }
    if (start == end)
        return Collections.emptyList();
    if (squash) {
        return singletonList(doSquash(fragments.subList(start, end)));
    }
    return fragments.subList(start, end);
}
Also used : CharSequenceSubSequence(com.intellij.util.text.CharSequenceSubSequence) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CharSequenceSubSequence

use of com.intellij.util.text.CharSequenceSubSequence in project intellij-community by JetBrains.

the class PsiFileFactoryImpl method createFileFromText.

@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);
}
Also used : CharSequenceSubSequence(com.intellij.util.text.CharSequenceSubSequence)

Example 4 with CharSequenceSubSequence

use of com.intellij.util.text.CharSequenceSubSequence in project intellij-community by JetBrains.

the class LexerEditorHighlighterLexer method start.

@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);
}
Also used : CharSequenceSubSequence(com.intellij.util.text.CharSequenceSubSequence)

Aggregations

CharSequenceSubSequence (com.intellij.util.text.CharSequenceSubSequence)4 IndexPattern (com.intellij.psi.search.IndexPattern)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 NotNull (org.jetbrains.annotations.NotNull)1