add few FQN constants CommonClassNames and use them

- `JAVA_UTIL_LINKED_HASH_SET`
- `JAVA_UTIL_LINKED_LIST`
- `JAVA_UTIL_QUEUE`
- `JAVA_UTIL_SORTED_SET`
- `JAVA_UTIL_STACK`

GitOrigin-RevId: 14129d2a0ed006a9df3bc84a3d45a182a4c66964
This commit is contained in:
Daniil Ovchinnikov
2019-11-21 16:17:15 +00:00
committed by intellij-monorepo-bot
parent 8333ebe6df
commit ffbcf84f82
15 changed files with 48 additions and 113 deletions
@@ -30,7 +30,7 @@ class DebuggerDfaRunner extends DataFlowRunner {
};
private static final Set<String> COLLECTIONS_WITH_SIZE_FIELD =
ContainerUtil.immutableSet(CommonClassNames.JAVA_UTIL_ARRAY_LIST,
"java.util.LinkedList",
CommonClassNames.JAVA_UTIL_LINKED_LIST,
CommonClassNames.JAVA_UTIL_HASH_MAP,
"java.util.TreeMap");
private final @NotNull PsiCodeBlock myBody;
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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-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.
package com.intellij.codeInspection.dataFlow;
import com.intellij.codeInspection.dataFlow.StandardMethodContract.ValueConstraint;
@@ -55,7 +41,7 @@ public class HardcodedContracts {
);
private static final CallMatcher QUEUE_POLL = anyOf(
instanceCall("java.util.Queue", "poll").parameterCount(0),
instanceCall(JAVA_UTIL_QUEUE, "poll").parameterCount(0),
instanceCall("java.util.Deque", "pollFirst", "pollLast").parameterCount(0)
);
@@ -109,9 +95,9 @@ public class HardcodedContracts {
.register(instanceCall(JAVA_UTIL_LIST, "get", "remove").parameterTypes("int"),
ContractProvider.of(specialFieldRangeContract(0, RelationType.LT, SpecialField.COLLECTION_SIZE)))
.register(anyOf(
instanceCall("java.util.SortedSet", "first", "last").parameterCount(0),
instanceCall(JAVA_UTIL_SORTED_SET, "first", "last").parameterCount(0),
instanceCall("java.util.Deque", "getFirst", "getLast").parameterCount(0),
instanceCall("java.util.Queue", "element").parameterCount(0)),
instanceCall(JAVA_UTIL_QUEUE, "element").parameterCount(0)),
ContractProvider.of(singleConditionContract(
ContractValue.qualifier().specialField(SpecialField.COLLECTION_SIZE), RelationType.EQ,
ContractValue.zero(), fail())))
@@ -122,7 +108,7 @@ public class HardcodedContracts {
.register(staticCall("org.mockito.ArgumentMatchers", "argThat").parameterCount(1),
ContractProvider.of(StandardMethodContract.fromText("_->_")))
.register(anyOf(
instanceCall("java.util.Queue", "peek", "poll").parameterCount(0),
instanceCall(JAVA_UTIL_QUEUE, "peek", "poll").parameterCount(0),
instanceCall("java.util.Deque", "peekFirst", "peekLast", "pollFirst", "pollLast").parameterCount(0)),
(call, paramCount) -> Arrays.asList(singleConditionContract(
ContractValue.qualifier().specialField(SpecialField.COLLECTION_SIZE), RelationType.EQ,
@@ -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-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.
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
@@ -68,7 +54,7 @@ class CollectionsUtilityMethodsProvider {
addCollectionMethod(JAVA_UTIL_LIST, "unmodifiableList", collectionsClass);
addCollectionMethod(JAVA_UTIL_SET, "unmodifiableSet", collectionsClass);
addCollectionMethod(JAVA_UTIL_MAP, "unmodifiableMap", collectionsClass);
addCollectionMethod("java.util.SortedSet", "unmodifiableSortedSet", collectionsClass);
addCollectionMethod(JAVA_UTIL_SORTED_SET, "unmodifiableSortedSet", collectionsClass);
addCollectionMethod("java.util.SortedMap", "unmodifiableSortedMap", collectionsClass);
}
@@ -29,7 +29,6 @@ import static com.intellij.util.ObjectUtils.tryCast;
* @author Pavel.Dolgov
*/
public class WrapWithUnmodifiableAction extends BaseIntentionAction {
private static final String JAVA_UTIL_SORTED_SET = "java.util.SortedSet";
private static final String JAVA_UTIL_SORTED_MAP = "java.util.SortedMap";
@Override
@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-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.
package com.intellij.codeInspection.streamMigration;
import com.intellij.codeInsight.Nullability;
@@ -41,9 +41,9 @@ class CollectMigration extends BaseStreamApiMigration {
static final Map<String, String> INTERMEDIATE_STEPS = EntryStream.of(
CommonClassNames.JAVA_UTIL_ARRAY_LIST, "",
"java.util.LinkedList", "",
CommonClassNames.JAVA_UTIL_LINKED_LIST, "",
CommonClassNames.JAVA_UTIL_HASH_SET, ".distinct()",
"java.util.LinkedHashSet", ".distinct()",
CommonClassNames.JAVA_UTIL_LINKED_HASH_SET, ".distinct()",
"java.util.TreeSet", ".distinct().sorted()"
).toMap();
@@ -897,7 +897,7 @@ class CollectMigration extends BaseStreamApiMigration {
static class UnmodifiableTerminal extends RecreateTerminal {
private static final Map<String, String> TYPE_TO_UNMODIFIABLE_WRAPPER = EntryStream.of(
CommonClassNames.JAVA_UTIL_ARRAY_LIST, "toUnmodifiableList",
"java.util.LinkedList", "toUnmodifiableList",
CommonClassNames.JAVA_UTIL_LINKED_LIST, "toUnmodifiableList",
CommonClassNames.JAVA_UTIL_HASH_SET, "toUnmodifiableSet",
CommonClassNames.JAVA_UTIL_HASH_MAP, "toUnmodifiableMap"
).toMap();
@@ -47,8 +47,13 @@ public interface CommonClassNames {
String JAVA_UTIL_CONCURRENT_HASH_MAP = "java.util.concurrent.ConcurrentHashMap";
String JAVA_UTIL_LIST = "java.util.List";
String JAVA_UTIL_ARRAY_LIST = "java.util.ArrayList";
String JAVA_UTIL_LINKED_LIST = "java.util.LinkedList";
String JAVA_UTIL_SET = "java.util.Set";
String JAVA_UTIL_HASH_SET = "java.util.HashSet";
String JAVA_UTIL_LINKED_HASH_SET = "java.util.LinkedHashSet";
String JAVA_UTIL_SORTED_SET = "java.util.SortedSet";
String JAVA_UTIL_QUEUE = "java.util.Queue";
String JAVA_UTIL_STACK = "java.util.Stack";
String JAVA_UTIL_PROPERTIES = "java.util.Properties";
String JAVA_UTIL_PROPERTY_RESOURCE_BUNDLE = "java.util.PropertyResourceBundle";
String JAVA_UTIL_DATE = "java.util.Date";
@@ -74,7 +74,7 @@ public class SetReplaceableByEnumSetInspection extends BaseInspection {
@Override
protected List<String> getUnreplaceableCollectionNames() {
return Arrays.asList("java.util.concurrent.CopyOnWriteArraySet", "java.util.concurrent.ConcurrentSkipListSet",
"java.util.LinkedHashSet");
CommonClassNames.JAVA_UTIL_LINKED_HASH_SET);
}
@NotNull
@@ -74,16 +74,16 @@ public class CollectionUtils {
"java.util.Hashtable",
"java.util.IdentityHashMap",
"java.util.LinkedHashMap",
"java.util.LinkedHashSet",
"java.util.LinkedList",
CommonClassNames.JAVA_UTIL_LINKED_HASH_SET,
CommonClassNames.JAVA_UTIL_LINKED_LIST,
CommonClassNames.JAVA_UTIL_LIST,
CommonClassNames.JAVA_UTIL_MAP,
"java.util.PriorityQueue",
"java.util.Queue",
CommonClassNames.JAVA_UTIL_QUEUE,
CommonClassNames.JAVA_UTIL_SET,
"java.util.SortedMap",
"java.util.SortedSet",
"java.util.Stack",
CommonClassNames.JAVA_UTIL_SORTED_SET,
CommonClassNames.JAVA_UTIL_STACK,
"java.util.TreeMap",
"java.util.TreeSet",
"java.util.Vector",
@@ -144,9 +144,9 @@ public class CollectionUtils {
s_interfaceForCollection.put("java.util.Hashtable", CommonClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.IdentityHashMap", CommonClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.LinkedHashMap", CommonClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.LinkedHashSet", CommonClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put("java.util.LinkedList", CommonClassNames.JAVA_UTIL_LIST);
s_interfaceForCollection.put("java.util.PriorityQueue", "java.util.Queue");
s_interfaceForCollection.put(CommonClassNames.JAVA_UTIL_LINKED_HASH_SET, CommonClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put(CommonClassNames.JAVA_UTIL_LINKED_LIST, CommonClassNames.JAVA_UTIL_LIST);
s_interfaceForCollection.put("java.util.PriorityQueue", CommonClassNames.JAVA_UTIL_QUEUE);
s_interfaceForCollection.put("java.util.TreeMap", CommonClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.TreeSet", CommonClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put("java.util.Vector", CommonClassNames.JAVA_UTIL_LIST);
@@ -63,7 +63,7 @@ public class MismatchedCollectionQueryUpdateInspection
CollectionUtils.DERIVED_COLLECTION,
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_LIST, "subList"),
CallMatcher.instanceCall("java.util.SortedMap", "headMap", "tailMap", "subMap"),
CallMatcher.instanceCall("java.util.SortedSet", "headSet", "tailSet", "subSet"));
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_SORTED_SET, "headSet", "tailSet", "subSet"));
private static final CallMatcher COLLECTION_SAFE_ARGUMENT_METHODS =
CallMatcher.anyOf(
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_COLLECTION, "addAll", "removeAll", "containsAll", "remove"),
@@ -1,4 +1,4 @@
// Copyright 2000-2017 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-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.
package com.siyeh.ig.encapsulation;
import com.intellij.codeInspection.CommonQuickFixBundle;
@@ -40,8 +40,8 @@ class ReturnOfCollectionFieldFix extends InspectionGadgetsFix {
}
else if (TypeUtils.expressionHasTypeOrSubtype(referenceExpression, CommonClassNames.JAVA_UTIL_COLLECTION)) {
if (TypeUtils.expressionHasTypeOrSubtype(referenceExpression, CommonClassNames.JAVA_UTIL_SET)) {
if (TypeUtils.expressionHasTypeOrSubtype(referenceExpression, "java.util.SortedSet")) {
return new ReturnOfCollectionFieldFix("java.util.Collections.unmodifiableSortedSet(" + text + ')', "java.util.SortedSet");
if (TypeUtils.expressionHasTypeOrSubtype(referenceExpression, CommonClassNames.JAVA_UTIL_SORTED_SET)) {
return new ReturnOfCollectionFieldFix("java.util.Collections.unmodifiableSortedSet(" + text + ')', CommonClassNames.JAVA_UTIL_SORTED_SET);
}
return new ReturnOfCollectionFieldFix("java.util.Collections.unmodifiableSet(" + text + ')', CommonClassNames.JAVA_UTIL_SET);
}
@@ -118,7 +118,7 @@ public class MethodCallInLoopConditionInspection extends BaseInspection {
MethodCallUtils.isCallToMethod(expression, "java.util.ListIterator", PsiType.BOOLEAN, "hasPrevious") ||
MethodCallUtils.isCallToMethod(expression, "java.sql.ResultSet", PsiType.BOOLEAN, "next") ||
MethodCallUtils.isCallToMethod(expression, "java.util.Enumeration", PsiType.BOOLEAN, "hasMoreElements") ||
MethodCallUtils.isCallToMethod(expression, "java.util.Queue", null, "poll") ||
MethodCallUtils.isCallToMethod(expression, CommonClassNames.JAVA_UTIL_QUEUE, null, "poll") ||
MethodCallUtils.isCallToMethod(expression, "java.lang.ref.ReferenceQueue", null, "poll");
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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-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.
package com.siyeh.ig.performance;
import com.intellij.codeInsight.daemon.QuickFixBundle;
@@ -48,7 +34,7 @@ public abstract class CollectionsListSettings {
set.add("java.util.HashSet");
set.add("java.util.IdentityHashMap");
set.add("java.util.LinkedHashMap");
set.add("java.util.LinkedHashSet");
set.add(CommonClassNames.JAVA_UTIL_LINKED_HASH_SET);
set.add("java.util.PriorityQueue");
set.add("java.util.Vector");
set.add("java.util.WeakHashMap");
@@ -3,6 +3,7 @@ package org.jetbrains.idea.devkit.util;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
@@ -62,7 +63,7 @@ public class ExtensionLocatorTest extends LightJavaCodeInsightFixtureTestCase {
myFixture.copyFileToProject("SomeClass.java");
PsiClass arrayListPsiClass = myFixture.findClass("java.util.ArrayList");
PsiClass linkedListPsiClass = myFixture.findClass("java.util.LinkedList");
PsiClass linkedListPsiClass = myFixture.findClass(CommonClassNames.JAVA_UTIL_LINKED_LIST);
PsiClass myList1PsiClass = myFixture.findClass("SomeClass.MyList1");
PsiClass myList2PsiClass = myFixture.findClass("SomeClass.MyList2");
@@ -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-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.
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions;
import com.intellij.openapi.project.Project;
@@ -24,20 +10,20 @@ import org.jetbrains.annotations.Nullable;
public class CollectionUtil {
@Nullable
public static PsiClassType createSimilarCollection(@Nullable PsiType collection, Project project, PsiType... itemType) {
if (InheritanceUtil.isInheritor(collection, "java.util.SortedSet")) {
return createCollection(project, "java.util.SortedSet", itemType);
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_SORTED_SET)) {
return createCollection(project, CommonClassNames.JAVA_UTIL_SORTED_SET, itemType);
}
if (InheritanceUtil.isInheritor(collection, "java.util.LinkedHashSet")) {
return createCollection(project, "java.util.LinkedHashSet", itemType);
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_LINKED_HASH_SET)) {
return createCollection(project, CommonClassNames.JAVA_UTIL_LINKED_HASH_SET, itemType);
}
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_SET)) {
return createCollection(project, "java.util.HashSet", itemType);
}
if (InheritanceUtil.isInheritor(collection, "java.util.LinkedList")) {
return createCollection(project, "java.util.LInkedList", itemType);
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_LINKED_LIST)) {
return createCollection(project, CommonClassNames.JAVA_UTIL_LINKED_LIST, itemType);
}
if (InheritanceUtil.isInheritor(collection, "java.util.Stack")) {
return createCollection(project, "java.util.Stack", itemType);
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_STACK)) {
return createCollection(project, CommonClassNames.JAVA_UTIL_STACK, itemType);
}
if (InheritanceUtil.isInheritor(collection, "java.util.Vector")) {
return createCollection(project, "java.util.Vector", itemType);
@@ -45,8 +31,8 @@ public class CollectionUtil {
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_LIST)) {
return createCollection(project, "java.util.ArrayList", itemType);
}
if (InheritanceUtil.isInheritor(collection, "java.util.Queue")) {
return createCollection(project, "java.util.LinkedList", itemType);
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_QUEUE)) {
return createCollection(project, CommonClassNames.JAVA_UTIL_LINKED_LIST, itemType);
}
return createCollection(project, "java.util.ArrayList", itemType);
@@ -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-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.
package org.jetbrains.idea.maven.dom;
import com.intellij.openapi.util.Key;
@@ -51,7 +37,7 @@ public class MavenPluginConfigurationDomExtender extends DomExtender<MavenDomCon
private static final Set<String> COLLECTIONS_TYPE_NAMES = ContainerUtil.immutableSet("java.util.Collection", CommonClassNames.JAVA_UTIL_SET,
CommonClassNames.JAVA_UTIL_LIST,
"java.util.ArrayList", "java.util.HashSet",
"java.util.LinkedList");
CommonClassNames.JAVA_UTIL_LINKED_LIST);
@Override
public void registerExtensions(@NotNull MavenDomConfiguration config, @NotNull DomExtensionsRegistrar r) {