|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - |
17 | 16 | package consulo.python.spellchecker; |
18 | 17 |
|
19 | 18 | import com.intellij.spellchecker.generator.SpellCheckerDictionaryGenerator; |
20 | 19 | import com.jetbrains.python.codeInsight.controlflow.ScopeOwner; |
21 | 20 | import com.jetbrains.python.psi.*; |
| 21 | +import consulo.annotation.access.RequiredReadAction; |
22 | 22 | import consulo.document.util.TextRange; |
23 | 23 | import consulo.language.Language; |
24 | 24 | import consulo.language.psi.PsiFile; |
|
28 | 28 | import consulo.project.Project; |
29 | 29 | import consulo.virtualFileSystem.VirtualFile; |
30 | 30 |
|
31 | | -import java.util.HashSet; |
| 31 | +import java.util.Set; |
32 | 32 |
|
33 | 33 | /** |
34 | 34 | * @author yole |
35 | 35 | */ |
36 | 36 | public class PythonSpellcheckerDictionaryGenerator extends SpellCheckerDictionaryGenerator { |
37 | | - public PythonSpellcheckerDictionaryGenerator(final Project project, final String dictOutputFolder) { |
38 | | - super(project, dictOutputFolder, "python"); |
39 | | - } |
| 37 | + public PythonSpellcheckerDictionaryGenerator(Project project, String dictOutputFolder) { |
| 38 | + super(project, dictOutputFolder, "python"); |
| 39 | + } |
40 | 40 |
|
41 | | - @Override |
42 | | - protected void processFolder(final HashSet<String> seenNames, PsiManager manager, VirtualFile folder) { |
43 | | - if (!myExcludedFolders.contains(folder)) { |
44 | | - final String name = folder.getName(); |
45 | | - IdentifierTokenSplitter.getInstance().split(name, TextRange.allOf(name), textRange -> { |
46 | | - final String word = textRange.substring(name); |
47 | | - addSeenWord(seenNames, word, Language.ANY); |
48 | | - }); |
| 41 | + @Override |
| 42 | + protected void processFolder(Set<String> seenNames, PsiManager manager, VirtualFile folder) { |
| 43 | + if (!myExcludedFolders.contains(folder)) { |
| 44 | + String name = folder.getName(); |
| 45 | + IdentifierTokenSplitter.getInstance().split( |
| 46 | + name, |
| 47 | + TextRange.allOf(name), |
| 48 | + textRange -> { |
| 49 | + String word = textRange.substring(name); |
| 50 | + addSeenWord(seenNames, word, Language.ANY); |
| 51 | + } |
| 52 | + ); |
| 53 | + } |
| 54 | + super.processFolder(seenNames, manager, folder); |
49 | 55 | } |
50 | | - super.processFolder(seenNames, manager, folder); |
51 | | - } |
52 | 56 |
|
53 | | - @Override |
54 | | - protected void processFile(PsiFile file, final HashSet<String> seenNames) { |
55 | | - file.accept(new PyRecursiveElementVisitor() { |
56 | | - @Override |
57 | | - public void visitPyFunction(PyFunction node) { |
58 | | - super.visitPyFunction(node); |
59 | | - processLeafsNames(node, seenNames); |
60 | | - } |
| 57 | + @Override |
| 58 | + protected void processFile(PsiFile file, Set<String> seenNames) { |
| 59 | + file.accept(new PyRecursiveElementVisitor() { |
| 60 | + @Override |
| 61 | + @RequiredReadAction |
| 62 | + public void visitPyFunction(PyFunction node) { |
| 63 | + super.visitPyFunction(node); |
| 64 | + processLeafsNames(node, seenNames); |
| 65 | + } |
61 | 66 |
|
62 | | - @Override |
63 | | - public void visitPyClass(PyClass node) { |
64 | | - super.visitPyClass(node); |
65 | | - processLeafsNames(node, seenNames); |
66 | | - } |
| 67 | + @Override |
| 68 | + @RequiredReadAction |
| 69 | + public void visitPyClass(PyClass node) { |
| 70 | + super.visitPyClass(node); |
| 71 | + processLeafsNames(node, seenNames); |
| 72 | + } |
67 | 73 |
|
68 | | - @Override |
69 | | - public void visitPyTargetExpression(PyTargetExpression node) { |
70 | | - super.visitPyTargetExpression(node); |
71 | | - if (PsiTreeUtil.getParentOfType(node, ScopeOwner.class) instanceof PyFile) { |
72 | | - processLeafsNames(node, seenNames); |
73 | | - } |
74 | | - } |
75 | | - }); |
76 | | - } |
| 74 | + @Override |
| 75 | + @RequiredReadAction |
| 76 | + public void visitPyTargetExpression(PyTargetExpression node) { |
| 77 | + super.visitPyTargetExpression(node); |
| 78 | + if (PsiTreeUtil.getParentOfType(node, ScopeOwner.class) instanceof PyFile) { |
| 79 | + processLeafsNames(node, seenNames); |
| 80 | + } |
| 81 | + } |
| 82 | + }); |
| 83 | + } |
77 | 84 | } |
0 commit comments