use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.
the class DocumentImpl method stripTrailingSpaces.
/**
* @return true if stripping was completed successfully, false if the document prevented stripping by e.g. caret(s) being in the way
*/
boolean stripTrailingSpaces(@Nullable final Project project, boolean inChangedLinesOnly, boolean skipCaretLines, @NotNull int[] caretOffsets) {
if (!isStripTrailingSpacesEnabled) {
return true;
}
List<StripTrailingSpacesFilter> filters = new ArrayList<>();
for (StripTrailingSpacesFilterFactory filterFactory : StripTrailingSpacesFilterFactory.EXTENSION_POINT.getExtensions()) {
StripTrailingSpacesFilter filter = filterFactory.createFilter(project, this);
if (filter == StripTrailingSpacesFilter.NOT_ALLOWED) {
return true;
} else if (filter == StripTrailingSpacesFilter.POSTPONED) {
return false;
} else {
filters.add(filter);
}
}
boolean markAsNeedsStrippingLater = false;
CharSequence text = myText;
TIntObjectHashMap<List<RangeMarker>> caretMarkers = new TIntObjectHashMap<>(caretOffsets.length);
try {
if (skipCaretLines) {
for (int caretOffset : caretOffsets) {
if (caretOffset < 0 || caretOffset > getTextLength()) {
continue;
}
int line = getLineNumber(caretOffset);
List<RangeMarker> markers = caretMarkers.get(line);
if (markers == null) {
markers = new ArrayList<>();
caretMarkers.put(line, markers);
}
RangeMarker marker = createRangeMarker(caretOffset, caretOffset);
markers.add(marker);
}
}
lineLoop: for (int line = 0; line < getLineCount(); line++) {
LineSet lineSet = getLineSet();
int maxSpacesToLeave = getMaxSpacesToLeave(line, filters);
if (inChangedLinesOnly && !lineSet.isModified(line) || maxSpacesToLeave < 0)
continue;
int whiteSpaceStart = -1;
final int lineEnd = lineSet.getLineEnd(line) - lineSet.getSeparatorLength(line);
int lineStart = lineSet.getLineStart(line);
for (int offset = lineEnd - 1; offset >= lineStart; offset--) {
char c = text.charAt(offset);
if (c != ' ' && c != '\t') {
break;
}
whiteSpaceStart = offset;
}
if (whiteSpaceStart == -1)
continue;
if (skipCaretLines) {
List<RangeMarker> markers = caretMarkers.get(line);
if (markers != null) {
for (RangeMarker marker : markers) {
if (marker.getStartOffset() >= 0 && whiteSpaceStart < marker.getStartOffset()) {
// mark this as a document that needs stripping later
// otherwise the caret would jump madly
markAsNeedsStrippingLater = true;
continue lineLoop;
}
}
}
}
final int finalStart = whiteSpaceStart + maxSpacesToLeave;
if (finalStart < lineEnd) {
// document must be unblocked by now. If not, some Save handler attempted to modify PSI
// which should have been caught by assertion in com.intellij.pom.core.impl.PomModelImpl.runTransaction
DocumentUtil.writeInRunUndoTransparentAction(new DocumentRunnable(DocumentImpl.this, project) {
@Override
public void run() {
deleteString(finalStart, lineEnd);
}
});
}
text = myText;
}
} finally {
caretMarkers.forEachValue(markerList -> {
if (markerList != null) {
for (RangeMarker marker : markerList) {
try {
marker.dispose();
} catch (Exception e) {
LOG.error(e);
}
}
}
return true;
});
}
return markAsNeedsStrippingLater;
}
use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.
the class FrameworkDetectorRegistryImpl method loadDetectors.
private void loadDetectors() {
Map<String, FrameworkDetector> newDetectors = new HashMap<>();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
newDetectors.put(detector.getDetectorId(), detector);
}
myDetectorIds = new TObjectIntHashMap<>();
final File file = getDetectorsRegistryFile();
int maxId = REGISTRY_VERSION;
if (file.exists()) {
LOG.debug("loading framework detectors registry from " + file.getAbsolutePath());
List<String> unknownIds = new ArrayList<>();
boolean versionChanged = false;
try {
DataInputStream input = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
try {
input.readInt();
myDetectorsVersion = input.readInt();
int size = input.readInt();
while (size-- > REGISTRY_VERSION) {
final String stringId = input.readUTF();
int intId = input.readInt();
maxId = Math.max(maxId, intId);
final int version = input.readInt();
final FrameworkDetector detector = newDetectors.remove(stringId);
if (detector != null) {
if (version != detector.getDetectorVersion()) {
LOG.info("Version of framework detector '" + stringId + "' changed: " + version + " -> " + detector.getDetectorVersion());
versionChanged = true;
}
myDetectorIds.put(stringId, intId);
} else {
unknownIds.add(stringId);
}
}
} finally {
input.close();
}
} catch (IOException e) {
LOG.info(e);
}
if (!unknownIds.isEmpty()) {
LOG.debug("Unknown framework detectors: " + unknownIds);
}
if (versionChanged || !newDetectors.isEmpty()) {
if (!newDetectors.isEmpty()) {
LOG.info("New framework detectors: " + newDetectors.keySet());
}
myDetectorsVersion++;
LOG.info("Framework detection index version changed to " + myDetectorsVersion);
}
}
int nextId = maxId + 1;
for (String newDetector : newDetectors.keySet()) {
myDetectorIds.put(newDetector, nextId++);
}
myDetectorById = new TIntObjectHashMap<>();
myDetectorsByFileType = new MultiMap<>();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
final int id = myDetectorIds.get(detector.getDetectorId());
myDetectorsByFileType.putValue(detector.getFileType(), id);
myDetectorById.put(id, detector);
LOG.debug("'" + detector.getDetectorId() + "' framework detector: id = " + id);
}
}
Aggregations