use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class EncodingProjectManagerImpl method setMapping.
public void setMapping(@NotNull final Map<VirtualFile, Charset> mapping) {
ApplicationManager.getApplication().assertIsDispatchThread();
// consider all files as unmodified
FileDocumentManager.getInstance().saveAllDocuments();
final Map<VirtualFile, Charset> newMap = new THashMap<>(mapping.size());
final Map<VirtualFile, Charset> oldMap = new THashMap<>(myMapping);
// ChangeFileEncodingAction should not start progress "reload files..."
suppressReloadDuring(() -> {
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
for (Map.Entry<VirtualFile, Charset> entry : mapping.entrySet()) {
VirtualFile virtualFile = entry.getKey();
Charset charset = entry.getValue();
if (charset == null)
throw new IllegalArgumentException("Null charset for " + virtualFile + "; mapping: " + mapping);
if (virtualFile == null) {
myProjectCharset = charset;
} else {
if (!fileIndex.isInContent(virtualFile))
continue;
if (!virtualFile.isDirectory() && !Comparing.equal(charset, oldMap.get(virtualFile))) {
Document document;
byte[] bytes;
try {
document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null)
throw new IOException();
bytes = virtualFile.contentsToByteArray();
} catch (IOException e) {
continue;
}
// ask whether to reload/convert when in doubt
boolean changed = new ChangeFileEncodingAction().chosen(document, null, virtualFile, bytes, charset);
if (!changed)
continue;
}
newMap.put(virtualFile, charset);
}
}
});
myMapping.clear();
myMapping.putAll(newMap);
final Set<VirtualFile> changed = new HashSet<>(oldMap.keySet());
for (Map.Entry<VirtualFile, Charset> entry : newMap.entrySet()) {
VirtualFile file = entry.getKey();
Charset charset = entry.getValue();
Charset oldCharset = oldMap.get(file);
if (Comparing.equal(oldCharset, charset)) {
changed.remove(file);
}
}
Set<VirtualFile> added = new HashSet<>(newMap.keySet());
added.removeAll(oldMap.keySet());
Set<VirtualFile> removed = new HashSet<>(oldMap.keySet());
removed.removeAll(newMap.keySet());
changed.addAll(added);
changed.addAll(removed);
changed.remove(null);
if (!changed.isEmpty()) {
final Processor<VirtualFile> reloadProcessor = createChangeCharsetProcessor();
tryStartReloadWithProgress(() -> {
Set<VirtualFile> processed = new THashSet<>();
next: for (VirtualFile changedFile : changed) {
for (VirtualFile processedFile : processed) {
if (VfsUtilCore.isAncestor(processedFile, changedFile, false))
continue next;
}
processSubFiles(changedFile, reloadProcessor);
processed.add(changedFile);
}
});
}
myModificationTracker.incModificationCount();
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class StubUpdatingIndex method getIndexer.
@NotNull
@Override
public DataIndexer<Integer, SerializedStubTree, FileContent> getIndexer() {
return new DataIndexer<Integer, SerializedStubTree, FileContent>() {
@Override
@NotNull
public Map<Integer, SerializedStubTree> map(@NotNull final FileContent inputData) {
final Map<Integer, SerializedStubTree> result = new THashMap<Integer, SerializedStubTree>() {
StubUpdatingIndexKeys myKeySet;
@Override
public Set<Integer> keySet() {
if (myKeySet == null) {
myKeySet = new StubUpdatingIndexKeys(super.keySet());
}
return myKeySet;
}
};
ApplicationManager.getApplication().runReadAction(() -> {
final Stub rootStub = StubTreeBuilder.buildStubTree(inputData);
if (rootStub == null)
return;
VirtualFile file = inputData.getFile();
int contentLength;
if (file.getFileType().isBinary()) {
contentLength = -1;
} else {
contentLength = ((FileContentImpl) inputData).getPsiFileForPsiDependentIndex().getTextLength();
}
rememberIndexingStamp(file, contentLength);
final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
SerializationManagerEx.getInstanceEx().serialize(rootStub, bytes);
if (DebugAssertions.DEBUG) {
try {
Stub deserialized = SerializationManagerEx.getInstanceEx().deserialize(new ByteArrayInputStream(bytes.getInternalBuffer(), 0, bytes.size()));
check(deserialized, rootStub);
} catch (ProcessCanceledException pce) {
throw pce;
} catch (Throwable t) {
LOG.error("Error indexing:" + file, t);
}
}
final int key = Math.abs(FileBasedIndex.getFileId(file));
SerializedStubTree serializedStubTree = new SerializedStubTree(bytes.getInternalBuffer(), bytes.size(), rootStub, file.getLength(), contentLength);
result.put(key, serializedStubTree);
try {
((StubUpdatingIndexKeys) result.keySet()).myStubIndicesValueMap = calcStubIndicesValueMap(serializedStubTree, key);
} catch (StorageException ex) {
throw new RuntimeException(ex);
}
});
return result;
}
};
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class Win32FsCache method getAttributes.
@Nullable
FileAttributes getAttributes(@NotNull VirtualFile file) {
VirtualFile parent = file.getParent();
int parentId = parent instanceof VirtualFileWithId ? ((VirtualFileWithId) parent).getId() : -((VirtualFileWithId) file).getId();
TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
THashMap<String, FileAttributes> nestedMap = map.get(parentId);
String name = file.getName();
FileAttributes attributes = nestedMap != null ? nestedMap.get(name) : null;
if (attributes == null) {
if (nestedMap != null && !(nestedMap instanceof IncompleteChildrenMap)) {
// our info from parent doesn't mention the child in this refresh session
return null;
}
FileInfo info = myKernel.getInfo(file.getPath());
if (info == null) {
return null;
}
attributes = info.toFileAttributes();
if (nestedMap == null) {
nestedMap = new IncompleteChildrenMap<>(FileUtil.PATH_HASHING_STRATEGY);
map.put(parentId, nestedMap);
}
nestedMap.put(name, attributes);
}
return attributes;
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class Win32FsCache method list.
@NotNull
String[] list(@NotNull VirtualFile file) {
String path = file.getPath();
FileInfo[] fileInfo = myKernel.listChildren(path);
if (fileInfo == null || fileInfo.length == 0) {
return ArrayUtil.EMPTY_STRING_ARRAY;
}
String[] names = new String[fileInfo.length];
TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
int parentId = ((VirtualFileWithId) file).getId();
THashMap<String, FileAttributes> nestedMap = map.get(parentId);
if (nestedMap == null) {
nestedMap = new THashMap<>(fileInfo.length, FileUtil.PATH_HASHING_STRATEGY);
map.put(parentId, nestedMap);
}
for (int i = 0, length = fileInfo.length; i < length; i++) {
FileInfo info = fileInfo[i];
String name = info.getName();
nestedMap.put(name, info.toFileAttributes());
names[i] = name;
}
return names;
}
use of gnu.trove.THashMap in project intellij-community by JetBrains.
the class FileColorsModel method load.
public void load(@NotNull Element e, boolean isProjectLevel) {
List<FileColorConfiguration> configurations = isProjectLevel ? myProjectLevelConfigurations : myApplicationLevelConfigurations;
configurations.clear();
Map<String, String> predefinedScopeNameToPropertyKey = new THashMap<>(FileColorsModel.predefinedScopeNameToPropertyKey);
for (Element child : e.getChildren(FILE_COLOR)) {
FileColorConfiguration configuration = FileColorConfiguration.load(child);
if (configuration != null) {
if (!isProjectLevel) {
predefinedScopeNameToPropertyKey.remove(configuration.getScopeName());
}
configurations.add(configuration);
}
}
if (!isProjectLevel) {
PropertiesComponent properties = PropertiesComponent.getInstance();
for (String scopeName : predefinedScopeNameToPropertyKey.keySet()) {
String colorName = properties.getValue(predefinedScopeNameToPropertyKey.get(scopeName));
if (colorName == null) {
// backward compatibility, previously it was saved incorrectly as scope name instead of specified property key
colorName = properties.getValue(scopeName);
// so, default value
if (colorName == null) {
colorName = predefinedScopeNameToColor.get(scopeName);
}
}
// empty means that value deleted
if (!StringUtil.isEmpty(colorName)) {
configurations.add(new FileColorConfiguration(scopeName, colorName));
}
}
}
}
Aggregations