From 84a7e3c032932c3d18bf15a774bf2c48934176e4 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 2 Dec 2016 21:41:20 +0300 Subject: [PATCH] Add tests for enhanced java signatures based on AbstractResolvedCallsTest. Refactor AbstractResolvedCallsTest to support multiple carets (multiple methods being tested for resolve) in testdata file. --- .../collection/collectionRemoveIf.kt | 11 + .../collection/collectionRemoveIf.txt | 20 ++ .../collection/collectionSpliterator.kt | 12 ++ .../collection/collectionSpliterator.txt | 21 ++ .../collection/collectionStream.kt | 14 ++ .../collection/collectionStream.txt | 32 +++ .../iterable/iterableSpliterator.kt | 11 + .../iterable/iterableSpliterator.txt | 20 ++ .../iterator/iteratorForEachRemaining.kt | 7 + .../iterator/iteratorForEachRemaining.txt | 13 ++ .../enhancedSignatures/list/listReplaceAll.kt | 9 + .../list/listReplaceAll.txt | 15 ++ .../enhancedSignatures/list/listStream.kt | 14 ++ .../enhancedSignatures/list/listStream.txt | 32 +++ .../enhancedSignatures/map/mapCompute.kt | 19 ++ .../enhancedSignatures/map/mapCompute.txt | 34 +++ .../map/mapComputeIfAbsent.kt | 19 ++ .../map/mapComputeIfAbsent.txt | 34 +++ .../map/mapComputeIfPresent.kt | 19 ++ .../map/mapComputeIfPresent.txt | 34 +++ .../enhancedSignatures/map/mapForEach.kt | 7 + .../enhancedSignatures/map/mapForEach.txt | 13 ++ .../enhancedSignatures/map/mapMerge.kt | 21 ++ .../enhancedSignatures/map/mapMerge.txt | 42 ++++ .../enhancedSignatures/map/mapPutIfAbsent.kt | 7 + .../enhancedSignatures/map/mapPutIfAbsent.txt | 14 ++ .../enhancedSignatures/map/mapReplace.kt | 13 ++ .../enhancedSignatures/map/mapReplace.txt | 32 +++ .../optional/optionalEmpty.kt | 6 + .../optional/optionalEmpty.txt | 13 ++ .../optional/optionalGet.kt | 9 + .../optional/optionalGet.txt | 16 ++ .../optional/optionalIfPresent.kt | 9 + .../optional/optionalIfPresent.txt | 16 ++ .../enhancedSignatures/optional/optionalOf.kt | 9 + .../optional/optionalOf.txt | 19 ++ ...ractEnhancedSignaturesResolvedCallsTest.kt | 56 +++++ .../calls/AbstractResolvedCallsTest.kt | 60 ++++-- ...ResolvedConstructorDelegationCallsTests.kt | 6 +- ...dSignaturesResolvedCallsTestGenerated.java | 200 ++++++++++++++++++ .../calls/ResolvedCallsTestGenerated.java | 2 +- .../kotlin/generators/tests/GenerateTests.kt | 7 +- 42 files changed, 946 insertions(+), 21 deletions(-) create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.txt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.kt create mode 100644 compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt create mode 100644 compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractEnhancedSignaturesResolvedCallsTest.kt create mode 100644 compiler/tests-java8/tests/org/jetbrains/kotlin/resolve/calls/EnhancedSignaturesResolvedCallsTestGenerated.java diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.kt b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.kt new file mode 100644 index 00000000000..f4332a81fac --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.kt @@ -0,0 +1,11 @@ +fun notNullValues(collection: MutableCollection) { + collection.removeIf { it.length > 5 } +} + +fun nullableValues(collection: MutableCollection) { + collection.removeIf { it != null && it.length > 5 } +} + +fun nullableValues2(collection: MutableCollection) { + collection.removeIf { it == null } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.txt b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.txt new file mode 100644 index 00000000000..a9472fce8c7 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.txt @@ -0,0 +1,20 @@ +fun notNullValues(collection: MutableCollection) { + collection.removeIf { it.length > 5 } + // SUCCESS + // ORIGINAL: fun removeIf((E) -> Boolean): Boolean defined in kotlin.collections.MutableCollection + // SUBSTITUTED: fun removeIf((String) -> Boolean): Boolean defined in kotlin.collections.MutableCollection +} + +fun nullableValues(collection: MutableCollection) { + collection.removeIf { it != null && it.length > 5 } + // SUCCESS + // ORIGINAL: fun removeIf((E) -> Boolean): Boolean defined in kotlin.collections.MutableCollection + // SUBSTITUTED: fun removeIf((E?) -> Boolean): Boolean defined in kotlin.collections.MutableCollection +} + +fun nullableValues2(collection: MutableCollection) { + collection.removeIf { it == null } + // SUCCESS + // ORIGINAL: fun removeIf((E) -> Boolean): Boolean defined in kotlin.collections.MutableCollection + // SUBSTITUTED: fun removeIf((E) -> Boolean): Boolean defined in kotlin.collections.MutableCollection +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.kt b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.kt new file mode 100644 index 00000000000..583e33973e3 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.kt @@ -0,0 +1,12 @@ +// TODO: Fix platform types +fun notNullValues(collection: Collection) { + collection.spliterator() +} + +fun nullableValues(collection: Collection) { + collection.spliterator() +} + +fun nullableValues2(collection: Collection) { + collection.spliterator() +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.txt b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.txt new file mode 100644 index 00000000000..1ef23d71003 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.txt @@ -0,0 +1,21 @@ +// TODO: Fix platform types +fun notNullValues(collection: Collection) { + collection.spliterator() + // SUCCESS + // ORIGINAL: fun spliterator(): Spliterator defined in kotlin.collections.Collection + // SUBSTITUTED: fun spliterator(): Spliterator defined in kotlin.collections.Collection +} + +fun nullableValues(collection: Collection) { + collection.spliterator() + // SUCCESS + // ORIGINAL: fun spliterator(): Spliterator defined in kotlin.collections.Collection + // SUBSTITUTED: fun spliterator(): Spliterator defined in kotlin.collections.Collection +} + +fun nullableValues2(collection: Collection) { + collection.spliterator() + // SUCCESS + // ORIGINAL: fun spliterator(): Spliterator defined in kotlin.collections.Collection + // SUBSTITUTED: fun spliterator(): Spliterator defined in kotlin.collections.Collection +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.kt b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.kt new file mode 100644 index 00000000000..60094b94fc2 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.kt @@ -0,0 +1,14 @@ +fun notNullValues(collection: Collection) { + collection.stream() + collection.parallelStream() +} + +fun nullableValues(collection: Collection) { + collection.stream() + collection.parallelStream() +} + +fun nullableValues2(collection: Collection) { + collection.stream() + collection.parallelStream() +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.txt b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.txt new file mode 100644 index 00000000000..65f75568b31 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.txt @@ -0,0 +1,32 @@ +fun notNullValues(collection: Collection) { + collection.stream() + // SUCCESS + // ORIGINAL: fun stream(): Stream defined in kotlin.collections.Collection + // SUBSTITUTED: fun stream(): Stream defined in kotlin.collections.Collection + collection.parallelStream() + // SUCCESS + // ORIGINAL: fun parallelStream(): Stream defined in kotlin.collections.Collection + // SUBSTITUTED: fun parallelStream(): Stream defined in kotlin.collections.Collection +} + +fun nullableValues(collection: Collection) { + collection.stream() + // SUCCESS + // ORIGINAL: fun stream(): Stream defined in kotlin.collections.Collection + // SUBSTITUTED: fun stream(): Stream defined in kotlin.collections.Collection + collection.parallelStream() + // SUCCESS + // ORIGINAL: fun parallelStream(): Stream defined in kotlin.collections.Collection + // SUBSTITUTED: fun parallelStream(): Stream defined in kotlin.collections.Collection +} + +fun nullableValues2(collection: Collection) { + collection.stream() + // SUCCESS + // ORIGINAL: fun stream(): Stream defined in kotlin.collections.Collection + // SUBSTITUTED: fun stream(): Stream defined in kotlin.collections.Collection + collection.parallelStream() + // SUCCESS + // ORIGINAL: fun parallelStream(): Stream defined in kotlin.collections.Collection + // SUBSTITUTED: fun parallelStream(): Stream defined in kotlin.collections.Collection +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.kt b/compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.kt new file mode 100644 index 00000000000..e7eae959593 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.kt @@ -0,0 +1,11 @@ +fun notNullValues(collection: Iterable) { + collection.spliterator() +} + +fun nullableValues(collection: Iterable) { + collection.spliterator() +} + +fun nullableValues2(collection: Iterable) { + collection.spliterator() +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.txt b/compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.txt new file mode 100644 index 00000000000..7c88143f376 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.txt @@ -0,0 +1,20 @@ +fun notNullValues(collection: Iterable) { + collection.spliterator() + // SUCCESS + // ORIGINAL: fun spliterator(): Spliterator defined in kotlin.collections.Iterable + // SUBSTITUTED: fun spliterator(): Spliterator defined in kotlin.collections.Iterable +} + +fun nullableValues(collection: Iterable) { + collection.spliterator() + // SUCCESS + // ORIGINAL: fun spliterator(): Spliterator defined in kotlin.collections.Iterable + // SUBSTITUTED: fun spliterator(): Spliterator defined in kotlin.collections.Iterable +} + +fun nullableValues2(collection: Iterable) { + collection.spliterator() + // SUCCESS + // ORIGINAL: fun spliterator(): Spliterator defined in kotlin.collections.Iterable + // SUBSTITUTED: fun spliterator(): Spliterator defined in kotlin.collections.Iterable +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.kt b/compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.kt new file mode 100644 index 00000000000..f3c4699bf03 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.kt @@ -0,0 +1,7 @@ +fun notNullValues(it: Iterator) { + it.forEachRemaining { e -> } +} + +fun mutableNullableValues(it: MutableIterator) { + it.forEachRemaining { e -> } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.txt b/compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.txt new file mode 100644 index 00000000000..227328b4923 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.txt @@ -0,0 +1,13 @@ +fun notNullValues(it: Iterator) { + it.forEachRemaining { e -> } + // SUCCESS + // ORIGINAL: fun forEachRemaining((T) -> Unit): Unit defined in kotlin.collections.Iterator + // SUBSTITUTED: fun forEachRemaining((String) -> Unit): Unit defined in kotlin.collections.Iterator +} + +fun mutableNullableValues(it: MutableIterator) { + it.forEachRemaining { e -> } + // SUCCESS + // ORIGINAL: fun forEachRemaining((T) -> Unit): Unit defined in kotlin.collections.MutableIterator + // SUBSTITUTED: fun forEachRemaining((String?) -> Unit): Unit defined in kotlin.collections.MutableIterator +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.kt b/compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.kt new file mode 100644 index 00000000000..009c34094ed --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.kt @@ -0,0 +1,9 @@ +fun notNullValues(list: MutableList) { + // TODO: Fix platform types + list.replaceAll { it.length.toString() } +} + +fun nullableValues(list: MutableList) { + // TODO: Fix platform types + list.replaceAll { it?.run { length.toString() } } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.txt b/compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.txt new file mode 100644 index 00000000000..14b967cabf6 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.txt @@ -0,0 +1,15 @@ +fun notNullValues(list: MutableList) { + // TODO: Fix platform types + list.replaceAll { it.length.toString() } + // SUCCESS + // ORIGINAL: fun replaceAll((E!) -> E!): Unit defined in kotlin.collections.MutableList + // SUBSTITUTED: fun replaceAll((String!) -> String!): Unit defined in kotlin.collections.MutableList +} + +fun nullableValues(list: MutableList) { + // TODO: Fix platform types + list.replaceAll { it?.run { length.toString() } } + // SUCCESS + // ORIGINAL: fun replaceAll((E!) -> E!): Unit defined in kotlin.collections.MutableList + // SUBSTITUTED: fun replaceAll((String?) -> String?): Unit defined in kotlin.collections.MutableList +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.kt b/compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.kt new file mode 100644 index 00000000000..3e7f6d1397f --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.kt @@ -0,0 +1,14 @@ +fun notNullValues(collection: List) { + collection.stream() + collection.parallelStream() +} + +fun nullableValues(collection: List) { + collection.stream() + collection.parallelStream() +} + +fun nullableValues2(collection: List) { + collection.stream() + collection.parallelStream() +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.txt b/compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.txt new file mode 100644 index 00000000000..cd36919cf8b --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.txt @@ -0,0 +1,32 @@ +fun notNullValues(collection: List) { + collection.stream() + // SUCCESS + // ORIGINAL: fun stream(): Stream defined in kotlin.collections.List + // SUBSTITUTED: fun stream(): Stream defined in kotlin.collections.List + collection.parallelStream() + // SUCCESS + // ORIGINAL: fun parallelStream(): Stream defined in kotlin.collections.List + // SUBSTITUTED: fun parallelStream(): Stream defined in kotlin.collections.List +} + +fun nullableValues(collection: List) { + collection.stream() + // SUCCESS + // ORIGINAL: fun stream(): Stream defined in kotlin.collections.List + // SUBSTITUTED: fun stream(): Stream defined in kotlin.collections.List + collection.parallelStream() + // SUCCESS + // ORIGINAL: fun parallelStream(): Stream defined in kotlin.collections.List + // SUBSTITUTED: fun parallelStream(): Stream defined in kotlin.collections.List +} + +fun nullableValues2(collection: List) { + collection.stream() + // SUCCESS + // ORIGINAL: fun stream(): Stream defined in kotlin.collections.List + // SUBSTITUTED: fun stream(): Stream defined in kotlin.collections.List + collection.parallelStream() + // SUCCESS + // ORIGINAL: fun parallelStream(): Stream defined in kotlin.collections.List + // SUBSTITUTED: fun parallelStream(): Stream defined in kotlin.collections.List +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.kt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.kt new file mode 100644 index 00000000000..e23b680d697 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.kt @@ -0,0 +1,19 @@ +fun valuesNotNull(map: MutableMap) { + map.compute(1) { k, v -> null } +} + +fun valuesNullable(map: MutableMap) { + map.compute(1) { k, v -> v?.let { it + k } } +} + +fun valuesT(map: MutableMap, newValue: T) { + map.compute(1) { k, v -> null } +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.compute(1) { k, v -> null } +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.compute(1) { k, v -> null } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.txt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.txt new file mode 100644 index 00000000000..36d2a9755ca --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.txt @@ -0,0 +1,34 @@ +fun valuesNotNull(map: MutableMap) { + map.compute(1) { k, v -> null } + // SUCCESS + // ORIGINAL: fun compute(K, (K, V?) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun compute(Int, (Int, String?) -> String?): String? defined in kotlin.collections.MutableMap +} + +fun valuesNullable(map: MutableMap) { + map.compute(1) { k, v -> v?.let { it + k } } + // SUCCESS + // ORIGINAL: fun compute(K, (K, V?) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun compute(Int, (Int, String?) -> String?): String? defined in kotlin.collections.MutableMap +} + +fun valuesT(map: MutableMap, newValue: T) { + map.compute(1) { k, v -> null } + // SUCCESS + // ORIGINAL: fun compute(K, (K, V?) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun compute(Int, (Int, T?) -> T?): T? defined in kotlin.collections.MutableMap +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.compute(1) { k, v -> null } + // SUCCESS + // ORIGINAL: fun compute(K, (K, V?) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun compute(Int, (Int, T?) -> T?): T? defined in kotlin.collections.MutableMap +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.compute(1) { k, v -> null } + // SUCCESS + // ORIGINAL: fun compute(K, (K, V?) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun compute(Int, (Int, T?) -> T?): T? defined in kotlin.collections.MutableMap +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.kt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.kt new file mode 100644 index 00000000000..c845288d280 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.kt @@ -0,0 +1,19 @@ +fun valuesNotNull(map: MutableMap) { + map.computeIfAbsent(1) { k -> "new value" } +} + +fun valuesNullable(map: MutableMap) { + map.computeIfAbsent(1) { k -> null } +} + +fun valuesT(map: MutableMap, newValue: T) { + map.computeIfAbsent(1) { k -> newValue } +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.computeIfAbsent(1) { k -> newValue } +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.computeIfAbsent(1) { k -> newValue } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.txt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.txt new file mode 100644 index 00000000000..d49287d3bb4 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.txt @@ -0,0 +1,34 @@ +fun valuesNotNull(map: MutableMap) { + map.computeIfAbsent(1) { k -> "new value" } + // SUCCESS + // ORIGINAL: fun computeIfAbsent(K, (K) -> V): V defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfAbsent(Int, (Int) -> String): String defined in kotlin.collections.MutableMap +} + +fun valuesNullable(map: MutableMap) { + map.computeIfAbsent(1) { k -> null } + // SUCCESS + // ORIGINAL: fun computeIfAbsent(K, (K) -> V): V defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfAbsent(Int, (Int) -> String?): String? defined in kotlin.collections.MutableMap +} + +fun valuesT(map: MutableMap, newValue: T) { + map.computeIfAbsent(1) { k -> newValue } + // SUCCESS + // ORIGINAL: fun computeIfAbsent(K, (K) -> V): V defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfAbsent(Int, (Int) -> T): T defined in kotlin.collections.MutableMap +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.computeIfAbsent(1) { k -> newValue } + // SUCCESS + // ORIGINAL: fun computeIfAbsent(K, (K) -> V): V defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfAbsent(Int, (Int) -> T): T defined in kotlin.collections.MutableMap +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.computeIfAbsent(1) { k -> newValue } + // SUCCESS + // ORIGINAL: fun computeIfAbsent(K, (K) -> V): V defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfAbsent(Int, (Int) -> T?): T? defined in kotlin.collections.MutableMap +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.kt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.kt new file mode 100644 index 00000000000..0e624d063d1 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.kt @@ -0,0 +1,19 @@ +fun valuesNotNull(map: MutableMap) { + map.computeIfPresent(1) { k, v -> v.length.toString() ?: null } +} + +fun valuesNullable(map: MutableMap) { + map.computeIfPresent(1) { k, v -> v?.length?.toString() } +} + +fun valuesT(map: MutableMap, newValue: T) { + map.computeIfPresent(1) { k, v -> v?.length.toString() ?: null } +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.computeIfPresent(1) { k, v -> null } +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.computeIfPresent(1) { k, v -> null } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.txt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.txt new file mode 100644 index 00000000000..2a5914be571 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.txt @@ -0,0 +1,34 @@ +fun valuesNotNull(map: MutableMap) { + map.computeIfPresent(1) { k, v -> v.length.toString() ?: null } + // SUCCESS + // ORIGINAL: fun computeIfPresent(K, (K, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfPresent(Int, (Int, String) -> String?): String? defined in kotlin.collections.MutableMap +} + +fun valuesNullable(map: MutableMap) { + map.computeIfPresent(1) { k, v -> v?.length?.toString() } + // SUCCESS + // ORIGINAL: fun computeIfPresent(K, (K, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfPresent(Int, (Int, String) -> String?): String? defined in kotlin.collections.MutableMap +} + +fun valuesT(map: MutableMap, newValue: T) { + map.computeIfPresent(1) { k, v -> v?.length.toString() ?: null } + // SUCCESS + // ORIGINAL: fun computeIfPresent(K, (K, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfPresent(Int, (Int, T) -> T?): T? defined in kotlin.collections.MutableMap +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.computeIfPresent(1) { k, v -> null } + // SUCCESS + // ORIGINAL: fun computeIfPresent(K, (K, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfPresent(Int, (Int, T) -> T?): T? defined in kotlin.collections.MutableMap +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.computeIfPresent(1) { k, v -> null } + // SUCCESS + // ORIGINAL: fun computeIfPresent(K, (K, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun computeIfPresent(Int, (Int, T) -> T?): T? defined in kotlin.collections.MutableMap +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.kt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.kt new file mode 100644 index 00000000000..2719d9480d5 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.kt @@ -0,0 +1,7 @@ +fun valuesNotNull(map: MutableMap) { + map.forEach { k, v -> } +} + +fun valuesT(map: MutableMap, newValue: T) { + map.forEach { k, v -> } +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.txt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.txt new file mode 100644 index 00000000000..0430d504ce9 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.txt @@ -0,0 +1,13 @@ +fun valuesNotNull(map: MutableMap) { + map.forEach { k, v -> } + // SUCCESS + // ORIGINAL: fun forEach((K, V) -> Unit): Unit defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun forEach((Int, String) -> Unit): Unit defined in kotlin.collections.MutableMap +} + +fun valuesT(map: MutableMap, newValue: T) { + map.forEach { k, v -> } + // SUCCESS + // ORIGINAL: fun forEach((K, V) -> Unit): Unit defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun forEach((Int, T) -> Unit): Unit defined in kotlin.collections.MutableMap +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.kt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.kt new file mode 100644 index 00000000000..bf825b52aa0 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.kt @@ -0,0 +1,21 @@ +fun valuesNotNull(map: MutableMap) { + map.merge(1, "x") { old, new -> old + new } +} + +fun valuesNullable(map: MutableMap) { + map.merge(1, "x") { old, new -> old + new } + map.merge(1, null) { old, new -> old + new } +} + +fun valuesT(map: MutableMap, newValue: T) { + map.merge(1, newValue) { old, new -> null } +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.merge(1, newValue) { old, new -> null } +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.merge(1, newValue) { old, new -> new } + map.merge(1, newValue!!) { old, new -> new } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.txt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.txt new file mode 100644 index 00000000000..addf39b8908 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.txt @@ -0,0 +1,42 @@ +fun valuesNotNull(map: MutableMap) { + map.merge(1, "x") { old, new -> old + new } + // SUCCESS + // ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun merge(Int, String, (String, String) -> String?): String? defined in kotlin.collections.MutableMap +} + +fun valuesNullable(map: MutableMap) { + map.merge(1, "x") { old, new -> old + new } + // SUCCESS + // ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun merge(Int, String, (String, String) -> String?): String? defined in kotlin.collections.MutableMap + map.merge(1, null) { old, new -> old + new } + // OTHER_ERROR + // ORIGINAL: fun merge(K, V, BiFunction): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun merge(Int, String, BiFunction): String? defined in kotlin.collections.MutableMap +} + +fun valuesT(map: MutableMap, newValue: T) { + map.merge(1, newValue) { old, new -> null } + // SUCCESS + // ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun merge(Int, T, (T, T) -> T?): T? defined in kotlin.collections.MutableMap +} + +fun valuesTNotNull(map: MutableMap, newValue: T) { + map.merge(1, newValue) { old, new -> null } + // SUCCESS + // ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun merge(Int, T, (T, T) -> T?): T? defined in kotlin.collections.MutableMap +} + +fun valuesTNullable(map: MutableMap, newValue: T?) { + map.merge(1, newValue) { old, new -> new } + // OTHER_ERROR + // ORIGINAL: fun merge(K, V, BiFunction): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun merge(Int, T, BiFunction): T? defined in kotlin.collections.MutableMap + map.merge(1, newValue!!) { old, new -> new } + // SUCCESS + // ORIGINAL: fun merge(K, V, (V, V) -> V?): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun merge(Int, T, (T, T) -> T?): T? defined in kotlin.collections.MutableMap +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.kt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.kt new file mode 100644 index 00000000000..81d127fa92f --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.kt @@ -0,0 +1,7 @@ +fun valuesNotNull(map: MutableMap) { + map.putIfAbsent(1, "") +} + +fun valuesNullable(map: MutableMap) { + map.putIfAbsent(1, null) +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.txt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.txt new file mode 100644 index 00000000000..8b4803b02f3 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.txt @@ -0,0 +1,14 @@ +fun valuesNotNull(map: MutableMap) { + map.putIfAbsent(1, "") + // SUCCESS + // ORIGINAL: fun putIfAbsent(K, V): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun putIfAbsent(Int, String): String? defined in kotlin.collections.MutableMap +} + +fun valuesNullable(map: MutableMap) { + map.putIfAbsent(1, null) + // SUCCESS + // ORIGINAL: fun putIfAbsent(K, V): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun putIfAbsent(Int, String?): String? defined in kotlin.collections.MutableMap +} + diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.kt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.kt new file mode 100644 index 00000000000..afcf6e7f64e --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.kt @@ -0,0 +1,13 @@ +fun valuesNotNull(map: MutableMap) { + map.replace(1, "x") + map.replace(1, "x", "y") + + map.replaceAll { k, v -> "$k to ${v.length}" } +} + +fun valuesNullable(map: MutableMap) { + map.replace(1, null) + map.replace(1, null, "x") + + map.replaceAll { k, v -> "$k to $v" } +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.txt b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.txt new file mode 100644 index 00000000000..0b2614a07e9 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.txt @@ -0,0 +1,32 @@ +fun valuesNotNull(map: MutableMap) { + map.replace(1, "x") + // SUCCESS + // ORIGINAL: fun replace(K, V): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun replace(Int, String): String? defined in kotlin.collections.MutableMap + map.replace(1, "x", "y") + // SUCCESS + // ORIGINAL: fun replace(K, V, V): Boolean defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun replace(Int, String, String): Boolean defined in kotlin.collections.MutableMap + + map.replaceAll { k, v -> "$k to ${v.length}" } + // SUCCESS + // ORIGINAL: fun replaceAll((K, V) -> V): Unit defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun replaceAll((Int, String) -> String): Unit defined in kotlin.collections.MutableMap +} + +fun valuesNullable(map: MutableMap) { + map.replace(1, null) + // SUCCESS + // ORIGINAL: fun replace(K, V): V? defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun replace(Int, String?): String? defined in kotlin.collections.MutableMap + map.replace(1, null, "x") + // SUCCESS + // ORIGINAL: fun replace(K, V, V): Boolean defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun replace(Int, String?, String?): Boolean defined in kotlin.collections.MutableMap + + map.replaceAll { k, v -> "$k to $v" } + // SUCCESS + // ORIGINAL: fun replaceAll((K, V) -> V): Unit defined in kotlin.collections.MutableMap + // SUBSTITUTED: fun replaceAll((Int, String?) -> String?): Unit defined in kotlin.collections.MutableMap +} + diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.kt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.kt new file mode 100644 index 00000000000..6e7fd43137c --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.kt @@ -0,0 +1,6 @@ +import java.util.* + +fun use() { + Optional.empty() + Optional.empty() +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.txt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.txt new file mode 100644 index 00000000000..c5e296cb349 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.txt @@ -0,0 +1,13 @@ +import java.util.* + +fun use() { + Optional.empty() + // SUCCESS + // ORIGINAL: fun empty(): Optional defined in java.util.Optional + // SUBSTITUTED: fun empty(): Optional defined in java.util.Optional + Optional.empty() + // SUCCESS + // ORIGINAL: fun empty(): Optional defined in java.util.Optional + // SUBSTITUTED: fun empty(): Optional defined in java.util.Optional +} + diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.kt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.kt new file mode 100644 index 00000000000..5fbbc877cbb --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.kt @@ -0,0 +1,9 @@ +import java.util.* + +fun use(v: Optional) { + v.get() +} + +fun use2(v: Optional) { + v.get() +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.txt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.txt new file mode 100644 index 00000000000..e65b4465711 --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.txt @@ -0,0 +1,16 @@ +import java.util.* + +fun use(v: Optional) { + v.get() + // SUCCESS + // ORIGINAL: fun get(): T defined in java.util.Optional + // SUBSTITUTED: fun get(): String defined in java.util.Optional +} + +fun use2(v: Optional) { + v.get() + // SUCCESS + // ORIGINAL: fun get(): T defined in java.util.Optional + // SUBSTITUTED: fun get(): String defined in java.util.Optional +} + diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.kt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.kt new file mode 100644 index 00000000000..34557a3677b --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.kt @@ -0,0 +1,9 @@ +import java.util.* + +fun use(v: Optional) { + v.ifPresent { value -> } +} + +fun use2(v: Optional) { + v.ifPresent { value -> } +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.txt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.txt new file mode 100644 index 00000000000..3c2ff5d47bf --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.txt @@ -0,0 +1,16 @@ +import java.util.* + +fun use(v: Optional) { + v.ifPresent { value -> } + // SUCCESS + // ORIGINAL: fun ifPresent((T) -> Unit): Unit defined in java.util.Optional + // SUBSTITUTED: fun ifPresent((String) -> Unit): Unit defined in java.util.Optional +} + +fun use2(v: Optional) { + v.ifPresent { value -> } + // SUCCESS + // ORIGINAL: fun ifPresent((T) -> Unit): Unit defined in java.util.Optional + // SUBSTITUTED: fun ifPresent((String) -> Unit): Unit defined in java.util.Optional +} + diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.kt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.kt new file mode 100644 index 00000000000..950a259d2fd --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.kt @@ -0,0 +1,9 @@ +import java.util.* + +fun use() { + val x: String? = "x" + Optional.of(x) + + Optional.of(x!!) + Optional.ofNullable(x) +} diff --git a/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt new file mode 100644 index 00000000000..a1486a87f9f --- /dev/null +++ b/compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.txt @@ -0,0 +1,19 @@ +import java.util.* + +fun use() { + val x: String? = "x" + Optional.of(x) + // OTHER_ERROR + // ORIGINAL: fun of(T): Optional defined in java.util.Optional + // SUBSTITUTED: fun of(String): Optional defined in java.util.Optional + + Optional.of(x!!) + // SUCCESS + // ORIGINAL: fun of(T): Optional defined in java.util.Optional + // SUBSTITUTED: fun of(String): Optional defined in java.util.Optional + Optional.ofNullable(x) + // SUCCESS + // ORIGINAL: fun ofNullable(T?): Optional defined in java.util.Optional + // SUBSTITUTED: fun ofNullable(String?): Optional defined in java.util.Optional +} + diff --git a/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractEnhancedSignaturesResolvedCallsTest.kt b/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractEnhancedSignaturesResolvedCallsTest.kt new file mode 100644 index 00000000000..2819096d57b --- /dev/null +++ b/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractEnhancedSignaturesResolvedCallsTest.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2010-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. + * 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 org.jetbrains.kotlin.resolve.calls + +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.test.ConfigurationKind +import org.jetbrains.kotlin.test.TestJdkKind + +abstract class AbstractEnhancedSignaturesResolvedCallsTest : AbstractResolvedCallsTest() { + // requires full JDK with various Java API: java.util.Optional, java.util.Map + override fun createEnvironment(): KotlinCoreEnvironment = createEnvironmentWithJdk(ConfigurationKind.ALL, TestJdkKind.FULL_JDK) + + override fun renderOutput(originalText: String, text: String, resolvedCallsAt: List?>>): String { + val lines = text.lines() + val lineOffsets = run { + var offset = 0 + lines.map { offset.apply { offset += it.length + 1 /* new-line delimiter */ } } + } + fun lineIndexAt(caret: Int): Int = + lineOffsets.binarySearch(caret).let { result -> + if (result < 0) result.inv() - 1 else result } + + + val callsByLine = resolvedCallsAt.groupBy ({ (caret) -> lineIndexAt(caret) }, { (_, resolvedCall) -> resolvedCall }) + + return buildString { + lines.forEachIndexed { lineIndex, line -> + appendln(line) + callsByLine[lineIndex]?.let { calls -> + val indent = line.takeWhile(Char::isWhitespace) + " " + calls.forEach { resolvedCall -> + appendln("$indent// ${resolvedCall?.status}") + appendln("$indent// ORIGINAL: ${resolvedCall?.run { resultingDescriptor!!.original.getText() }}") + appendln("$indent// SUBSTITUTED: ${resolvedCall?.run { resultingDescriptor!!.getText() }}") + } + } + } + } + } + +} \ No newline at end of file diff --git a/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedCallsTest.kt b/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedCallsTest.kt index fe842fc8631..03423711250 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedCallsTest.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedCallsTest.kt @@ -48,34 +48,62 @@ abstract class AbstractResolvedCallsTest : KotlinTestWithEnvironment() { override fun createEnvironment(): KotlinCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.ALL) fun doTest(filePath: String) { - val text = KotlinTestUtils.doLoadFile(File(filePath))!! + val originalText = KotlinTestUtils.doLoadFile(File(filePath))!! + val (text, carets) = extractCarets(originalText) - val ktFile = KtPsiFactory(project).createFile(text.replace("", "")) + val ktFile = KtPsiFactory(project).createFile(text) val bindingContext = JvmResolveUtil.analyze(ktFile, environment).bindingContext - val (element, cachedCall) = buildCachedCall(bindingContext, ktFile, text) + val resolvedCallsAt = carets.map { caret -> caret to run { + val (element, cachedCall) = buildCachedCallAtIndex(bindingContext, ktFile, caret) - val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall - else if ("(" == element?.text) cachedCall.functionCall - else cachedCall.variableCall + val resolvedCall = when { + cachedCall !is VariableAsFunctionResolvedCall -> cachedCall + "(" == element?.text -> cachedCall.functionCall + else -> cachedCall.variableCall + } + + resolvedCall + }} + + val output = renderOutput(originalText, text, resolvedCallsAt) val resolvedCallInfoFileName = FileUtil.getNameWithoutExtension(filePath) + ".txt" - KotlinTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), "$text\n\n\n${resolvedCall?.renderToText()}") + KotlinTestUtils.assertEqualsToFile(File(resolvedCallInfoFileName), output) } - open protected fun buildCachedCall( - bindingContext: BindingContext, jetFile: KtFile, text: String + protected open fun renderOutput(originalText: String, text: String, resolvedCallsAt: List?>>): String = + resolvedCallsAt.joinToString("\n\n", prefix = "$originalText\n\n\n") { (_, resolvedCall) -> + resolvedCall?.renderToText().toString() + } + + protected fun extractCarets(text: String): Pair> { + val parts = text.split("") + if (parts.size < 2) return text to emptyList() + // possible to rewrite using 'scan' function to get partial sums of parts lengths + val indices = mutableListOf() + val resultText = buildString { + parts.dropLast(1).forEach { part -> + append(part) + indices.add(this.length) + } + append(parts.last()) + } + return resultText to indices + } + + protected open fun buildCachedCallAtIndex( + bindingContext: BindingContext, jetFile: KtFile, index: Int ): Pair?> { - val element = jetFile.findElementAt(text.indexOf(""))!! + val element = jetFile.findElementAt(index)!! val expression = element.getStrictParentOfType() val cachedCall = expression?.getParentResolvedCall(bindingContext, strict = false) return Pair(element, cachedCall) } - } -private fun Receiver?.getText() = when (this) { +internal fun Receiver?.getText() = when (this) { is ExpressionReceiver -> "${expression.text} {${type}}" is ImplicitClassReceiver -> "Class{${type}}" is ExtensionReceiver -> "${type}Ext{${declarationDescriptor.getText()}}" @@ -83,9 +111,9 @@ private fun Receiver?.getText() = when (this) { else -> toString() } -private fun ValueArgument.getText() = this.getArgumentExpression()?.text?.replace("\n", " ") ?: "" +internal fun ValueArgument.getText() = this.getArgumentExpression()?.text?.replace("\n", " ") ?: "" -private fun ArgumentMapping.getText() = when (this) { +internal fun ArgumentMapping.getText() = when (this) { is ArgumentMatch -> { val parameterType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(valueParameter.type) "${status.name} ${valueParameter.name} : ${parameterType} =" @@ -93,12 +121,12 @@ private fun ArgumentMapping.getText() = when (this) { else -> "ARGUMENT UNMAPPED: " } -private fun DeclarationDescriptor.getText(): String = when (this) { +internal fun DeclarationDescriptor.getText(): String = when (this) { is ReceiverParameterDescriptor -> "${value.getText()}::this" else -> DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.render(this) } -private fun ResolvedCall<*>.renderToText(): String { +internal fun ResolvedCall<*>.renderToText(): String { return buildString { appendln("Resolved call:") appendln() diff --git a/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedConstructorDelegationCallsTests.kt b/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedConstructorDelegationCallsTests.kt index edb34362cba..0448558b0d9 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedConstructorDelegationCallsTests.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/resolve/calls/AbstractResolvedConstructorDelegationCallsTests.kt @@ -27,10 +27,10 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall abstract class AbstractResolvedConstructorDelegationCallsTests : AbstractResolvedCallsTest() { - override fun buildCachedCall( - bindingContext: BindingContext, jetFile: KtFile, text: String + override fun buildCachedCallAtIndex( + bindingContext: BindingContext, jetFile: KtFile, index: Int ): Pair?> { - val element = jetFile.findElementAt(text.indexOf("")) + val element = jetFile.findElementAt(index) val constructor = element?.getNonStrictParentOfType()!! val delegationCall = constructor.getDelegationCall() diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/resolve/calls/EnhancedSignaturesResolvedCallsTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/resolve/calls/EnhancedSignaturesResolvedCallsTestGenerated.java new file mode 100644 index 00000000000..10407a17d2d --- /dev/null +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/resolve/calls/EnhancedSignaturesResolvedCallsTestGenerated.java @@ -0,0 +1,200 @@ +/* + * Copyright 2010-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. + * 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 org.jetbrains.kotlin.resolve.calls; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/resolvedCalls/enhancedSignatures") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class EnhancedSignaturesResolvedCallsTestGenerated extends AbstractEnhancedSignaturesResolvedCallsTest { + public void testAllFilesPresentInEnhancedSignatures() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/enhancedSignatures"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("compiler/testData/resolvedCalls/enhancedSignatures/collection") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Collection extends AbstractEnhancedSignaturesResolvedCallsTest { + public void testAllFilesPresentInCollection() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/enhancedSignatures/collection"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("collectionRemoveIf.kt") + public void testCollectionRemoveIf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionRemoveIf.kt"); + doTest(fileName); + } + + @TestMetadata("collectionSpliterator.kt") + public void testCollectionSpliterator() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionSpliterator.kt"); + doTest(fileName); + } + + @TestMetadata("collectionStream.kt") + public void testCollectionStream() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/collection/collectionStream.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/resolvedCalls/enhancedSignatures/iterable") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Iterable extends AbstractEnhancedSignaturesResolvedCallsTest { + public void testAllFilesPresentInIterable() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/enhancedSignatures/iterable"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("iterableSpliterator.kt") + public void testIterableSpliterator() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/iterable/iterableSpliterator.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/resolvedCalls/enhancedSignatures/iterator") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Iterator extends AbstractEnhancedSignaturesResolvedCallsTest { + public void testAllFilesPresentInIterator() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/enhancedSignatures/iterator"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("iteratorForEachRemaining.kt") + public void testIteratorForEachRemaining() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/iterator/iteratorForEachRemaining.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/resolvedCalls/enhancedSignatures/list") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class List extends AbstractEnhancedSignaturesResolvedCallsTest { + public void testAllFilesPresentInList() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/enhancedSignatures/list"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("listReplaceAll.kt") + public void testListReplaceAll() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/list/listReplaceAll.kt"); + doTest(fileName); + } + + @TestMetadata("listStream.kt") + public void testListStream() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/list/listStream.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Map extends AbstractEnhancedSignaturesResolvedCallsTest { + public void testAllFilesPresentInMap() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/enhancedSignatures/map"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("mapCompute.kt") + public void testMapCompute() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map/mapCompute.kt"); + doTest(fileName); + } + + @TestMetadata("mapComputeIfAbsent.kt") + public void testMapComputeIfAbsent() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfAbsent.kt"); + doTest(fileName); + } + + @TestMetadata("mapComputeIfPresent.kt") + public void testMapComputeIfPresent() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map/mapComputeIfPresent.kt"); + doTest(fileName); + } + + @TestMetadata("mapForEach.kt") + public void testMapForEach() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map/mapForEach.kt"); + doTest(fileName); + } + + @TestMetadata("mapMerge.kt") + public void testMapMerge() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map/mapMerge.kt"); + doTest(fileName); + } + + @TestMetadata("mapPutIfAbsent.kt") + public void testMapPutIfAbsent() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map/mapPutIfAbsent.kt"); + doTest(fileName); + } + + @TestMetadata("mapReplace.kt") + public void testMapReplace() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/map/mapReplace.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/resolvedCalls/enhancedSignatures/optional") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Optional extends AbstractEnhancedSignaturesResolvedCallsTest { + public void testAllFilesPresentInOptional() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/enhancedSignatures/optional"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("optionalEmpty.kt") + public void testOptionalEmpty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalEmpty.kt"); + doTest(fileName); + } + + @TestMetadata("optionalGet.kt") + public void testOptionalGet() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalGet.kt"); + doTest(fileName); + } + + @TestMetadata("optionalIfPresent.kt") + public void testOptionalIfPresent() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalIfPresent.kt"); + doTest(fileName); + } + + @TestMetadata("optionalOf.kt") + public void testOptionalOf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/resolvedCalls/enhancedSignatures/optional/optionalOf.kt"); + doTest(fileName); + } + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/calls/ResolvedCallsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/resolve/calls/ResolvedCallsTestGenerated.java index c1cf65a43a9..57b8084838d 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/calls/ResolvedCallsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/resolve/calls/ResolvedCallsTestGenerated.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; @RunWith(JUnit3RunnerWithInners.class) public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { public void testAllFilesPresentInResolvedCalls() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true, "enhancedSignatures"); } @TestMetadata("explicitReceiverIsDispatchReceiver.kt") diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index e521c754cc7..5b5f9a81f8c 100755 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -151,6 +151,7 @@ import org.jetbrains.kotlin.renderer.AbstractFunctionDescriptorInExpressionRende import org.jetbrains.kotlin.repl.AbstractReplInterpreterTest import org.jetbrains.kotlin.resolve.AbstractResolveTest import org.jetbrains.kotlin.resolve.annotation.AbstractAnnotationParameterTest +import org.jetbrains.kotlin.resolve.calls.AbstractEnhancedSignaturesResolvedCallsTest import org.jetbrains.kotlin.resolve.calls.AbstractResolvedCallsTest import org.jetbrains.kotlin.resolve.calls.AbstractResolvedConstructorDelegationCallsTests import org.jetbrains.kotlin.resolve.constants.evaluate.AbstractCompileTimeConstantEvaluatorTest @@ -208,7 +209,7 @@ fun main(args: Array) { } testClass() { - model("resolvedCalls") + model("resolvedCalls", excludeDirs = listOf("enhancedSignatures")) } testClass() { @@ -421,6 +422,10 @@ fun main(args: Array) { model("loadJava8/sourceJava", extension = "java", testMethod = "doTestSourceJava") } + testClass { + model("resolvedCalls/enhancedSignatures") + } + testClass() { model("loadJava8/compiledJava", extension = "java", excludeDirs = listOf("sam", "kotlinSignature/propagation")) }