reduce usages of Trove lib

GitOrigin-RevId: fd24c39bc3e75c97999086d66dbbba8a16bdb916
This commit is contained in:
Vladimir Krivosheev
2020-11-05 13:07:58 +01:00
committed by intellij-monorepo-bot
parent e9f22a2971
commit 2ed6e92635
19 changed files with 98 additions and 172 deletions

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2009 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.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.util.importProject;
import com.intellij.ide.highlighter.ModuleFileType;
@@ -49,7 +35,7 @@ public class ModuleDescriptor {
private boolean myReuseExistingElement;
private final List<ModuleBuilder.ModuleConfigurationUpdater> myConfigurationUpdaters = new SmartList<>();
private final ModuleType myModuleType;
private final ModuleType<?> myModuleType;
public ModuleDescriptor(final File contentRoot, final ModuleType moduleType, final Collection<? extends DetectedSourceRoot> sourceRoots) {
myName = suggestModuleName(contentRoot);
@@ -91,7 +77,7 @@ public class ModuleDescriptor {
return suggestion;
}
}
return contentRoot.getName();
}
@@ -114,27 +100,27 @@ public class ModuleDescriptor {
public Collection<DetectedSourceRoot> getSourceRoots(File contentRoot) {
return myContentToSourceRoots.get(contentRoot);
}
public void addContentRoot(File contentRoot) {
myContentToSourceRoots.put(contentRoot, new HashSet<>());
}
public Collection<DetectedSourceRoot> removeContentRoot(File contentRoot) {
return myContentToSourceRoots.remove(contentRoot);
}
public void addSourceRoot(final File contentRoot, DetectedSourceRoot sourceRoot) {
myContentToSourceRoots.putValue(contentRoot, sourceRoot);
}
public void addDependencyOn(ModuleDescriptor dependence) {
myDependencies.add(dependence);
}
public void removeDependencyOn(ModuleDescriptor module) {
myDependencies.remove(module);
}
public void addLibraryFile(File libFile) {
myLibraryFiles.add(libFile);
}

View File

@@ -19,7 +19,6 @@
<orderEntry type="module" module-name="intellij.java.impl" />
<orderEntry type="module" module-name="intellij.java.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.spellchecker" />
<orderEntry type="library" name="Trove4j" level="project" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
</component>
</module>

View File

@@ -28,8 +28,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.ClearableLazyValue;
import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
import gnu.trove.THashMap;
import com.intellij.util.containers.CollectionFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.lang.manifest.psi.Header;
@@ -50,7 +49,7 @@ public final class HeaderParserRepository {
@NotNull
@Override
protected Map<String, HeaderParser> compute() {
Map<String, HeaderParser> map = new THashMap<>(CaseInsensitiveStringHashingStrategy.INSTANCE);
Map<String, HeaderParser> map = CollectionFactory.createCaseInsensitiveStringMap();
for (HeaderParserProvider provider : HeaderParserProvider.EP_NAME.getExtensionList()) {
map.putAll(provider.getHeaderParsers());
}

View File

@@ -36,11 +36,10 @@ import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.intellij.spellchecker.engine.Suggestion;
import com.intellij.ui.DocumentAdapter;
import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
import com.intellij.util.text.EditDistance;
import com.intellij.util.xmlb.annotations.XCollection;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.lang.manifest.ManifestBundle;
import org.jetbrains.lang.manifest.header.HeaderParserRepository;
@@ -55,13 +54,13 @@ import java.util.*;
/**
* @author Robert F. Beeger (robert@beeger.net)
*/
public class MisspelledHeaderInspection extends LocalInspectionTool {
public final class MisspelledHeaderInspection extends LocalInspectionTool {
private static final int MAX_SUGGESTIONS = 5;
private static final int MAX_DISTANCE = 4;
private static final int TYPO_DISTANCE = 2;
@XCollection(elementName = "header")
public final Set<String> CUSTOM_HEADERS = new THashSet<>(CaseInsensitiveStringHashingStrategy.INSTANCE);
public final Set<String> CUSTOM_HEADERS = CollectionFactory.createCaseInsensitiveStringSet();
private final HeaderParserRepository myRepository;

View File

@@ -22,6 +22,7 @@ import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.StringSearcher;
import gnu.trove.TIntArrayList;
import gnu.trove.TIntProcedure;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import org.jetbrains.annotations.ApiStatus.ScheduledForRemoval;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,6 +30,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.function.IntPredicate;
import static com.intellij.openapi.util.text.StringUtil.isEscapedBackslash;
@@ -237,7 +239,7 @@ public final class LowLevelSearchUtil {
private static final ConcurrentMap<CharSequence, Map<StringSearcher, int[]>> cache = CollectionFactory.createConcurrentWeakIdentityMap();
/**
* @deprecated please use {@link #processTextOccurrences(CharSequence, int, int, StringSearcher, TIntProcedure)}
* @deprecated please use {@link #processTexts(CharSequence, int, int, StringSearcher, IntPredicate)}
*/
@ScheduledForRemoval(inVersion = "2020.2")
@Deprecated
@@ -250,6 +252,11 @@ public final class LowLevelSearchUtil {
return processTextOccurrences(text, startOffset, endOffset, searcher, processor);
}
/**
* @deprecated Use {@link #processTexts(CharSequence, int, int, StringSearcher, IntPredicate)}
*/
@Deprecated
@ScheduledForRemoval(inVersion = "2020.1")
public static boolean processTextOccurrences(@NotNull CharSequence text,
int startOffset,
int endOffset,
@@ -263,6 +270,19 @@ public final class LowLevelSearchUtil {
return true;
}
public static boolean processTexts(@NotNull CharSequence text,
int startOffset,
int endOffset,
@NotNull StringSearcher searcher,
@NotNull IntPredicate processor) {
for (int offset : getTextOccurrences(text, startOffset, endOffset, searcher)) {
if (!processor.test(offset)) {
return false;
}
}
return true;
}
private static int @NotNull [] getTextOccurrences(@NotNull CharSequence text,
int startOffset,
int endOffset,
@@ -294,7 +314,7 @@ public final class LowLevelSearchUtil {
}
cachedMap.put(searcher, cachedOccurrences);
}
TIntArrayList offsets = new TIntArrayList(cachedOccurrences.length - 2);
IntArrayList offsets = new IntArrayList(cachedOccurrences.length - 2);
for (int i = 2; i < cachedOccurrences.length; i++) {
int occurrence = cachedOccurrences[i];
if (occurrence > endOffset - searcher.getPatternLength()) break;
@@ -302,7 +322,7 @@ public final class LowLevelSearchUtil {
offsets.add(occurrence);
}
}
return offsets.toNativeArray();
return offsets.toIntArray();
}
private static boolean checkJavaIdentifier(@NotNull CharSequence text,

View File

@@ -631,7 +631,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
CharSequence text = ReadAction.compute(() -> psiFile.getViewProvider().getContents());
LowLevelSearchUtil.processTextOccurrences(text, 0, text.length(), searcher, index -> {
LowLevelSearchUtil.processTexts(text, 0, text.length(), searcher, index -> {
boolean isReferenceOK = myDumbService.runReadActionInSmartMode(() -> {
PsiReference referenceAt = psiFile.findReferenceAt(index);
return referenceAt == null || useScope == null || !PsiSearchScopeUtil.isInScope(useScope.intersectWith(initialScope), psiFile);

View File

@@ -21,6 +21,5 @@
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="module" module-name="intellij.platform.util.ui" />
<orderEntry type="library" name="fastutil-min" level="project" />
<orderEntry type="library" name="Trove4j" level="project" />
</component>
</module>

View File

@@ -23,7 +23,6 @@
<orderEntry type="module" module-name="intellij.properties.psi" />
<orderEntry type="module" module-name="intellij.properties.psi.impl" />
<orderEntry type="module" module-name="intellij.jvm.analysis" />
<orderEntry type="library" name="Trove4j" level="project" />
<orderEntry type="library" name="StreamEx" level="project" />
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="library" name="icu4j" level="project" />

View File

@@ -32,7 +32,6 @@ import com.intellij.util.containers.ConcurrentFactoryMap;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.StringSearcher;
import com.siyeh.ig.style.UnnecessarilyQualifiedStaticUsageInspection;
import gnu.trove.THashSet;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -43,7 +42,7 @@ import javax.swing.event.DocumentEvent;
import java.util.*;
import java.util.stream.Stream;
public class DuplicateStringLiteralInspection extends AbstractBaseJavaLocalInspectionTool {
public final class DuplicateStringLiteralInspection extends AbstractBaseJavaLocalInspectionTool {
private static final int MAX_FILES_TO_ON_THE_FLY_SEARCH = 10;
@SuppressWarnings("WeakerAccess") public int MIN_STRING_LENGTH = 5;
@@ -114,7 +113,7 @@ public class DuplicateStringLiteralInspection extends AbstractBaseJavaLocalInspe
StringSearcher searcher = new StringSearcher(stringToFind, true, true);
List<PsiLiteralExpression> foundExpr = new SmartList<>();
LowLevelSearchUtil.processTextOccurrences(text, 0, text.length(), searcher, offset -> {
LowLevelSearchUtil.processTexts(text, 0, text.length(), searcher, offset -> {
PsiElement element = file.findElementAt(offset);
if (element == null || !(element.getParent() instanceof PsiLiteralExpression)) return true;
PsiLiteralExpression expression = (PsiLiteralExpression)element.getParent();
@@ -131,7 +130,7 @@ public class DuplicateStringLiteralInspection extends AbstractBaseJavaLocalInspe
final boolean isOnTheFly) {
PsiExpression[] foundExpr = getDuplicateLiterals(holder.getProject(), originalExpression, isOnTheFly);
if (foundExpr.length == 0) return;
Set<PsiClass> classes = new THashSet<>();
Set<PsiClass> classes = new HashSet<>();
for (PsiElement aClass : foundExpr) {
if (aClass == originalExpression) continue;
ProgressManager.checkCanceled();

View File

@@ -41,7 +41,6 @@ import com.intellij.util.containers.ContainerUtil;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.psiutils.TypeUtils;
import com.siyeh.ig.psiutils.VariableAccessUtils;
import gnu.trove.THashSet;
import org.intellij.lang.annotations.RegExp;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
@@ -67,16 +66,16 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class I18nInspection extends AbstractBaseUastLocalInspectionTool implements CustomSuppressableInspectionTool {
public final class I18nInspection extends AbstractBaseUastLocalInspectionTool implements CustomSuppressableInspectionTool {
private static final CallMatcher ERROR_WRAPPER_METHODS = CallMatcher.anyOf(
CallMatcher.staticCall("kotlin.PreconditionsKt__PreconditionsKt", "error").parameterCount(1),
CallMatcher.staticCall("kotlin.StandardKt__StandardKt", "TODO").parameterCount(1)
);
private static final Set<UastBinaryOperator> STRING_COMPARISON_OPS =
Set.of(UastBinaryOperator.EQUALS, UastBinaryOperator.NOT_EQUALS, UastBinaryOperator.IDENTITY_EQUALS,
Set.of(UastBinaryOperator.EQUALS, UastBinaryOperator.NOT_EQUALS, UastBinaryOperator.IDENTITY_EQUALS,
UastBinaryOperator.IDENTITY_NOT_EQUALS);
private static final CallMatcher IGNORED_METHODS = CallMatcher.anyOf(
private static final CallMatcher IGNORED_METHODS = CallMatcher.anyOf(
CallMatcher.staticCall(CommonClassNames.JAVA_LANG_STRING, "valueOf").parameterTypes("int"),
CallMatcher.staticCall(CommonClassNames.JAVA_LANG_STRING, "valueOf").parameterTypes("double"),
CallMatcher.staticCall(CommonClassNames.JAVA_LANG_STRING, "valueOf").parameterTypes("long"),
@@ -386,7 +385,7 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
final JTextField commentPattern = new JTextField(nonNlsCommentPattern);
final FieldPanel nonNlsCommentPatternComponent =
new FieldPanel(commentPattern, JavaI18nBundle.message("inspection.i18n.option.ignore.comment.pattern"),
JavaI18nBundle.message("inspection.i18n.option.ignore.comment.title"), null,
JavaI18nBundle.message("inspection.i18n.option.ignore.comment.title"), null,
() -> setNonNlsCommentPattern(commentPattern.getText()));
panel.add(nonNlsCommentPatternComponent, gc);
gc.gridy ++;
@@ -397,7 +396,7 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
literalPattern.setText(nonNlsLiteralPattern);
final FieldPanel nonNlsStringPatternComponent =
new FieldPanel(literalPattern, JavaI18nBundle.message("inspection.i18n.option.ignore.string.pattern"),
JavaI18nBundle.message("inspection.i18n.option.ignore.string.title"), null,
JavaI18nBundle.message("inspection.i18n.option.ignore.string.title"), null,
() -> setNonNlsLiteralPattern(literalPattern.getText()));
panel.add(nonNlsStringPatternComponent, gc);
@@ -572,10 +571,10 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
}
if (NlsInfo.forModifierListOwner(target).canBeUsedInLocalizedContext()) return;
if (NlsInfo.forType(type).canBeUsedInLocalizedContext()) return;
String value = target instanceof PsiVariable ? ObjectUtils.tryCast(((PsiVariable)target).computeConstantValue(), String.class) : null;
NlsInfo targetInfo = getExpectedNlsInfo(myHolder.getProject(), ref, value, new THashSet<>(), myOnTheFly, true);
NlsInfo targetInfo = getExpectedNlsInfo(myHolder.getProject(), ref, value, new HashSet<>(), myOnTheFly, true);
if (targetInfo instanceof NlsInfo.Localized) {
AddAnnotationFix fix =
new AddAnnotationFix(((NlsInfo.Localized)targetInfo).suggestAnnotation(target), target, AnnotationUtil.NON_NLS);
@@ -605,7 +604,7 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
return;
}
Set<PsiModifierListOwner> nonNlsTargets = new THashSet<>();
Set<PsiModifierListOwner> nonNlsTargets = new HashSet<>();
NlsInfo info = getExpectedNlsInfo(myHolder.getProject(), expression, stringValue, nonNlsTargets, myOnTheFly, ignoreForAllButNls);
if (!(info instanceof NlsInfo.Localized)) {
return;
@@ -917,7 +916,7 @@ public class I18nInspection extends AbstractBaseUastLocalInspectionTool implemen
if (STRING_COMPARISON_OPS.contains(binOp.getOperator())) {
UResolvable left = ObjectUtils.tryCast(UastUtils.skipParenthesizedExprDown(binOp.getLeftOperand()), UResolvable.class);
UResolvable right = ObjectUtils.tryCast(UastUtils.skipParenthesizedExprDown(binOp.getRightOperand()), UResolvable.class);
return left != null && isNonNlsCall(left, nonNlsTargets) ||
return left != null && isNonNlsCall(left, nonNlsTargets) ||
right != null && isNonNlsCall(right, nonNlsTargets);
}
}

View File

@@ -21,7 +21,6 @@ import com.intellij.psi.util.PsiUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.siyeh.ig.psiutils.ExpressionUtils;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -82,7 +81,7 @@ public class InvalidPropertyKeyInspection extends AbstractBaseJavaLocalInspectio
private static class UnresolvedPropertyVisitor extends JavaRecursiveElementWalkingVisitor {
private final InspectionManager myManager;
private final Map<PsiElement, ProblemDescriptor> myProblems = new THashMap<>();
private final Map<PsiElement, ProblemDescriptor> myProblems = new HashMap<>();
private final boolean onTheFly;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.i18n;
import com.intellij.codeInsight.intention.IntentionAction;
@@ -28,7 +28,6 @@ import com.intellij.util.ArrayUtilRt;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UI;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,6 +38,7 @@ import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -252,7 +252,7 @@ public class JavaI18nizeQuickFixDialog<T extends UExpression> extends I18nizeQui
String templateName = getTemplateName();
LOG.assertTrue(templateName != null);
FileTemplate template = FileTemplateManager.getInstance(myProject).getCodeTemplate(templateName);
Map<String, String> attributes = new THashMap<>();
Map<String, String> attributes = new HashMap<>();
attributes.put(PROPERTY_KEY_OPTION_KEY, propertyKey);
attributes.put(RESOURCE_BUNDLE_OPTION_KEY, getResourceBundleText());
attributes.put(PROPERTY_VALUE_ATTR, StringUtil.escapeStringCharacters(myDefaultPropertyValue));

View File

@@ -41,7 +41,6 @@ import com.intellij.util.ArrayUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ui.ItemRemovable;
import com.intellij.util.ui.UI;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -60,7 +59,7 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class I18nizeMultipleStringsDialog<D> extends DialogWrapper {
public final class I18nizeMultipleStringsDialog<D> extends DialogWrapper {
private static final Logger LOG = Logger.getInstance(I18nizeMultipleStringsDialog.class);
private static final @NonNls String LAST_USED_PROPERTIES_FILE = "LAST_USED_PROPERTIES_FILE";
private static final @NonNls String LAST_USED_CONTEXT = "I18N_FIX_LAST_USED_CONTEXT";
@@ -80,7 +79,7 @@ public class I18nizeMultipleStringsDialog<D> extends DialogWrapper {
public I18nizeMultipleStringsDialog(@NotNull Project project,
@NotNull List<I18nizedPropertyData<D>> keyValuePairs,
@NotNull Set<PsiFile> contextFiles,
@NotNull Function<D, List<UsageInfo>> usagePreviewProvider,
@NotNull Function<D, List<UsageInfo>> usagePreviewProvider,
Icon markAsNonNlsButtonIcon,
boolean canShowCodeInfo) {
super(project, true);
@@ -110,11 +109,11 @@ public class I18nizeMultipleStringsDialog<D> extends DialogWrapper {
return textGenerator.getI18nizedConcatenationText(propertyKey, paramsString, getPropertiesFile(), null);
}
String templateName = paramsString.isEmpty() ? myResourceBundleManager.getTemplateName()
String templateName = paramsString.isEmpty() ? myResourceBundleManager.getTemplateName()
: myResourceBundleManager.getConcatenationTemplateName();
LOG.assertTrue(templateName != null);
FileTemplate template = FileTemplateManager.getInstance(myProject).getCodeTemplate(templateName);
Map<String, String> attributes = new THashMap<>();
Map<String, String> attributes = new HashMap<>();
attributes.put(JavaI18nizeQuickFixDialog.PROPERTY_KEY_OPTION_KEY, propertyKey);
attributes.put(JavaI18nizeQuickFixDialog.RESOURCE_BUNDLE_OPTION_KEY, myRBEditorTextField != null ? myRBEditorTextField.getText() : null);
attributes.put(JavaI18nizeQuickFixDialog.PROPERTY_VALUE_ATTR, propertyValue);
@@ -127,7 +126,7 @@ public class I18nizeMultipleStringsDialog<D> extends DialogWrapper {
return "";
}
}
@Override
protected @Nullable String getDimensionServiceKey() {
return "i18nInBatch";
@@ -172,7 +171,7 @@ public class I18nizeMultipleStringsDialog<D> extends DialogWrapper {
}
JPanel panel = new JPanel(new BorderLayout());
panel.add(component, BorderLayout.NORTH);
if (myShowCodeInfo && hasResourceBundleInTemplate()) {
myRBEditorTextField = new TextFieldWithStoredHistory("RESOURCE_BUNDLE_KEYS");
if (!myRBEditorTextField.getHistory().isEmpty()) {

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.i18n.inconsistentResourceBundle;
import com.intellij.codeInspection.InspectionManager;
@@ -26,9 +12,9 @@ import com.intellij.lang.properties.RemovePropertyLocalFix;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.util.Comparing;
import com.intellij.util.containers.BidirectionalMap;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -61,7 +47,7 @@ public class DuplicatedPropertiesInspectionProvider implements InconsistentResou
PropertiesFile parent = parents.get(file);
if (parent == null) continue;
Set<String> parentKeys = keysUpToParent.get(parent);
Set<String> overriddenKeys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
Set<String> overriddenKeys = new HashSet<>(propertiesFilesNamesMaps.get(file).keySet());
overriddenKeys.retainAll(parentKeys);
for (String overriddenKey : overriddenKeys) {
IProperty property = file.findPropertyByKey(overriddenKey);

View File

@@ -13,13 +13,9 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.BidirectionalMap;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* @author Dmitry Batkovich
@@ -49,7 +45,7 @@ public final class InconsistentPropertiesEndsInspectionProvider implements Incon
RefManager refManager,
ProblemDescriptionsProcessor processor) {
for (PropertiesFile file : files) {
final Set<String> filePropertyKeys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
final Set<String> filePropertyKeys = new HashSet<>(propertiesFilesNamesMaps.get(file).keySet());
PropertiesFile parent = parents.get(file);
while (parent != null) {
final Collection<String> commonKeys = ContainerUtil.intersection(propertiesFilesNamesMaps.get(parent).keySet(), filePropertyKeys);

View File

@@ -12,35 +12,29 @@ import com.intellij.psi.PsiFile;
import com.intellij.util.containers.BidirectionalMap;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.FactoryMap;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import javax.swing.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
public class InconsistentResourceBundleInspection extends GlobalSimpleInspectionTool {
public final class InconsistentResourceBundleInspection extends GlobalSimpleInspectionTool {
private static final Key<Set<ResourceBundle>> VISITED_BUNDLES_KEY = Key.create("VISITED_BUNDLES_KEY");
private final NotNullLazyValue<InconsistentResourceBundleInspectionProvider[]> myInspectionProviders =
new NotNullLazyValue<InconsistentResourceBundleInspectionProvider[]>() {
@Override
protected InconsistentResourceBundleInspectionProvider @NotNull [] compute() {
return new InconsistentResourceBundleInspectionProvider[] {
new PropertiesKeysConsistencyInspectionProvider(),
new DuplicatedPropertiesInspectionProvider(),
new MissingTranslationsInspectionProvider(),
new PropertiesPlaceholdersInspectionProvider(),
new InconsistentPropertiesEndsInspectionProvider(),
};
}
};
new NotNullLazyValue<>() {
@Override
protected InconsistentResourceBundleInspectionProvider @NotNull [] compute() {
return new InconsistentResourceBundleInspectionProvider[]{
new PropertiesKeysConsistencyInspectionProvider(),
new DuplicatedPropertiesInspectionProvider(),
new MissingTranslationsInspectionProvider(),
new PropertiesPlaceholdersInspectionProvider(),
new InconsistentPropertiesEndsInspectionProvider(),
};
}
};
private final Map<String, Boolean> mySettings = new LinkedHashMap<>();
@@ -51,8 +45,7 @@ public class InconsistentResourceBundleInspection extends GlobalSimpleInspection
}
@Override
@Nullable
public JComponent createOptionsPanel() {
public @NotNull JComponent createOptionsPanel() {
final MultipleCheckboxOptionsPanel panel = new MultipleCheckboxOptionsPanel(new OptionAccessor() {
@Override
public boolean getOption(String optionName) {
@@ -124,9 +117,9 @@ public class InconsistentResourceBundleInspection extends GlobalSimpleInspection
}
}
final Map<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps = FactoryMap.create(key -> key.getNamesMap());
Map<PropertiesFile, Set<String>> keysUpToParent = new THashMap<>();
Map<PropertiesFile, Set<String>> keysUpToParent = new HashMap<>();
for (PropertiesFile f : files) {
Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(f).keySet());
Set<String> keys = new HashSet<>(propertiesFilesNamesMaps.get(f).keySet());
PropertiesFile parent = parents.get(f);
while (parent != null) {
keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.i18n.inconsistentResourceBundle;
import com.intellij.codeInspection.*;
@@ -21,9 +7,9 @@ import com.intellij.java.i18n.JavaI18nBundle;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.util.containers.BidirectionalMap;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,7 +17,7 @@ import java.util.Set;
/**
* @author Dmitry Batkovich
*/
public class MissingTranslationsInspectionProvider implements InconsistentResourceBundleInspectionProvider {
public final class MissingTranslationsInspectionProvider implements InconsistentResourceBundleInspectionProvider {
@NotNull
@Override
public String getName() {
@@ -59,14 +45,14 @@ public class MissingTranslationsInspectionProvider implements InconsistentResour
boolean isLeaf = children == null || children.isEmpty();
if (!isLeaf) continue;
Set<String> keys = propertiesFilesNamesMaps.get(file).keySet();
Set<String> parentKeys = new THashSet<>(keysUpToParent.get(parent));
Set<String> parentKeys = new HashSet<>(keysUpToParent.get(parent));
if (parent.getLocale().getLanguage().equals(file.getLocale().getLanguage())) {
// properties can be left untranslated in the dialect files
keys = new THashSet<>(keys);
keys = new HashSet<>(keys);
keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());
parent = parents.get(parent);
if (parent == null) continue;
parentKeys = new THashSet<>(keysUpToParent.get(parent));
parentKeys = new HashSet<>(keysUpToParent.get(parent));
}
parentKeys.removeAll(keys);
for (String untranslatedKey : parentKeys) {

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.i18n.inconsistentResourceBundle;
import com.intellij.codeInspection.*;
@@ -21,9 +7,9 @@ import com.intellij.java.i18n.JavaI18nBundle;
import com.intellij.lang.properties.IProperty;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.util.containers.BidirectionalMap;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,7 +17,7 @@ import java.util.Set;
/**
* @author Dmitry Batkovich
*/
public class PropertiesKeysConsistencyInspectionProvider implements InconsistentResourceBundleInspectionProvider {
public final class PropertiesKeysConsistencyInspectionProvider implements InconsistentResourceBundleInspectionProvider {
@NotNull
@Override
public String getName() {
@@ -56,7 +42,7 @@ public class PropertiesKeysConsistencyInspectionProvider implements Inconsistent
PropertiesFile parent = parents.get(file);
Set<String> parentKeys = keysUpToParent.get(parent);
if (parent == null) {
parentKeys = new THashSet<>();
parentKeys = new HashSet<>();
for (PropertiesFile otherTopLevelFile : files) {
if (otherTopLevelFile != file && parents.get(otherTopLevelFile) == null) {
parent = otherTopLevelFile;
@@ -65,7 +51,7 @@ public class PropertiesKeysConsistencyInspectionProvider implements Inconsistent
}
if (parent == null) continue;
}
Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
Set<String> keys = new HashSet<>(propertiesFilesNamesMaps.get(file).keySet());
keys.removeAll(parentKeys);
for (String inconsistentKey : keys) {
IProperty property = file.findPropertyByKey(inconsistentKey);

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection.i18n.inconsistentResourceBundle;
import com.intellij.codeInspection.InspectionManager;
@@ -27,18 +13,14 @@ import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.BidirectionalMap;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* @author Dmitry Batkovich
*/
public class PropertiesPlaceholdersInspectionProvider implements InconsistentResourceBundleInspectionProvider {
public final class PropertiesPlaceholdersInspectionProvider implements InconsistentResourceBundleInspectionProvider {
@NotNull
@Override
public String getName() {
@@ -60,7 +42,7 @@ public class PropertiesPlaceholdersInspectionProvider implements InconsistentRes
RefManager refManager,
ProblemDescriptionsProcessor processor) {
for (PropertiesFile file : files) {
final Set<String> filePropertyKeys = new THashSet<>(propertiesFilesNamesMaps.get(file).keySet());
final Set<String> filePropertyKeys = new HashSet<>(propertiesFilesNamesMaps.get(file).keySet());
PropertiesFile parent = parents.get(file);
while (parent != null) {
final Collection<String> commonKeys = ContainerUtil.intersection(propertiesFilesNamesMaps.get(parent).keySet(), filePropertyKeys);