mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-179713 Add conversion empty list literal to Set
This commit is contained in:
+22
-23
@@ -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-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.
|
||||
package org.jetbrains.plugins.groovy.lang.typing
|
||||
|
||||
import com.intellij.openapi.util.RecursionManager.doPreventingRecursion
|
||||
@@ -65,17 +51,30 @@ class DefaultListOrMapTypeCalculator : GrTypeCalculator<GrListOrMap> {
|
||||
if (initializers.isNotEmpty()) return null
|
||||
|
||||
val lType = PsiImplUtil.inferExpectedTypeForDiamond(expression)
|
||||
if (lType !is PsiClassType || !isInheritor(lType, CommonClassNames.JAVA_UTIL_LIST)) return null
|
||||
|
||||
if (lType !is PsiClassType) return null
|
||||
val scope = expression.resolveScope
|
||||
val facade = JavaPsiFacade.getInstance(expression.project)
|
||||
|
||||
val arrayList = facade.findClass(CommonClassNames.JAVA_UTIL_ARRAY_LIST, scope) ?:
|
||||
facade.findClass(CommonClassNames.JAVA_UTIL_LIST, scope) ?: return null
|
||||
return facade.elementFactory.createType(
|
||||
arrayList,
|
||||
substituteTypeParameter(lType, CommonClassNames.JAVA_UTIL_LIST, 0, false)
|
||||
)
|
||||
if (isInheritor(lType, CommonClassNames.JAVA_UTIL_LIST)) {
|
||||
val arrayList = facade.findClass(CommonClassNames.JAVA_UTIL_ARRAY_LIST, scope) ?:
|
||||
facade.findClass(CommonClassNames.JAVA_UTIL_LIST, scope) ?: return null
|
||||
|
||||
return facade.elementFactory.createType(
|
||||
arrayList,
|
||||
substituteTypeParameter(lType, CommonClassNames.JAVA_UTIL_LIST, 0, false)
|
||||
)
|
||||
}
|
||||
if (isInheritor(lType, CommonClassNames.JAVA_UTIL_SET)) {
|
||||
val set = facade.findClass("java.util.LinkedHashSet", scope) ?:
|
||||
facade.findClass(CommonClassNames.JAVA_UTIL_SET, scope) ?: return null
|
||||
|
||||
return facade.elementFactory.createType(
|
||||
set,
|
||||
substituteTypeParameter(lType, CommonClassNames.JAVA_UTIL_SET, 0, false)
|
||||
)
|
||||
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun getTupleType(expression: GrListOrMap): PsiType? {
|
||||
|
||||
+8
-2
@@ -19,7 +19,8 @@ class GrAssignAutoTestFalsePositiveTest extends GrHighlightingTestBase {
|
||||
|
||||
List<String> types = ['boolean', 'int', 'double', 'String', 'Integer', 'BigDecimal', 'BigInteger', 'List', 'Object', 'Thread',
|
||||
'List<BigDecimal>', 'List<BigInteger>', 'List<Integer>', 'List<String>', 'List<Object>', 'List<Thread>', 'boolean[]',
|
||||
'int[]', 'double[]', 'String[]', 'Integer[]', 'List[]', 'Object[]', 'Thread[]', 'short', 'byte']
|
||||
'int[]', 'double[]', 'String[]', 'Integer[]', 'List[]', 'Object[]', 'Thread[]', 'short', 'byte', 'Set', 'Set<String>',
|
||||
'Set<Integer>', 'Set<Object>', 'Set<Thread>']
|
||||
|
||||
List<String> values = ['true', '0', '1', '(int)1', '(short)1', '(byte)1', '1.1', '1.1d', '1.1f', '"1"', '["1"]', '1f', '"str"', 'null', 'new Object()',
|
||||
'new Thread()', '[]' /*, '[1]', '[(int)1]', '[(byte)1]'*/, '[1.1]', '[1.1d]', '[1.1f]', '["str"]', 'new ArrayList<>()',
|
||||
@@ -59,7 +60,12 @@ class GrAssignAutoTestFalsePositiveTest extends GrHighlightingTestBase {
|
||||
'List<Thread> -> String[]', 'List<Thread> -> Integer[]', 'List<Thread> -> List[]', 'boolean[] -> int[]', 'boolean[] -> double[]',
|
||||
'boolean[] -> String[]', 'int[] -> boolean[]', 'int[] -> String[]', 'double[] -> boolean[]', 'double[] -> String[]',
|
||||
'String[] -> boolean[]', 'Integer[] -> boolean[]', 'Integer[] -> String[]', 'List[] -> boolean[]', 'List[] -> String[]',
|
||||
'Object[] -> boolean[]', 'Object[] -> String[]', 'Thread[] -> boolean[]', 'Thread[] -> String[]']
|
||||
'Object[] -> boolean[]', 'Object[] -> String[]', 'Thread[] -> boolean[]', 'Thread[] -> String[]', 'Set<String> -> boolean[]',
|
||||
'Set<String> -> int[]', 'Set<String> -> double[]', 'Set<String> -> Integer[]', 'Set<String> -> List[]', 'Set<String> -> Thread[]',
|
||||
'Set<Integer> -> boolean[]', 'Set<Integer> -> String[]', 'Set<Integer> -> List[]', 'Set<Integer> -> Thread[]',
|
||||
'Set<Object> -> boolean[]', 'Set<Object> -> int[]', 'Set<Object> -> double[]', 'Set<Object> -> String[]',
|
||||
'Set<Object> -> Integer[]', 'Set<Object> -> List[]', 'Set<Object> -> Thread[]', 'Set<Thread> -> boolean[]',
|
||||
'Set<Thread> -> int[]', 'Set<Thread> -> double[]', 'Set<Thread> -> String[]', 'Set<Thread> -> Integer[]', 'Set<Thread> -> List[]']
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user