Search in sources :

Example 1 with TIntIntHashMap

use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.

the class PyWhiteSpaceFormattingStrategy method adjustWhiteSpaceIfNecessary.

/**
   * Python uses backslashes at the end of the line as indication that next line is an extension of the current one.
   * <p/>
   * Hence, we need to preserve them during white space manipulation.
   *
   *
   * @param whiteSpaceText    white space text to use by default for replacing sub-sequence of the given text
   * @param text              target text which region is to be replaced by the given white space symbols
   * @param startOffset       start offset to use with the given text (inclusive)
   * @param endOffset         end offset to use with the given text (exclusive)
   * @param codeStyleSettings the code style settings
   * @param nodeAfter
   * @return                  symbols to use for replacing {@code [startOffset; endOffset)} sub-sequence of the given text
   */
@NotNull
@Override
public CharSequence adjustWhiteSpaceIfNecessary(@NotNull CharSequence whiteSpaceText, @NotNull CharSequence text, int startOffset, int endOffset, CodeStyleSettings codeStyleSettings, ASTNode nodeAfter) {
    // The general idea is that '\' symbol before line feed should be preserved.
    TIntIntHashMap initialBackSlashes = countBackSlashes(text, startOffset, endOffset);
    if (initialBackSlashes.isEmpty()) {
        if (nodeAfter != null && whiteSpaceText.length() > 0 && whiteSpaceText.charAt(0) == '\n' && PythonEnterHandler.needInsertBackslash(nodeAfter, false)) {
            return addBackslashPrefix(whiteSpaceText, codeStyleSettings);
        }
        return whiteSpaceText;
    }
    final TIntIntHashMap newBackSlashes = countBackSlashes(whiteSpaceText, 0, whiteSpaceText.length());
    final AtomicBoolean continueProcessing = new AtomicBoolean();
    initialBackSlashes.forEachKey(new TIntProcedure() {

        @Override
        public boolean execute(int key) {
            if (!newBackSlashes.containsKey(key)) {
                continueProcessing.set(true);
                return false;
            }
            return true;
        }
    });
    if (!continueProcessing.get()) {
        return whiteSpaceText;
    }
    PyCodeStyleSettings settings = codeStyleSettings.getCustomSettings(PyCodeStyleSettings.class);
    StringBuilder result = new StringBuilder();
    int line = 0;
    for (int i = 0; i < whiteSpaceText.length(); i++) {
        char c = whiteSpaceText.charAt(i);
        if (c != '\n') {
            result.append(c);
            continue;
        }
        if (!newBackSlashes.contains(line++)) {
            if ((i == 0 || (i > 0 && whiteSpaceText.charAt(i - 1) != ' ')) && settings.SPACE_BEFORE_BACKSLASH) {
                result.append(' ');
            }
            result.append('\\');
        }
        result.append(c);
    }
    return result;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TIntProcedure(gnu.trove.TIntProcedure) TIntIntHashMap(gnu.trove.TIntIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TIntIntHashMap

use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.

the class CompactSyntaxLexerAdapter method init.

@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
private void init(int startOffset, int endOffset, Reader reader, int initialState) {
    myEndOffset = endOffset;
    myLengthMap = new TIntIntHashMap();
    myLexer = createTokenManager(initialState, new EscapePreprocessor(reader, startOffset, myLengthMap));
    myCurrentToken = START;
    myCurrentOffset = startOffset;
    myCurrentEnd = startOffset;
    myTokenQueue.clear();
    advance();
}
Also used : TIntIntHashMap(gnu.trove.TIntIntHashMap)

Example 3 with TIntIntHashMap

use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.

the class AbstractDataGetter method getCommitsMap.

@NotNull
private static TIntIntHashMap getCommitsMap(@NotNull Iterable<Integer> hashes) {
    TIntIntHashMap commits = new TIntIntHashMap();
    int row = 0;
    for (Integer commitId : hashes) {
        commits.put(commitId, row);
        row++;
    }
    return commits;
}
Also used : TIntIntHashMap(gnu.trove.TIntIntHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TIntIntHashMap

use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.

the class SrcFileAnnotator method getCoverageVersionToCurrentLineMapping.

private static TIntIntHashMap getCoverageVersionToCurrentLineMapping(Diff.Change change, int firstNLines) {
    TIntIntHashMap result = new TIntIntHashMap();
    int prevLineInFirst = 0;
    int prevLineInSecond = 0;
    while (change != null) {
        for (int l = 0; l < change.line0 - prevLineInFirst; l++) {
            result.put(prevLineInFirst + l, prevLineInSecond + l);
        }
        prevLineInFirst = change.line0 + change.deleted;
        prevLineInSecond = change.line1 + change.inserted;
        change = change.link;
    }
    for (int i = prevLineInFirst; i < firstNLines; i++) {
        result.put(i, prevLineInSecond + i - prevLineInFirst);
    }
    return result;
}
Also used : TIntIntHashMap(gnu.trove.TIntIntHashMap)

Example 5 with TIntIntHashMap

use of gnu.trove.TIntIntHashMap in project intellij-community by JetBrains.

the class SrcFileAnnotator method collectNonCoveredFileInfo.

private void collectNonCoveredFileInfo(final File outputFile, final List<RangeHighlighter> highlighters, final MarkupModel markupModel, final TreeMap<Integer, LineData> executableLines, final boolean coverageByTestApplicable, @NotNull MyEditorBean editorBean) {
    final CoverageSuitesBundle coverageSuite = CoverageDataManager.getInstance(myProject).getCurrentSuitesBundle();
    if (coverageSuite == null)
        return;
    Document document = editorBean.getDocument();
    VirtualFile file = editorBean.getVFile();
    final TIntIntHashMap mapping;
    if (outputFile.lastModified() < file.getTimeStamp()) {
        mapping = getOldToNewLineMapping(outputFile.lastModified(), editorBean);
        if (mapping == null)
            return;
    } else {
        mapping = null;
    }
    final List<Integer> uncoveredLines = coverageSuite.getCoverageEngine().collectSrcLinesForUntouchedFile(outputFile, coverageSuite);
    final int lineCount = document.getLineCount();
    if (uncoveredLines == null) {
        for (int lineNumber = 0; lineNumber < lineCount; lineNumber++) {
            addHighlighter(outputFile, highlighters, markupModel, executableLines, coverageByTestApplicable, coverageSuite, lineNumber, lineNumber, editorBean);
        }
    } else {
        for (int lineNumber : uncoveredLines) {
            if (lineNumber >= lineCount) {
                continue;
            }
            final int updatedLineNumber = mapping != null ? mapping.get(lineNumber) : lineNumber;
            addHighlighter(outputFile, highlighters, markupModel, executableLines, coverageByTestApplicable, coverageSuite, lineNumber, updatedLineNumber, editorBean);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) TIntIntHashMap(gnu.trove.TIntIntHashMap)

Aggregations

TIntIntHashMap (gnu.trove.TIntIntHashMap)14 NotNull (org.jetbrains.annotations.NotNull)4 Document (com.intellij.openapi.editor.Document)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Editor (com.intellij.openapi.editor.Editor)2 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)2 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)2 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Module (com.intellij.openapi.module.Module)2 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiFile (com.intellij.psi.PsiFile)2 ClassData (com.intellij.rt.coverage.data.ClassData)2 LineData (com.intellij.rt.coverage.data.LineData)2 ProjectData (com.intellij.rt.coverage.data.ProjectData)2 File (java.io.File)2 Nullable (org.jetbrains.annotations.Nullable)2