use of com.intellij.openapi.vfs.encoding.EncodingProjectManagerImpl in project intellij-community by JetBrains.
the class CompilerEncodingServiceImpl method computeModuleCharsetMap.
@NotNull
private Map<Module, Set<Charset>> computeModuleCharsetMap() {
final Map<Module, Set<Charset>> map = new THashMap<>();
final Map<VirtualFile, Charset> mappings = ((EncodingProjectManagerImpl) EncodingProjectManager.getInstance(myProject)).getAllMappings();
ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
for (Map.Entry<VirtualFile, Charset> entry : mappings.entrySet()) {
final VirtualFile file = entry.getKey();
final Charset charset = entry.getValue();
if (file == null || charset == null || (!file.isDirectory() && !compilerManager.isCompilableFileType(file.getFileType())) || !index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES))
continue;
final Module module = index.getModuleForFile(file);
if (module == null)
continue;
Set<Charset> set = map.get(module);
if (set == null) {
set = new LinkedHashSet<>();
map.put(module, set);
final VirtualFile sourceRoot = index.getSourceRootForFile(file);
VirtualFile current = file.getParent();
Charset parentCharset = null;
while (current != null) {
final Charset currentCharset = mappings.get(current);
if (currentCharset != null) {
parentCharset = currentCharset;
}
if (current.equals(sourceRoot)) {
break;
}
current = current.getParent();
}
if (parentCharset != null) {
set.add(parentCharset);
}
}
set.add(charset);
}
//todo[nik,jeka] perhaps we should take into account encodings of source roots only not individual files
for (Module module : ModuleManager.getInstance(myProject).getModules()) {
for (VirtualFile file : ModuleRootManager.getInstance(module).getSourceRoots(true)) {
Charset encoding = EncodingProjectManager.getInstance(myProject).getEncoding(file, true);
if (encoding != null) {
Set<Charset> charsets = map.get(module);
if (charsets == null) {
charsets = new LinkedHashSet<>();
map.put(module, charsets);
}
charsets.add(encoding);
}
}
}
return map;
}
Aggregations