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;
}
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();
}
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;
}
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;
}
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);
}
}
}
Aggregations