mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
cleanup and refactoring
This commit is contained in:
+70
-46
@@ -2,6 +2,8 @@ package com.intellij.spellchecker.generator;
|
||||
|
||||
import com.intellij.lang.refactoring.NamesValidator;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -29,6 +31,7 @@ public abstract class SpellCheckerDictionaryGenerator {
|
||||
private final String myDefaultDictName;
|
||||
protected final String myDictOutputFolder;
|
||||
protected final MultiMap<String, VirtualFile> myDict2FolderMap;
|
||||
protected final Set<VirtualFile> myExcludedFolders = new HashSet<VirtualFile>();
|
||||
protected SpellCheckerManager mySpellCheckerManager;
|
||||
protected NamesValidator[] myNamesValidators;
|
||||
|
||||
@@ -46,35 +49,45 @@ public abstract class SpellCheckerDictionaryGenerator {
|
||||
myDict2FolderMap.putValue(dictName, path);
|
||||
}
|
||||
|
||||
public void excludeFolder(VirtualFile folder) {
|
||||
myExcludedFolders.add(folder);
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
// let's do result a bit more predictable
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
// let's do result a bit more predictable
|
||||
|
||||
// ruby dictionary
|
||||
generate(myDefaultDictName);
|
||||
// ruby dictionary
|
||||
generate(myDefaultDictName, progressIndicator);
|
||||
|
||||
// other gem-related dictionaries in alphabet order
|
||||
final List<String> dictsList = new ArrayList<String>(myDict2FolderMap.keySet());
|
||||
Collections.sort(dictsList);
|
||||
// other gem-related dictionaries in alphabet order
|
||||
final List<String> dictsList = new ArrayList<String>(myDict2FolderMap.keySet());
|
||||
Collections.sort(dictsList);
|
||||
|
||||
for (String dict : dictsList) {
|
||||
if (myDefaultDictName.equals(dict)) {
|
||||
continue;
|
||||
for (String dict : dictsList) {
|
||||
if (myDefaultDictName.equals(dict)) {
|
||||
continue;
|
||||
}
|
||||
generate(dict, progressIndicator);
|
||||
}
|
||||
}
|
||||
generate(dict);
|
||||
}
|
||||
}, "Generating Dictionaries", false, myProject);
|
||||
}
|
||||
|
||||
private void generate(@NotNull String dict) {
|
||||
System.out.println("Processing dictionary: " + dict);
|
||||
generateDictionary(myProject, myDict2FolderMap.get(dict), myDictOutputFolder + "/" + dict + ".dic");
|
||||
System.out.println("Done");
|
||||
private void generate(@NotNull String dict, ProgressIndicator progressIndicator) {
|
||||
progressIndicator.setText("Processing dictionary: " + dict);
|
||||
generateDictionary(myProject, myDict2FolderMap.get(dict), myDictOutputFolder + "/" + dict + ".dic", progressIndicator);
|
||||
}
|
||||
|
||||
private void generateDictionary(final Project project, final Collection<VirtualFile> folderPaths, final String outFile) {
|
||||
private void generateDictionary(final Project project, final Collection<VirtualFile> folderPaths, final String outFile,
|
||||
final ProgressIndicator progressIndicator) {
|
||||
final HashSet<String> seenNames = new HashSet<String>();
|
||||
// Collect stuff
|
||||
for (VirtualFile folder : folderPaths) {
|
||||
System.out.println(" Scanning folder: " + folder.getPath());
|
||||
progressIndicator.setText2("Scanning folder: " + folder.getPath());
|
||||
final PsiManager manager = PsiManager.getInstance(project);
|
||||
processFolder(seenNames, manager, folder);
|
||||
}
|
||||
@@ -110,10 +123,13 @@ public abstract class SpellCheckerDictionaryGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private void processFolder(final HashSet<String> seenNames, final PsiManager manager,
|
||||
protected void processFolder(final HashSet<String> seenNames, final PsiManager manager,
|
||||
final VirtualFile folder) {
|
||||
if (myExcludedFolders.contains(folder)) {
|
||||
return;
|
||||
}
|
||||
for (VirtualFile virtualFile : folder.getChildren()) {
|
||||
if (virtualFile.isDirectory()){
|
||||
if (virtualFile.isDirectory()) {
|
||||
processFolder(seenNames, manager, virtualFile);
|
||||
continue;
|
||||
}
|
||||
@@ -157,34 +173,42 @@ public abstract class SpellCheckerDictionaryGenerator {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (CheckArea area : areas) {
|
||||
boolean ignored = area.isIgnored();
|
||||
final TextRange textRange = area.getTextRange();
|
||||
|
||||
if (ignored || textRange ==null){
|
||||
continue;
|
||||
}
|
||||
|
||||
final String word = area.getWord();
|
||||
if (word == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String lowerWord = word.toLowerCase();
|
||||
if (globalSeenNames.contains(lowerWord)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean keyword = SpellCheckingInspection.isKeyword(myNamesValidators, token.getElement(), word);
|
||||
if (keyword){
|
||||
continue;
|
||||
}
|
||||
globalSeenNames.add(lowerWord);
|
||||
if (mySpellCheckerManager.hasProblem(lowerWord)){
|
||||
seenNames.add(lowerWord);
|
||||
}
|
||||
}
|
||||
processCheckAreas(areas, seenNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void processCheckAreas(List<CheckArea> areas, HashSet<String> seenNames) {
|
||||
for (CheckArea area : areas) {
|
||||
boolean ignored = area.isIgnored();
|
||||
final TextRange textRange = area.getTextRange();
|
||||
|
||||
if (ignored || textRange ==null){
|
||||
continue;
|
||||
}
|
||||
|
||||
final String word = area.getWord();
|
||||
if (word == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
addSeenWord(seenNames, word);
|
||||
}
|
||||
}
|
||||
|
||||
private void addSeenWord(HashSet<String> seenNames, String word) {
|
||||
final String lowerWord = word.toLowerCase();
|
||||
if (globalSeenNames.contains(lowerWord)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean keyword = SpellCheckingInspection.isKeyword(myProject, myNamesValidators, word);
|
||||
if (keyword){
|
||||
return;
|
||||
}
|
||||
globalSeenNames.add(lowerWord);
|
||||
if (mySpellCheckerManager.hasProblem(lowerWord)){
|
||||
seenNames.add(lowerWord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -26,6 +26,7 @@ import com.intellij.lang.refactoring.NamesValidator;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileTypes.PlainTextLanguage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -192,7 +193,7 @@ public class SpellCheckingInspection extends LocalInspectionTool {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean keyword = isKeyword(validators, token.getElement(), word);
|
||||
boolean keyword = isKeyword(token.getElement().getProject(), validators, word);
|
||||
if (keyword){
|
||||
continue;
|
||||
}
|
||||
@@ -265,12 +266,12 @@ public class SpellCheckingInspection extends LocalInspectionTool {
|
||||
return validators;
|
||||
}
|
||||
|
||||
public static boolean isKeyword(NamesValidator[] validators, PsiElement element, String word) {
|
||||
public static boolean isKeyword(Project project, NamesValidator[] validators, String word) {
|
||||
if (validators == null) {
|
||||
return false;
|
||||
}
|
||||
for (NamesValidator validator : validators) {
|
||||
if (validator.isKeyword(word, element.getProject())) {
|
||||
if (validator.isKeyword(word, project)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user