IDEA-179713 Add conversion empty list literal to Set

This commit is contained in:
alexey.afanasiev
2017-10-10 17:45:46 +03:00
parent 4ffd02dd8b
commit cee5232a5e
2 changed files with 30 additions and 25 deletions
@@ -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? {
@@ -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[]']
}