-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Опциональный параметр диагностики Typo (caseInsensitive) #2945
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,22 +111,30 @@ public class TypoDiagnostic extends AbstractDiagnostic { | |
type = String.class | ||
) | ||
private String userWordsToIgnore = DEFAULT_USER_WORDS_TO_IGNORE; | ||
@DiagnosticParameter( | ||
type = Boolean.class | ||
) | ||
private Boolean caseInsensitive = false; | ||
|
||
@Override | ||
public void configure(Map<String, Object> configuration) { | ||
super.configure(configuration); | ||
minWordLength = Math.max(minWordLength, DEFAULT_MIN_WORD_LENGTH); | ||
} | ||
|
||
private Set<String> getWordsToIgnore() { | ||
private List<String> getWordsToIgnore() { | ||
var delimiter = ","; | ||
String exceptions = SPACES_PATTERN.matcher(info.getResourceString("diagnosticExceptions")).replaceAll(""); | ||
if (!userWordsToIgnore.isEmpty()) { | ||
exceptions = exceptions + delimiter + SPACES_PATTERN.matcher(userWordsToIgnore).replaceAll(""); | ||
} | ||
|
||
if (caseInsensitive) { | ||
exceptions = exceptions.toLowerCase(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В параметрах lowerCase должна быть явно указана локаль (в проекте вроде используется English) |
||
} | ||
|
||
return Arrays.stream(exceptions.split(delimiter)) | ||
.collect(Collectors.toSet()); | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static JLanguageTool acquireLanguageTool(String lang) { | ||
|
@@ -140,7 +148,7 @@ private static void releaseLanguageTool(String lang, JLanguageTool languageTool) | |
private Map<String, List<Token>> getTokensMap( | ||
DocumentContext documentContext | ||
) { | ||
Set<String> wordsToIgnore = getWordsToIgnore(); | ||
List<String> wordsToIgnore = getWordsToIgnore(); | ||
Map<String, List<Token>> tokensMap = new HashMap<>(); | ||
|
||
Trees.findAllRuleNodes(documentContext.getAst(), rulesToFind).stream() | ||
|
@@ -150,12 +158,14 @@ private Map<String, List<Token>> getTokensMap( | |
.filter(token -> !FORMAT_STRING_PATTERN.matcher(token.getText()).find()) | ||
.forEach((Token token) -> { | ||
String curText = QUOTE_PATTERN.matcher(token.getText()).replaceAll("").trim(); | ||
String[] camelCaseSplitedWords = StringUtils.splitByCharacterTypeCamelCase(curText); | ||
String[] camelCaseSplitWords = StringUtils.splitByCharacterTypeCamelCase(curText); | ||
|
||
Arrays.stream(camelCaseSplitedWords) | ||
Arrays.stream(camelCaseSplitWords) | ||
.filter(Predicate.not(String::isBlank)) | ||
.filter(element -> element.length() >= minWordLength) | ||
.filter(Predicate.not(wordsToIgnore::contains)) | ||
.filter(element -> wordsToIgnore.stream().noneMatch(word | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь замена Set на List сделала поиск слова медленнее. contains в сете работает за О(1), здесь же теперь линейный поиск за O(N), в результате сложность всего стрима стала из линейной квадратичной |
||
-> (caseInsensitive && word.equalsIgnoreCase(element)) | ||
|| (!caseInsensitive && word.equals(element)))) | ||
.forEach(element -> tokensMap.computeIfAbsent(element, newElement -> new ArrayList<>()).add(token)); | ||
} | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В чем логика замены Set на List?