Search in sources :

Example 1 with CharArrayCharSequence

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

the class CompactSyntaxLexerAdapter method main.

public static void main(String[] args) throws IOException {
    final CompactSyntaxLexerAdapter lexer = new CompactSyntaxLexerAdapter();
    lexer.start(new CharArrayCharSequence(FileUtil.adaptiveLoadText(new FileReader(args[0]))));
    while (lexer.getTokenType() != null) {
        System.out.println("token = " + lexer.getTokenType());
        final int start = lexer.getTokenStart();
        System.out.println("start = " + start);
        final int end = lexer.getTokenEnd();
        System.out.println("end = " + end);
        final CharSequence t = lexer.getBufferSequence().subSequence(start, end);
        System.out.println("t = " + t);
        lexer.advance();
    }
}
Also used : CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence) CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence) FileReader(java.io.FileReader)

Example 2 with CharArrayCharSequence

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

the class CompactSyntaxLexerAdapter method start.

@Deprecated
public void start(char[] buffer, int startOffset, int endOffset, int initialState) {
    myBuffer = new CharArrayCharSequence(buffer, startOffset, endOffset);
    final CharArrayReader reader = new CharArrayReader(buffer, startOffset, endOffset - startOffset);
    init(startOffset, endOffset, reader, initialState);
}
Also used : CharArrayReader(java.io.CharArrayReader) CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence)

Example 3 with CharArrayCharSequence

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

the class ShelveChangesManager method loadPatches.

private static List<TextFilePatch> loadPatches(Project project, final String patchPath, CommitContext commitContext, boolean loadContent) throws IOException, PatchSyntaxException {
    char[] text = FileUtil.loadFileText(new File(patchPath), CharsetToolkit.UTF8);
    PatchReader reader = new PatchReader(new CharArrayCharSequence(text), loadContent);
    final List<TextFilePatch> textFilePatches = reader.readTextPatches();
    ApplyPatchDefaultExecutor.applyAdditionalInfoBefore(project, reader.getAdditionalInfo(null), commitContext);
    return textFilePatches;
}
Also used : CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 4 with CharArrayCharSequence

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

the class YYYYYYY method paintBackgrounds.

private void paintBackgrounds(@NotNull Graphics g, @NotNull Rectangle clip, @NotNull LogicalPosition clipStartPosition, @NotNull VisualPosition clipStartVisualPos, int clipStartOffset, int clipEndOffset) {
    Color defaultBackground = getBackgroundColor();
    if (myEditorComponent.isOpaque()) {
        g.setColor(defaultBackground);
        g.fillRect(clip.x, clip.y, clip.width, clip.height);
    }
    Color prevBackColor = null;
    int lineHeight = getLineHeight();
    int visibleLine = yPositionToVisibleLine(clip.y);
    Point position = new Point(0, visibleLine * lineHeight);
    CharSequence prefixText = myPrefixText == null ? null : new CharArrayCharSequence(myPrefixText);
    if (clipStartVisualPos.line == 0 && prefixText != null) {
        Color backColor = myPrefixAttributes.getBackgroundColor();
        position.x = drawBackground(g, backColor, prefixText, 0, prefixText.length(), position, myPrefixAttributes.getFontType(), defaultBackground, clip);
        prevBackColor = backColor;
    }
    if (clipStartPosition.line >= myDocument.getLineCount() || clipStartPosition.line < 0) {
        if (position.x > 0)
            flushBackground(g, clip);
        return;
    }
    myLastBackgroundPosition = null;
    myLastBackgroundColor = null;
    mySelectionStartPosition = null;
    mySelectionEndPosition = null;
    int start = clipStartOffset;
    if (!myPurePaintingMode) {
        getSoftWrapModel().registerSoftWrapsIfNecessary();
    }
    LineIterator lIterator = createLineIterator();
    lIterator.start(start);
    if (lIterator.atEnd()) {
        return;
    }
    IterationState iterationState = new IterationState(this, start, clipEndOffset, isPaintSelection());
    TextAttributes attributes = iterationState.getMergedAttributes();
    Color backColor = getBackgroundColor(attributes);
    int fontType = attributes.getFontType();
    int lastLineIndex = Math.max(0, myDocument.getLineCount() - 1);
    // There is a possible case that we need to draw background from the start of soft wrap-introduced visual line. Given position
    // has valid 'y' coordinate then at it shouldn't be affected by soft wrap that corresponds to the visual line start offset.
    // Hence, we store information about soft wrap to be skipped for further processing and adjust 'x' coordinate value if necessary.
    TIntHashSet softWrapsToSkip = new TIntHashSet();
    SoftWrap softWrap = getSoftWrapModel().getSoftWrap(start);
    if (softWrap != null) {
        softWrapsToSkip.add(softWrap.getStart());
        Color color = null;
        if (backColor != null && !backColor.equals(defaultBackground)) {
            color = backColor;
        }
        // virtual space then.
        if (color == null && position.y == getCaretModel().getVisualPosition().line * getLineHeight()) {
            color = mySettings.isCaretRowShown() ? getColorsScheme().getColor(EditorColors.CARET_ROW_COLOR) : null;
        }
        if (color != null) {
            drawBackground(g, color, softWrap.getIndentInPixels(), position, defaultBackground, clip);
            prevBackColor = color;
        }
        position.x = softWrap.getIndentInPixels();
    }
    // There is a possible case that caret is located at soft-wrapped line. We don't need to paint caret row background
    // on a last visual line of that soft-wrapped line then. Below is a holder for the flag that indicates if caret row
    // background is already drawn.
    boolean[] caretRowPainted = new boolean[1];
    CharSequence text = myDocument.getImmutableCharSequence();
    while (!iterationState.atEnd() && !lIterator.atEnd()) {
        int hEnd = iterationState.getEndOffset();
        int lEnd = lIterator.getEnd();
        if (hEnd >= lEnd) {
            FoldRegion collapsedFolderAt = myFoldingModel.getCollapsedRegionAtOffset(start);
            if (collapsedFolderAt == null) {
                position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, start, lEnd - lIterator.getSeparatorLength(), position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
                prevBackColor = backColor;
                paintAfterLineEndBackgroundSegments(g, iterationState, position, defaultBackground, lineHeight);
                if (lIterator.getLineNumber() < lastLineIndex) {
                    if (backColor != null && !backColor.equals(defaultBackground)) {
                        g.setColor(backColor);
                        g.fillRect(position.x, position.y, clip.x + clip.width - position.x, lineHeight);
                    }
                } else {
                    if (iterationState.hasPastFileEndBackgroundSegments()) {
                        paintAfterLineEndBackgroundSegments(g, iterationState, position, defaultBackground, lineHeight);
                    }
                    paintAfterFileEndBackground(iterationState, g, position, clip, lineHeight, defaultBackground, caretRowPainted);
                    break;
                }
                position.x = 0;
                if (position.y > clip.y + clip.height)
                    break;
                position.y += lineHeight;
                start = lEnd;
            } else if (collapsedFolderAt.getEndOffset() == clipEndOffset) {
                drawCollapsedFolderBackground(g, clip, defaultBackground, prevBackColor, position, backColor, fontType, softWrapsToSkip, caretRowPainted, text, collapsedFolderAt);
                prevBackColor = backColor;
            }
            lIterator.advance();
        } else {
            FoldRegion collapsedFolderAt = iterationState.getCurrentFold();
            if (collapsedFolderAt != null) {
                drawCollapsedFolderBackground(g, clip, defaultBackground, prevBackColor, position, backColor, fontType, softWrapsToSkip, caretRowPainted, text, collapsedFolderAt);
                prevBackColor = backColor;
            } else if (hEnd > lEnd - lIterator.getSeparatorLength()) {
                position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, start, lEnd - lIterator.getSeparatorLength(), position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
                prevBackColor = backColor;
            } else {
                position.x = drawSoftWrapAwareBackground(g, backColor, prevBackColor, text, start, hEnd, position, fontType, defaultBackground, clip, softWrapsToSkip, caretRowPainted);
                prevBackColor = backColor;
            }
            iterationState.advance();
            attributes = iterationState.getMergedAttributes();
            backColor = getBackgroundColor(attributes);
            fontType = attributes.getFontType();
            start = iterationState.getStartOffset();
        }
    }
    flushBackground(g, clip);
    if (lIterator.getLineNumber() >= lastLineIndex && position.y <= clip.y + clip.height) {
        paintAfterFileEndBackground(iterationState, g, position, clip, lineHeight, defaultBackground, caretRowPainted);
    }
    // Perform additional activity if soft wrap is added or removed during repainting.
    if (mySoftWrapsChanged) {
        mySoftWrapsChanged = false;
        clearTextWidthCache();
        validateSize();
        // Repaint editor to the bottom in order to ensure that its content is shown correctly after new soft wrap introduction.
        repaintToScreenBottom(EditorUtil.yPositionToLogicalLine(this, position));
        // Repaint gutter at all space that is located after active clip in order to ensure that line numbers are correctly redrawn
        // in accordance with the newly introduced soft wrap(s).
        myGutterComponent.repaint(0, clip.y, myGutterComponent.getWidth(), myGutterComponent.getHeight() - clip.y);
    }
}
Also used : CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence) CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence) TIntHashSet(gnu.trove.TIntHashSet)

Example 5 with CharArrayCharSequence

use of com.intellij.util.text.CharArrayCharSequence in project intellij-plugins by JetBrains.

the class IOUtil method getCharSequenceOrReader.

private static Object getCharSequenceOrReader(InputStream inputStream, int length, Charset charset, boolean returnReader) throws IOException {
    final InputStreamReader reader = new InputStreamReader(inputStream, charset);
    try {
        char[] chars = new char[length];
        int count = 0;
        while (count < chars.length) {
            int n = reader.read(chars, count, chars.length - count);
            if (n <= 0) {
                break;
            }
            count += n;
        }
        return returnReader ? new CharArrayReader(chars, 0, count) : new CharArrayCharSequence(chars, 0, count);
    } finally {
        reader.close();
    }
}
Also used : CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence)

Aggregations

CharArrayCharSequence (com.intellij.util.text.CharArrayCharSequence)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 TIntHashSet (gnu.trove.TIntHashSet)2 AttributedString (java.text.AttributedString)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)1 CharArrayReader (java.io.CharArrayReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1