|
1 | 1 | package fr.adrienbrault.idea.symfony2plugin.translation.parser; |
2 | 2 |
|
| 3 | +import com.intellij.openapi.progress.ProgressManager; |
3 | 4 | import com.intellij.openapi.vfs.VfsUtil; |
4 | 5 | import com.intellij.openapi.vfs.VirtualFile; |
5 | 6 | import fr.adrienbrault.idea.symfony2plugin.translation.parser.PhpCatalogueParser.ArrayEntry; |
|
10 | 11 |
|
11 | 12 | import java.io.IOException; |
12 | 13 | import java.util.*; |
13 | | -import java.util.function.Function; |
14 | | -import java.util.stream.Stream; |
15 | 14 |
|
16 | 15 | /** |
17 | 16 | * @author Daniel Espendiller <daniel@espendiller.net> |
@@ -45,15 +44,24 @@ public static TranslationStringMap createEmpty() { |
45 | 44 |
|
46 | 45 | @NotNull |
47 | 46 | public static TranslationStringMap create(@NotNull Collection<VirtualFile> translationDirectories) { |
48 | | - List<FileData> perFileData = translationDirectories.stream() |
49 | | - .flatMap((Function<VirtualFile, Stream<VirtualFile>>) dir -> { |
50 | | - VirtualFile[] children = dir.getChildren(); |
51 | | - if (children == null) return Stream.empty(); |
52 | | - return Arrays.stream(children).filter(f -> isCatalogueFile(f.getName())); |
53 | | - }) |
54 | | - .parallel() |
55 | | - .map(FileData::parse) |
56 | | - .toList(); |
| 47 | + List<FileData> perFileData = new ArrayList<>(); |
| 48 | + |
| 49 | + for (VirtualFile dir : translationDirectories) { |
| 50 | + ProgressManager.checkCanceled(); |
| 51 | + |
| 52 | + VirtualFile[] children = dir.getChildren(); |
| 53 | + if (children == null) { |
| 54 | + continue; |
| 55 | + } |
| 56 | + |
| 57 | + for (VirtualFile child : children) { |
| 58 | + ProgressManager.checkCanceled(); |
| 59 | + |
| 60 | + if (isCatalogueFile(child.getName())) { |
| 61 | + perFileData.add(FileData.parse(child)); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
57 | 65 |
|
58 | 66 | return merge(perFileData); |
59 | 67 | } |
@@ -82,13 +90,17 @@ private static TranslationStringMap merge(@NotNull Collection<FileData> perFileD |
82 | 90 | private record FileData(@NotNull Map<String, Set<String>> domainMap) { |
83 | 91 | @NotNull |
84 | 92 | static FileData parse(@NotNull VirtualFile file) { |
| 93 | + ProgressManager.checkCanceled(); |
| 94 | + |
85 | 95 | String content; |
86 | 96 | try { |
87 | 97 | content = VfsUtil.loadText(file); |
88 | 98 | } catch (IOException e) { |
89 | 99 | return empty(); |
90 | 100 | } |
91 | 101 |
|
| 102 | + ProgressManager.checkCanceled(); |
| 103 | + |
92 | 104 | Map<String, Set<String>> data = new HashMap<>(); |
93 | 105 |
|
94 | 106 | // A compiled catalogue file may contain multiple MessageCatalogue instances, |
|
0 commit comments