Cleanup (warnings; formatting; dead code)

This commit is contained in:
Roman Shevchenko
2016-03-21 17:02:55 +01:00
parent b05ddad023
commit ce3bfb7a2c
3 changed files with 47 additions and 100 deletions
@@ -1,26 +0,0 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.util.text;
import com.intellij.util.text.EditDistance;
/** @deprecated use {@link EditDistance} (to be removed in IDEA 17) */
@SuppressWarnings("unused")
public class LevenshteinDistance {
public int calculateMetrics(CharSequence str1, CharSequence str2) {
return EditDistance.levenshtein(str1, str2, true);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package com.intellij.spellchecker.engine;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -49,7 +50,7 @@ public class BaseSpellChecker implements SpellCheckerEngine {
private final List<Pair<Loader, Consumer<Dictionary>>> myDictionariesToLoad = ContainerUtil.createLockFreeCopyOnWriteList();
private final Project myProject;
public BaseSpellChecker(final Project project) {
public BaseSpellChecker(@NotNull Project project) {
myProject = project;
}
@@ -72,70 +73,55 @@ public class BaseSpellChecker implements SpellCheckerEngine {
addCompressedFixedDictionary(dictionary);
}
else {
loadDictionaryAsync(loader, new Consumer<Dictionary>() {
@Override
public void consume(final Dictionary dictionary) {
addCompressedFixedDictionary(dictionary);
}
});
loadDictionaryAsync(loader, this::addCompressedFixedDictionary);
}
}
private void loadDictionaryAsync(@NotNull final Loader loader, @NotNull final Consumer<Dictionary> consumer) {
if (myLoadingDictionaries.compareAndSet(false, true)) {
LOG.debug("Loading " + loader.getName());
_doLoadDictionaryAsync(loader, consumer);
doLoadDictionaryAsync(loader, consumer);
}
else {
queueDictionaryLoad(loader, consumer);
}
}
private void _doLoadDictionaryAsync(final Loader loader, final Consumer<Dictionary> consumer) {
final Runnable runnable = new Runnable() {
@Override
public void run() {
LOG.debug("Loading " + loader.getName());
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
if (ApplicationManager.getApplication().isDisposed()) return;
final CompressedDictionary dictionary = CompressedDictionary.create(loader, transform);
LOG.debug(loader.getName() + " loaded!");
consumer.consume(dictionary);
private void doLoadDictionaryAsync(Loader loader, Consumer<Dictionary> consumer) {
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
LOG.debug("Loading " + loader.getName());
Application app = ApplicationManager.getApplication();
app.executeOnPooledThread(() -> {
if (app.isDisposed()) return;
while (!myDictionariesToLoad.isEmpty()) {
if (ApplicationManager.getApplication().isDisposed()) return;
final Pair<Loader, Consumer<Dictionary>> nextDictionary = myDictionariesToLoad.remove(0);
Loader nextDictionaryLoader = nextDictionary.getFirst();
CompressedDictionary dictionary1 = CompressedDictionary.create(nextDictionaryLoader, transform);
LOG.debug(nextDictionaryLoader.getName() + " loaded!");
nextDictionary.getSecond().consume(dictionary1);
CompressedDictionary dictionary = CompressedDictionary.create(loader, transform);
LOG.debug(loader.getName() + " loaded!");
consumer.consume(dictionary);
while (!myDictionariesToLoad.isEmpty()) {
if (app.isDisposed()) return;
Pair<Loader, Consumer<Dictionary>> nextDictionary = myDictionariesToLoad.remove(0);
Loader nextDictionaryLoader = nextDictionary.getFirst();
dictionary = CompressedDictionary.create(nextDictionaryLoader, transform);
LOG.debug(nextDictionaryLoader.getName() + " loaded!");
nextDictionary.getSecond().consume(dictionary);
}
LOG.debug("Loading finished, restarting daemon...");
myLoadingDictionaries.set(false);
UIUtil.invokeLaterIfNeeded(() -> {
if (app.isDisposed()) return;
for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
DaemonCodeAnalyzer instance = DaemonCodeAnalyzer.getInstance(project);
if (instance != null) instance.restart();
}
LOG.debug("Loading finished, restarting daemon...");
myLoadingDictionaries.set(false);
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
if (ApplicationManager.getApplication().isDisposed()) return;
for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
final DaemonCodeAnalyzer instance = DaemonCodeAnalyzer.getInstance(project);
if (instance != null) instance.restart();
}
}
}
});
}
});
}
};
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(runnable);
});
});
}
private void queueDictionaryLoad(final Loader loader, final Consumer<Dictionary> consumer) {
@@ -167,12 +153,9 @@ public class BaseSpellChecker implements SpellCheckerEngine {
((CompressedDictionary)dictionary).getWords(first, i, j, result);
}
else {
dictionary.traverse(new Consumer<String>() {
@Override
public void consume(String s) {
if (!StringUtil.isEmpty(s) && s.charAt(0) == first && s.length() >= i && s.length() <= j) {
result.add(s);
}
dictionary.traverse(s -> {
if (!StringUtil.isEmpty(s) && s.charAt(0) == first && s.length() >= i && s.length() <= j) {
result.add(s);
}
});
}
@@ -268,9 +251,6 @@ public class BaseSpellChecker implements SpellCheckerEngine {
@Nullable
public Dictionary getBundledDictionaryByName(@NotNull String name) {
if (bundledDictionaries == null) {
return null;
}
for (Dictionary dictionary : bundledDictionaries) {
if (name.equals(dictionary.getName())) {
return dictionary;
@@ -278,4 +258,4 @@ public class BaseSpellChecker implements SpellCheckerEngine {
}
return null;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,9 @@
package com.intellij.spellchecker.engine;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
public class Suggestion implements Comparable{
public class Suggestion implements Comparable<Suggestion> {
private final String word;
private final int metrics;
@@ -30,7 +31,6 @@ public class Suggestion implements Comparable{
return word;
}
public int getMetrics() {
return metrics;
}
@@ -55,21 +55,14 @@ public class Suggestion implements Comparable{
return result;
}
@Override
public int compareTo(Object o) {
if (!(o instanceof Suggestion)) throw new IllegalArgumentException();
Suggestion r = (Suggestion)o;
int c = new Integer(getMetrics()).compareTo(r.getMetrics());
if (c !=0) return c;
return StringUtil.compare(word, r.word, true);
public int compareTo(@NotNull Suggestion o) {
int c = new Integer(getMetrics()).compareTo(o.getMetrics());
return c != 0 ? c : StringUtil.compare(word, o.word, true);
}
@Override
public String toString() {
return word + " : " + metrics;
}
}
}