JS backend: minor refactoring for LibrarySourcesConfig.
This commit is contained in:
@@ -67,10 +67,11 @@ public class LibrarySourcesConfig extends Config {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<JetFile> jetFiles = new ArrayList<JetFile>();
|
List<JetFile> jetFiles = new ArrayList<JetFile>();
|
||||||
String moduleName = UNKNOWN_EXTERNAL_MODULE_NAME;
|
String moduleName = UNKNOWN_EXTERNAL_MODULE_NAME;
|
||||||
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
|
VirtualFileSystem fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
|
||||||
final PsiManager psiManager = PsiManager.getInstance(getProject());
|
PsiManager psiManager = PsiManager.getInstance(getProject());
|
||||||
|
|
||||||
for (String path : files) {
|
for (String path : files) {
|
||||||
if (path.charAt(0) == '@') {
|
if (path.charAt(0) == '@') {
|
||||||
moduleName = path.substring(1);
|
moduleName = path.substring(1);
|
||||||
@@ -85,22 +86,15 @@ public class LibrarySourcesConfig extends Config {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VirtualFile file = fileSystem.findFileByPath(path);
|
VirtualFile file = fileSystem.findFileByPath(path);
|
||||||
assert file != null;
|
if (file == null) {
|
||||||
if (file.isDirectory()) {
|
LOG.error("File '" + path + "not found.'");
|
||||||
final String currentModuleName = moduleName;
|
}
|
||||||
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
|
else if (file.isDirectory()) {
|
||||||
@Override
|
JetFileCollector jetFileCollector = new JetFileCollector(jetFiles, moduleName, psiManager);
|
||||||
public boolean visitFile(@NotNull VirtualFile file) {
|
VfsUtilCore.visitChildrenRecursively(file, jetFileCollector);
|
||||||
if (file.getName().endsWith(".kt")) {
|
|
||||||
addJetFile(jetFiles, currentModuleName, psiManager, file);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addJetFile(jetFiles, moduleName, psiManager, file);
|
jetFiles.add(getJetFileByVirtualFile(file, moduleName, psiManager));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,10 +129,31 @@ public class LibrarySourcesConfig extends Config {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addJetFile(List<JetFile> jetFiles, String moduleName, PsiManager psiManager, VirtualFile file) {
|
private static JetFile getJetFileByVirtualFile(VirtualFile file, String moduleName, PsiManager psiManager) {
|
||||||
PsiFile psiFile = psiManager.findFile(file);
|
PsiFile psiFile = psiManager.findFile(file);
|
||||||
assert psiFile != null;
|
assert psiFile != null;
|
||||||
psiFile.putUserData(EXTERNAL_MODULE_NAME, moduleName);
|
psiFile.putUserData(EXTERNAL_MODULE_NAME, moduleName);
|
||||||
jetFiles.add((JetFile) psiFile);
|
return (JetFile) psiFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class JetFileCollector extends VirtualFileVisitor {
|
||||||
|
private final List<JetFile> jetFiles;
|
||||||
|
private final String moduleName;
|
||||||
|
private final PsiManager psiManager;
|
||||||
|
|
||||||
|
private JetFileCollector(List<JetFile> files, String name, PsiManager manager) {
|
||||||
|
moduleName = name;
|
||||||
|
psiManager = manager;
|
||||||
|
jetFiles = files;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visitFile(@NotNull VirtualFile file) {
|
||||||
|
if (file.getName().endsWith(".kt")) {
|
||||||
|
jetFiles.add(getJetFileByVirtualFile(file, moduleName, psiManager));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user