Compare commits

...

23 Commits

Author SHA1 Message Date
Nikolay Krasko
5208657f69 Relay plugins with version replacing 2015-11-17 22:17:35 +03:00
Yan Zhulanow
e8be0962c2 Android extensions: get descriptors using reflection (temporary change)
(cherry picked from commit f228c04)
2015-11-17 20:29:53 +03:00
Yan Zhulanow
8afd6421bb Revert "do not package kotlin-runtime and kotlin-reflect into Kotlin Android extensions zip"
This reverts commit 83bf5daf7f.
(cherry picked from commit a1dcede)
2015-11-17 20:29:45 +03:00
Dmitry Jemerov
a946126dca do not package kotlin-runtime and kotlin-reflect into Kotlin Android extensions zip
(cherry picked from commit 83bf5da)
2015-11-17 13:15:24 +01:00
Ilya Gorbunov
47895c0cc2 Correct deprecation replacement for Progression constructors.
Update testdata for LoadBuiltinsTest
2015-11-13 21:57:27 +03:00
Ilya Chernikov
bb6677620a Additional fix to the previous one: Disabling parallel builds without daemon again and undoing apprpriate fix to broken tests problem, since it effectively cancelled fix for parallel building itself and was causing exceptions on heavy builds 2015-11-12 19:14:00 +01:00
Ilya Chernikov
06104521f2 Disabling parallel builds without daemon again and undoing apprpriate fix to broken tests problem, since it effectively cancelled fix for parallel building itself and was causing exceptions on heavy builds 2015-11-12 17:13:26 +01:00
Valentin Kipyatkov
63fc7110a7 KT-9981 Code cleanup replace usages of !in incorrectly
#KT-9981 Fixed
2015-11-12 15:11:07 +03:00
Michael Bogdanov
f5bab93fd1 Additional diagnostic for KT-9980: KotlinFrontEndException: Exception while analyzing expression 2015-11-12 15:11:29 +03:00
Ilya Gorbunov
8f2c05668e Make MutableMap.set return Unit
#KT-7853 Fixed
2015-11-11 19:15:52 +03:00
Ilya Gorbunov
737763cc67 Restore correct sorting order (after cleanup in 17fc1d95) 2015-11-11 19:15:51 +03:00
Ilya Gorbunov
2bd44799f8 Simplify message expression from lambda argument when converting assert to if. 2015-11-11 19:15:50 +03:00
Ilya Gorbunov
e13fb0e7bc Deprecated with ERROR preconditions with eager message. 2015-11-11 19:15:49 +03:00
Ilya Gorbunov
16df7a9d92 Replace getStackTrace usages in j2k and testData. 2015-11-11 19:15:48 +03:00
Ilya Gorbunov
d5d803963f Replace Regex.match and matchAll usages 2015-11-11 19:15:47 +03:00
Ilya Gorbunov
20a15dc175 Refactor intention test files enumerating, do not use deprecated filter method, which would get another behavior after dropping deprecated one. 2015-11-11 19:15:46 +03:00
Ilya Gorbunov
26bd8600cf Drop deprecations and tighten up left ones. 2015-11-11 19:15:45 +03:00
Nikolay Krasko
abb116ef9a Fix locator syntax 2015-11-11 19:06:57 +03:00
Ilya Gorbunov
a336888858 Make emptyMap upperbound to be Any? rather than Any.
#KT-9963
2015-11-11 17:17:42 +03:00
Ilya Gorbunov
19501aac59 Do not override default AbstractList iterator() implementation for primitiveArray.asList wrappers.
#KT-9927 Fixed
2015-11-11 17:17:41 +03:00
Nikolay Krasko
f9ac5ae737 Enable auto-increment in beta2 branch 2015-11-11 17:13:27 +03:00
Dmitry Jemerov
9cb5defc43 don't analyze class repeatedly if we already found an annotated member there
#KT-8557 Fixed
(cherry picked from commit 6f2fb3f)
2015-11-11 15:10:12 +01:00
Valentin Kipyatkov
4782077357 KT-9928 Replacement not offered for a usage of symbol deprecated with DeprecationLevel.ERROR
#KT-9928 Fixed
(cherry picked from commit de11d57)
2015-11-11 17:08:58 +03:00
81 changed files with 481 additions and 241 deletions

1
.idea/ant.xml generated
View File

@@ -18,5 +18,6 @@
<property name="dokka.path" value="../../dokka" />
</properties>
</buildFile>
<buildFile url="file://$PROJECT_DIR$/TeamCityRelay.xml" />
</component>
</project>

99
TeamCityRelay.xml Normal file
View File

@@ -0,0 +1,99 @@
<project name="Change plugins version" default="change-version">
<property name="relay.origin.version" value="1.0.0-beta-2423"/>
<property name="relay.substitute.version" value="1.0.0-beta-2423-IJ-141-3"/>
<property name="relay.plugins.dir" value="artifacts"/>
<property name="relay.unpack.directory" value="relay-dir"/>
<macrodef name="substituteRegexpInFile">
<attribute name="src.file"/>
<attribute name="output.dir"/>
<attribute name="origin.version"/>
<attribute name="substituted.version"/>
<sequential>
<copy todir="@{output.dir}">
<fileset file="@{src.file}"/>
<filterchain>
<replaceregex pattern="@{origin.version}" replace="@{substituted.version}" />
</filterchain>
</copy>
</sequential>
</macrodef>
<macrodef name="substitudeVersionInPlugin">
<attribute name="plugin.path"/>
<attribute name="plugin.jar.name"/>
<attribute name="origin.version"/>
<attribute name="substituted.version"/>
<attribute name="plugin.subdir"/>
<attribute name="output-dir" default="@{substituted.version}"/>
<attribute name="output.plugin.file.name" default="@{plugin.jar.name}-@{substituted.version}.zip"/>
<attribute name="temp.origin.dir" default="${relay.unpack.directory}/@{plugin.jar.name}/plugin-origin"/>
<attribute name="temp.substitute.dir" default="${relay.unpack.directory}/@{plugin.jar.name}/substitute"/>
<sequential>
<delete dir="${relay.unpack.directory}/@{plugin.jar.name}"/>
<mkdir dir="${relay.unpack.directory}/@{plugin.jar.name}"/>
<unzip src="@{plugin.path}" dest="@{temp.origin.dir}">
<patternset>
<include name="**/lib/@{plugin.jar.name}.jar" />
</patternset>
<flattenmapper/>
</unzip>
<unzip src="@{temp.origin.dir}/@{plugin.jar.name}.jar" dest="@{temp.origin.dir}">
<patternset>
<include name="**/META-INF/plugin.xml" />
</patternset>
<flattenmapper/>
</unzip>
<substituteRegexpInFile
src.file="@{temp.origin.dir}/plugin.xml" output.dir="@{temp.substitute.dir}"
origin.version="@{origin.version}" substituted.version="@{substituted.version}"/>
<!-- Copy updated file back into jar -->
<copy file="@{temp.origin.dir}/@{plugin.jar.name}.jar" todir="@{temp.substitute.dir}"/>
<jar destfile="@{temp.substitute.dir}/@{plugin.jar.name}.jar" update="true">
<zipfileset file="@{temp.substitute.dir}/plugin.xml" prefix="META-INF"/>
</jar>
<!-- Pack updated plugin.jar back to zip file -->
<copy file="@{plugin.path}" tofile="@{substituted.version}/@{output.plugin.file.name}"/>
<zip destfile="@{substituted.version}/@{output.plugin.file.name}" update="true">
<zipfileset file="@{temp.substitute.dir}/@{plugin.jar.name}.jar" prefix="@{plugin.subdir}/lib"/>
</zip>
</sequential>
</macrodef>
<target name="change-version" description="Repack plugin with other version">
<delete dir="${relay.unpack.directory}"/>
<delete dir="${relay.substitute.version}"/>
<mkdir dir="${relay.unpack.directory}"/>
<mkdir dir="${relay.substitute.version}"/>
<substitudeVersionInPlugin
plugin.jar.name="kotlin-plugin"
plugin.path="${relay.plugins.dir}/kotlin-plugin-${relay.origin.version}.zip"
origin.version="${relay.origin.version}"
plugin.subdir="Kotlin"
substituted.version="${relay.substitute.version}"/>
<substitudeVersionInPlugin
plugin.jar.name="kotlin-bare-plugin"
plugin.path="${relay.plugins.dir}/kotlin-bare-plugin-${relay.origin.version}.zip"
origin.version="${relay.origin.version}"
plugin.subdir="BareKotlin"
substituted.version="${relay.substitute.version}"/>
<substitudeVersionInPlugin
plugin.jar.name="kotlin-android-extensions"
plugin.path="${relay.plugins.dir}/kotlin-android-extensions-plugin-${relay.origin.version}.zip"
origin.version="${relay.origin.version}"
plugin.subdir="KotlinAndroidExtensions"
substituted.version="${relay.substitute.version}"/>
</target>
</project>

View File

@@ -171,7 +171,7 @@ public object TypeIntrinsics {
*/
private fun getFunctionTypeArity(jetType: KotlinType): Int {
val classFqName = getClassFqName(jetType) ?: return -1
val match = KOTLIN_FUNCTION_INTERFACE_REGEX.match(classFqName) ?: return -1
val match = KOTLIN_FUNCTION_INTERFACE_REGEX.find(classFqName) ?: return -1
return Integer.valueOf(match.groups[1]!!.value)
}

View File

@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
import java.io.EOFException
public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePartProvider {
@@ -47,7 +48,11 @@ public class JvmPackagePartProvider(val env: KotlinCoreEnvironment) : PackagePar
}.filterNotNull().flatMap {
it.children.filter { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }.toList<VirtualFile>()
}.map {
ModuleMapping.create(it.contentsToByteArray())
try {
ModuleMapping.create(it.contentsToByteArray())
} catch (e: EOFException) {
throw RuntimeException("Error on reading package parts for '$packageFqName' package in '$it', roots: $roots", e)
}
}
return mappings.map { it.findPackageParts(packageFqName) }.filterNotNull().flatMap { it.parts }.distinct()

View File

@@ -255,7 +255,7 @@ public class KotlinCoreEnvironment private constructor(
val appEnv = getOrCreateApplicationEnvironmentForProduction(configuration, configFilePaths)
// Disposing of the environment is unsafe in production then parallel builds are enabled, but turning it off universally
// breaks a lot of tests, therefore it is disabled for production and enabled for tests
if (System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY) == null || appEnv.application.isUnitTestMode) {
if (System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY) == null) {
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
Disposer.register(parentDisposable, object : Disposable {

View File

@@ -254,8 +254,8 @@ public object KotlinCompilerClient {
private fun String.extractPortFromRunFilename(digest: String): Int =
makeRunFilenameString(timestamp = "[0-9TZ:\\.\\+-]+", digest = digest, port = "(\\d+)", escapeSequence = "\\").toRegex()
.match(this)
makeRunFilenameString(timestamp = "[0-9TZ:\\.\\+-]+", digest = digest, port = "(\\d+)", escapeSequence = "\\").toRegex()
.find(this)
?.groups?.get(1)
?.value?.toInt()
?: 0

View File

@@ -129,7 +129,7 @@ public abstract class ByteIterator : kotlin.Iterator<kotlin.Byte> {
}
@kotlin.Deprecated(level = DeprecationLevel.WARNING, message = "Use IntProgression instead.", replaceWith = kotlin.ReplaceWith(expression = "IntProgression", imports = {})) public open class ByteProgression : kotlin.Progression<kotlin.Byte> {
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use ByteProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "ByteProgression.fromClosedRange(start, end, increment)", imports = {})) public constructor ByteProgression(/*0*/ start: kotlin.Byte, /*1*/ endInclusive: kotlin.Byte, /*2*/ increment: kotlin.Int)
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use ByteProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "ByteProgression.fromClosedRange(start, endInclusive, increment)", imports = {})) public constructor ByteProgression(/*0*/ start: kotlin.Byte, /*1*/ endInclusive: kotlin.Byte, /*2*/ increment: kotlin.Int)
@kotlin.Deprecated(message = "Use 'last' property instead.") public open override /*1*/ val end: kotlin.Byte
public open override /*1*/ fun <get-end>(): kotlin.Byte
public final val first: kotlin.Byte
@@ -231,7 +231,7 @@ public abstract class CharIterator : kotlin.Iterator<kotlin.Char> {
}
public open class CharProgression : kotlin.Progression<kotlin.Char> {
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use CharProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "CharProgression.fromClosedRange(start, end, increment)", imports = {})) public constructor CharProgression(/*0*/ start: kotlin.Char, /*1*/ endInclusive: kotlin.Char, /*2*/ increment: kotlin.Int)
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use CharProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "CharProgression.fromClosedRange(start, endInclusive, increment)", imports = {})) public constructor CharProgression(/*0*/ start: kotlin.Char, /*1*/ endInclusive: kotlin.Char, /*2*/ increment: kotlin.Int)
@kotlin.Deprecated(message = "Use 'last' property instead.") public open override /*1*/ val end: kotlin.Char
public open override /*1*/ fun <get-end>(): kotlin.Char
public final val first: kotlin.Char
@@ -650,7 +650,7 @@ public abstract class IntIterator : kotlin.Iterator<kotlin.Int> {
}
public open class IntProgression : kotlin.Progression<kotlin.Int> {
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use IntProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "IntProgression.fromClosedRange(start, end, increment)", imports = {})) public constructor IntProgression(/*0*/ start: kotlin.Int, /*1*/ endInclusive: kotlin.Int, /*2*/ increment: kotlin.Int)
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use IntProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "IntProgression.fromClosedRange(start, endInclusive, increment)", imports = {})) public constructor IntProgression(/*0*/ start: kotlin.Int, /*1*/ endInclusive: kotlin.Int, /*2*/ increment: kotlin.Int)
@kotlin.Deprecated(message = "Use 'last' property instead.") public open override /*1*/ val end: kotlin.Int
public open override /*1*/ fun <get-end>(): kotlin.Int
public final val first: kotlin.Int
@@ -840,7 +840,7 @@ public abstract class LongIterator : kotlin.Iterator<kotlin.Long> {
}
public open class LongProgression : kotlin.Progression<kotlin.Long> {
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use LongProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "LongProgression.fromClosedRange(start, end, increment)", imports = {})) public constructor LongProgression(/*0*/ start: kotlin.Long, /*1*/ endInclusive: kotlin.Long, /*2*/ increment: kotlin.Long)
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use LongProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "LongProgression.fromClosedRange(start, endInclusive, increment)", imports = {})) public constructor LongProgression(/*0*/ start: kotlin.Long, /*1*/ endInclusive: kotlin.Long, /*2*/ increment: kotlin.Long)
@kotlin.Deprecated(message = "Use 'last' property instead.") public open override /*1*/ val end: kotlin.Long
public open override /*1*/ fun <get-end>(): kotlin.Long
public final val first: kotlin.Long
@@ -1165,7 +1165,7 @@ public abstract class ShortIterator : kotlin.Iterator<kotlin.Short> {
}
@kotlin.Deprecated(level = DeprecationLevel.WARNING, message = "Use IntProgression instead.", replaceWith = kotlin.ReplaceWith(expression = "IntProgression", imports = {})) public open class ShortProgression : kotlin.Progression<kotlin.Short> {
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use ShortProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "ShortProgression.fromClosedRange(start, end, increment)", imports = {})) public constructor ShortProgression(/*0*/ start: kotlin.Short, /*1*/ endInclusive: kotlin.Short, /*2*/ increment: kotlin.Int)
/*primary*/ @kotlin.Deprecated(message = "This constructor will become private soon. Use ShortProgression.fromClosedRange() instead.", replaceWith = kotlin.ReplaceWith(expression = "ShortProgression.fromClosedRange(start, endInclusive, increment)", imports = {})) public constructor ShortProgression(/*0*/ start: kotlin.Short, /*1*/ endInclusive: kotlin.Short, /*2*/ increment: kotlin.Int)
@kotlin.Deprecated(message = "Use 'last' property instead.") public open override /*1*/ val end: kotlin.Short
public open override /*1*/ fun <get-end>(): kotlin.Short
public final val first: kotlin.Short

View File

@@ -10,35 +10,35 @@ fun box(): String {
val s = J::s
// Check that correct reflection objects are created
assert(i !is KMutableProperty<*>, "Fail i class: ${i.javaClass}")
assert(s is KMutableProperty<*>, "Fail s class: ${s.javaClass}")
assert(i !is KMutableProperty<*>) { "Fail i class: ${i.javaClass}" }
assert(s is KMutableProperty<*>) { "Fail s class: ${s.javaClass}" }
// Check that no Method objects are created for such properties
assert(i.javaGetter == null, "Fail i getter")
assert(s.javaGetter == null, "Fail s getter")
assert(s.javaSetter == null, "Fail s setter")
assert(i.javaGetter == null) { "Fail i getter" }
assert(s.javaGetter == null) { "Fail s getter" }
assert(s.javaSetter == null) { "Fail s setter" }
// Check that correct Field objects are created
val ji = i.javaField!!
val js = s.javaField!!
assert(Modifier.isFinal(ji.getModifiers()), "Fail i final")
assert(!Modifier.isFinal(js.getModifiers()), "Fail s final")
assert(Modifier.isFinal(ji.getModifiers())) { "Fail i final" }
assert(!Modifier.isFinal(js.getModifiers())) { "Fail s final" }
// Check that those Field objects work as expected
val a = J(42, "abc")
assert(ji.get(a) == 42, "Fail ji get")
assert(js.get(a) == "abc", "Fail js get")
assert(ji.get(a) == 42) { "Fail ji get" }
assert(js.get(a) == "abc") { "Fail js get" }
js.set(a, "def")
assert(js.get(a) == "def", "Fail js set")
assert(a.s == "def", "Fail js access")
assert(js.get(a) == "def") { "Fail js set" }
assert(a.s == "def") { "Fail js access" }
// Check that valid Kotlin reflection objects are created by those Field objects
val ki = ji.kotlin as KProperty1<J, Int>
val ks = js.kotlin as KMutableProperty1<J, String>
assert(ki.get(a) == 42, "Fail ki get")
assert(ks.get(a) == "def", "Fail ks get")
assert(ki.get(a) == 42) { "Fail ki get" }
assert(ks.get(a) == "def") { "Fail ks get" }
ks.set(a, "ghi")
assert(ks.get(a) == "ghi", "Fail ks set")
assert(ks.get(a) == "ghi") { "Fail ks set" }
return "OK"
}

View File

@@ -21,7 +21,7 @@ fun testProperLineNumber(): String {
fail()
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("chainCalls.kt:21" != actual) {
return "fail 2: ${actual}"
@@ -34,7 +34,7 @@ fun testProperLineNumber(): String {
fail()
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("chainCalls.kt:34" != actual) {
return "fail 3: ${actual}"
@@ -46,7 +46,7 @@ fun testProperLineNumber(): String {
test().fail()
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("chainCalls.kt:46" != actual) {
return "fail 4: ${actual}"

View File

@@ -18,7 +18,7 @@ fun testProperLineNumber(): String {
test()
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("infixCalls.kt:17" != actual) {
return "fail 1: ${actual}"
@@ -30,7 +30,7 @@ fun testProperLineNumber(): String {
call() fail test()
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("infixCalls.kt:30" != actual) {
return "fail 1: ${actual}"

View File

@@ -18,7 +18,7 @@ fun testProperLineNumberAfterInline(): String {
test())
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("simpleCallWithParams.kt:17" != actual) {
return "fail 2: ${actual}"
@@ -36,7 +36,7 @@ fun testProperLineForOtherParameters(): String {
fail())
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("simpleCallWithParams.kt:35" != actual) {
return "fail 3: ${actual}"
@@ -50,7 +50,7 @@ fun testProperLineForOtherParameters(): String {
test())
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("simpleCallWithParams.kt:49" != actual) {
return "fail 4: ${actual}"
@@ -62,7 +62,7 @@ fun testProperLineForOtherParameters(): String {
checkEquals(fail(), test())
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("simpleCallWithParams.kt:62" != actual) {
return "fail 5: ${actual}"
@@ -74,7 +74,7 @@ fun testProperLineForOtherParameters(): String {
checkEquals(fail(), test())
}
catch(e: AssertionError) {
val entry = e.getStackTrace()!![1]
val entry = e.stackTrace!![1]
val actual = "${entry.getFileName()}:${entry.getLineNumber()}"
if ("simpleCallWithParams.kt:74" != actual) {
return "fail 6: ${actual}"

View File

@@ -11,14 +11,14 @@ class Secondary {
}
fun check(f: KFunction<Any>) {
assert(f.javaMethod == null, "Fail f method")
assert(f.javaConstructor != null, "Fail f constructor")
assert(f.javaMethod == null) { "Fail f method" }
assert(f.javaConstructor != null) { "Fail f constructor" }
val c = f.javaConstructor!!
assert(c.kotlinFunction != null, "Fail m function")
assert(c.kotlinFunction != null) { "Fail m function" }
val ff = c.kotlinFunction!!
assert(f == ff, "Fail f != ff")
assert(f == ff) { "Fail f != ff" }
}
fun box(): String {

View File

@@ -19,9 +19,9 @@ fun box(): String {
assertEquals(setter, Class.forName("ExtensionPropertyKt").getMethod("setExt", javaClass<K>(), javaClass<Double>()))
val k = K(42L)
assert(getter.invoke(null, k) == 42.0, "Fail k getter")
assert(getter.invoke(null, k) == 42.0) { "Fail k getter" }
setter.invoke(null, k, -239.0)
assert(getter.invoke(null, k) == -239.0, "Fail k setter")
assert(getter.invoke(null, k) == -239.0) { "Fail k setter" }
return "OK"
}

View File

@@ -8,14 +8,14 @@ fun bar(s: String): Int = s.length()
fun String.baz(): Int = this.length()
fun check(f: KFunction<Int>) {
assert(f.javaConstructor == null, "Fail f constructor")
assert(f.javaMethod != null, "Fail f method")
assert(f.javaConstructor == null) { "Fail f constructor" }
assert(f.javaMethod != null) { "Fail f method" }
val m = f.javaMethod!!
assert(m.kotlinFunction != null, "Fail m function")
assert(m.kotlinFunction != null) { "Fail m function" }
val ff = m.kotlinFunction!!
assert(f == ff, "Fail f != ff")
assert(f == ff) { "Fail f != ff" }
}
fun box(): String {

View File

@@ -6,7 +6,7 @@ class K(var value: Long)
fun box(): String {
val p = K::value
assert(p.javaField != null, "Fail p field")
assert(p.javaField != null) { "Fail p field" }
val getter = p.javaGetter!!
val setter = p.javaSetter!!
@@ -15,9 +15,9 @@ fun box(): String {
assertEquals(setter, javaClass<K>().getMethod("setValue", javaClass<Long>()))
val k = K(42L)
assert(getter.invoke(k) == 42L, "Fail k getter")
assert(getter.invoke(k) == 42L) { "Fail k getter" }
setter.invoke(k, -239L)
assert(getter.invoke(k) == -239L, "Fail k setter")
assert(getter.invoke(k) == -239L) { "Fail k setter" }
return "OK"
}

View File

@@ -6,7 +6,7 @@ var topLevel = "123"
fun box(): String {
val p = ::topLevel
assert(p.javaField != null, "Fail p field")
assert(p.javaField != null) { "Fail p field" }
val field = p.javaField!!
val className = field.getDeclaringClass().getName()
assertEquals("TopLevelPropertyKt", className)
@@ -17,9 +17,9 @@ fun box(): String {
assertEquals(getter, Class.forName("TopLevelPropertyKt").getMethod("getTopLevel"))
assertEquals(setter, Class.forName("TopLevelPropertyKt").getMethod("setTopLevel", javaClass<String>()))
assert(getter.invoke(null) == "123", "Fail k getter")
assert(getter.invoke(null) == "123") { "Fail k getter" }
setter.invoke(null, "456")
assert(getter.invoke(null) == "456", "Fail k setter")
assert(getter.invoke(null) == "456") { "Fail k setter" }
return "OK"
}

View File

@@ -8,5 +8,5 @@ fun main(args: Array<String>) {
val annotationClass = javaClass<AnnotationClass>()
val annotation = klass.getAnnotation(annotationClass)!!
val value = annotation.value
require(value == "100 20000 2000000 2000000000000 3.14 3.14 true \u03c0 :)", "Annotation value: $value")
require(value == "100 20000 2000000 2000000000000 3.14 3.14 true \u03c0 :)", { "Annotation value: $value" })
}

View File

@@ -42,7 +42,7 @@ internal fun Sequence<String>.ifNotContainsSequence(patternsIter: Iterator<LineP
{ acc, line ->
when {
!acc.iter.isValid() -> return@fold acc
acc.iter.value.regex.match(line)?.let { acc.iter.value.matchCheck(it) } ?: false -> acc.nextLineAndPattern()
acc.iter.value.regex.find(line)?.let { acc.iter.value.matchCheck(it) } ?: false -> acc.nextLineAndPattern()
else -> acc.nextLine()
}
}

View File

@@ -23,7 +23,7 @@ package kotlin
* A progression of values of type `Byte`.
*/
public open class ByteProgression
@Deprecated("This constructor will become private soon. Use ByteProgression.fromClosedRange() instead.", ReplaceWith("ByteProgression.fromClosedRange(start, end, increment)"))
@Deprecated("This constructor will become private soon. Use ByteProgression.fromClosedRange() instead.", ReplaceWith("ByteProgression.fromClosedRange(start, endInclusive, increment)"))
public constructor
(
start: Byte,
@@ -81,7 +81,7 @@ public open class ByteProgression
* A progression of values of type `Char`.
*/
public open class CharProgression
@Deprecated("This constructor will become private soon. Use CharProgression.fromClosedRange() instead.", ReplaceWith("CharProgression.fromClosedRange(start, end, increment)"))
@Deprecated("This constructor will become private soon. Use CharProgression.fromClosedRange() instead.", ReplaceWith("CharProgression.fromClosedRange(start, endInclusive, increment)"))
public constructor
(
start: Char,
@@ -140,7 +140,7 @@ public open class CharProgression
* A progression of values of type `Short`.
*/
public open class ShortProgression
@Deprecated("This constructor will become private soon. Use ShortProgression.fromClosedRange() instead.", ReplaceWith("ShortProgression.fromClosedRange(start, end, increment)"))
@Deprecated("This constructor will become private soon. Use ShortProgression.fromClosedRange() instead.", ReplaceWith("ShortProgression.fromClosedRange(start, endInclusive, increment)"))
public constructor
(
start: Short,
@@ -198,7 +198,7 @@ public open class ShortProgression
* A progression of values of type `Int`.
*/
public open class IntProgression
@Deprecated("This constructor will become private soon. Use IntProgression.fromClosedRange() instead.", ReplaceWith("IntProgression.fromClosedRange(start, end, increment)"))
@Deprecated("This constructor will become private soon. Use IntProgression.fromClosedRange() instead.", ReplaceWith("IntProgression.fromClosedRange(start, endInclusive, increment)"))
public constructor
(
start: Int,
@@ -256,7 +256,7 @@ public open class IntProgression
* A progression of values of type `Long`.
*/
public open class LongProgression
@Deprecated("This constructor will become private soon. Use LongProgression.fromClosedRange() instead.", ReplaceWith("LongProgression.fromClosedRange(start, end, increment)"))
@Deprecated("This constructor will become private soon. Use LongProgression.fromClosedRange() instead.", ReplaceWith("LongProgression.fromClosedRange(start, endInclusive, increment)"))
public constructor
(
start: Long,

View File

@@ -56,7 +56,7 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) {
* A progression of values of type `$t`.
*/
public open class $progression
@Deprecated("This constructor will become private soon. Use $progression.fromClosedRange() instead.", ReplaceWith("$progression.fromClosedRange(start, end, increment)"))
@Deprecated("This constructor will become private soon. Use $progression.fromClosedRange() instead.", ReplaceWith("$progression.fromClosedRange(start, endInclusive, increment)"))
public constructor
(
start: $t,

View File

@@ -89,6 +89,7 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
Errors.USELESS_ELVIS,
ErrorsJvm.POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION,
Errors.DEPRECATION,
Errors.DEPRECATION_ERROR,
Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION,
Errors.OPERATOR_MODIFIER_REQUIRED,
Errors.DEPRECATED_UNARY_PLUS_MINUS,

View File

@@ -23,8 +23,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.util.ShortenReferences
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.utils.addToStdlib.check
public class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCallExpression>(javaClass(), "Replace 'assert' with 'if' statement"), LowPriorityAction {
override fun isApplicableTo(element: KtCallExpression, caretOffset: Int): Boolean {
@@ -44,17 +48,21 @@ public class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCall
override fun applyTo(element: KtCallExpression, editor: Editor) {
val args = element.getValueArguments()
val conditionText = args[0]?.getArgumentExpression()?.getText() ?: return
val functionLiteral = element.getFunctionLiteralArguments().singleOrNull()
val messageIsFunction = messageIsFunction(element)
val functionLiteralArgument = element.functionLiteralArguments.singleOrNull()
val bindingContext = element.analyze(BodyResolveMode.PARTIAL)
val psiFactory = KtPsiFactory(element)
val messageExpr = when {
args.size() == 2 -> args[1]?.getArgumentExpression() ?: return
functionLiteral != null -> functionLiteral!!
else -> psiFactory.createExpression("\"Assertion failed\"")
val messageFunctionExpr = when {
args.size == 2 -> args[1]?.getArgumentExpression() ?: return
functionLiteralArgument != null -> functionLiteralArgument.getFunctionLiteral()
else -> null
}
val extractedMessageSingleExpr = (messageFunctionExpr as? KtFunctionLiteralExpression)?.let { extractMessageSingleExpression(it, bindingContext) }
val messageIsFunction = extractedMessageSingleExpr == null && messageIsFunction(element, bindingContext)
val messageExpr = extractedMessageSingleExpr ?: messageFunctionExpr ?: psiFactory.createExpression("\"Assertion failed\"")
val ifExpression = replaceWithIfThenThrowExpression(element)
// shorten java.lang.AssertionError
@@ -85,8 +93,14 @@ public class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCall
simplifyConditionIfPossible(ifExpression)
}
private fun messageIsFunction(callExpr: KtCallExpression): Boolean {
val resolvedCall = callExpr.getResolvedCall(callExpr.analyze()) ?: return false
private fun extractMessageSingleExpression(functionLiteral: KtFunctionLiteralExpression, bindingContext: BindingContext): KtExpression? {
return functionLiteral.bodyExpression?.statements?.singleOrNull()?.let { singleStatement ->
singleStatement.check { it.isUsedAsExpression(bindingContext) }
}
}
private fun messageIsFunction(callExpr: KtCallExpression, bindingContext: BindingContext): Boolean {
val resolvedCall = callExpr.getResolvedCall(bindingContext) ?: return false
val valParameters = resolvedCall.getResultingDescriptor().getValueParameters()
return valParameters.size() > 1 && !KotlinBuiltIns.isAny(valParameters[1].type)
}

View File

@@ -315,6 +315,7 @@ public class QuickFixRegistrar : QuickFixContributor {
ReplaceObsoleteLabelSyntaxFix.createWholeProjectFixFactory())
DEPRECATION.registerFactory(DeprecatedSymbolUsageFix, DeprecatedSymbolUsageInWholeProjectFix)
DEPRECATION_ERROR.registerFactory(DeprecatedSymbolUsageFix, DeprecatedSymbolUsageInWholeProjectFix)
POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION.registerFactory(ReplaceJavaAnnotationPositionedArgumentsFix)

View File

@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
import org.jetbrains.kotlin.idea.core.*
import org.jetbrains.kotlin.idea.intentions.OperatorToFunctionIntention
import org.jetbrains.kotlin.idea.intentions.RemoveExplicitTypeArgumentsIntention
import org.jetbrains.kotlin.idea.intentions.setType
import org.jetbrains.kotlin.idea.util.*
@@ -65,8 +66,14 @@ class CallableUsageReplacementStrategy(
if (!callTypeHandler.precheckReplacementPattern(replacement)) return null
return {
// copy replacement expression because it is modified by performCallReplacement
performCallReplacement(usage, bindingContext, resolvedCall, callElement, callTypeHandler, replacement.copy())
if (usage is KtOperationReferenceExpression && usage.getReferencedNameElementType() != KtTokens.IDENTIFIER) {
val nameExpression = OperatorToFunctionIntention.convert(usage.parent as KtExpression).second
createReplacer(nameExpression)!!.invoke()
}
else {
// copy replacement expression because it is modified by performCallReplacement
performCallReplacement(usage, bindingContext, resolvedCall, callElement, callTypeHandler, replacement.copy())
}
}
}

View File

@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.core.OptionalParametersHelper
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
@@ -100,7 +101,7 @@ public abstract class DeprecatedSymbolUsageFixBase(
else
null) ?: return null
val descriptor = Errors.DEPRECATION.cast(deprecatedDiagnostic).a
val descriptor = DiagnosticFactory.cast(deprecatedDiagnostic, Errors.DEPRECATION, Errors.DEPRECATION_ERROR).a
val replacement = DeprecatedSymbolUsageFixBase.fetchReplaceWithPattern(descriptor, nameExpression.project) ?: return null
return Data(nameExpression, replacement, descriptor)
}

View File

@@ -60,22 +60,27 @@ public class KotlinAnnotatedElementsSearcher : QueryExecutor<PsiModifierListOwne
companion object {
private val LOG = Logger.getInstance("#com.intellij.psi.impl.search.AnnotatedMembersSearcher")
public fun processAnnotatedMembers(annClass: PsiClass, useScope: SearchScope, consumer: (KtDeclaration) -> Boolean): Boolean {
public fun processAnnotatedMembers(annClass: PsiClass,
useScope: SearchScope,
preFilter: (KtAnnotationEntry) -> Boolean = { true },
consumer: (KtDeclaration) -> Boolean): Boolean {
assert(annClass.isAnnotationType()) { "Annotation type should be passed to annotated members search" }
val annotationFQN = annClass.getQualifiedName()
assert(annotationFQN != null)
for (elt in getKotlinAnnotationCandidates(annClass, useScope)) {
val candidates = getKotlinAnnotationCandidates(annClass, useScope)
for (elt in candidates) {
if (notKtAnnotationEntry(elt)) continue
val result = runReadAction(fun(): Boolean {
if (elt !is KtAnnotationEntry) return true
if (!preFilter(elt)) return true
val declaration = elt.getStrictParentOfType<KtDeclaration>() ?: return true
val annotationEntry = elt as KtAnnotationEntry
val context = annotationEntry.analyze(BodyResolveMode.PARTIAL)
val annotationDescriptor = context.get(BindingContext.ANNOTATION, annotationEntry) ?: return true
val context = elt.analyze(BodyResolveMode.PARTIAL)
val annotationDescriptor = context.get(BindingContext.ANNOTATION, elt) ?: return true
val descriptor = annotationDescriptor.getType().getConstructor().getDeclarationDescriptor() ?: return true
if (!(DescriptorUtils.getFqName(descriptor).asString() == annotationFQN)) return true

View File

@@ -34,10 +34,12 @@ class KotlinClassesWithAnnotatedMembersSearcher : ScopedQueryExecutor<PsiClass,
override fun execute(queryParameters: ClassesWithAnnotatedMembersSearch.Parameters, consumer: Processor<PsiClass>): Boolean {
val processed = hashSetOf<KtClassOrObject>()
return KotlinAnnotatedElementsSearcher.processAnnotatedMembers(queryParameters.annotationClass, queryParameters.scope) { declaration ->
val jetClass = declaration.getNonStrictParentOfType<KtClassOrObject>()
if (jetClass != null && processed.add(jetClass)) {
val lightClass = LightClassUtil.getPsiClass(jetClass)
return KotlinAnnotatedElementsSearcher.processAnnotatedMembers(queryParameters.annotationClass,
queryParameters.scope,
{ it.getNonStrictParentOfType<KtClassOrObject>() !in processed}) { declaration ->
val ktClass = declaration.getNonStrictParentOfType<KtClassOrObject>()
if (ktClass != null && processed.add(ktClass)) {
val lightClass = LightClassUtil.getPsiClass(ktClass)
if (lightClass != null) consumer.process(lightClass) else true
}
else

View File

@@ -1,7 +1,7 @@
package a
fun foo() {
<caret>assert(true, "text")
<caret>assert(true, { "text" })
}
class AssertionError

View File

@@ -1,4 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true && false, "text")
<caret>assert(true && false, { "text" })
}

View File

@@ -1,4 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(1 > 0, "text")
<caret>assert(1 > 0) { "text" }
}

View File

@@ -1,4 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(0 != 1, "text")
<caret>assert(0 != 1) { "text" }
}

View File

@@ -2,5 +2,5 @@
fun foo() {
val x = true
val y = false
<caret>assert(x || y, "text")
<caret>assert(x || y) { "text" }
}

View File

@@ -1,5 +1,5 @@
fun main(args: Array<String>) {
asse<caret>rt(false, "mess" as kotlin.String)
asse<caret>rt(false) { "mess" as kotlin.String }
}
// WITH_RUNTIME

View File

@@ -1,4 +1,4 @@
// WITH_RUNTIME
fun foo() {
kotlin.<caret>assert(true, "text")
kotlin.<caret>assert(true) {"text"}
}

View File

@@ -1,6 +1,6 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(bar(), "text")
<caret>assert(bar()) { "text" }
}
fun bar(): Boolean = true

View File

@@ -1,4 +1,6 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true, { "text" })
<caret>assert(true, {
if (true) "text" else return
})
}

View File

@@ -1,6 +1,6 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError({ "text" }())
throw AssertionError(if (true) "text" else return)
}
}

View File

@@ -1,4 +1,6 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true) { "text" }
<caret>assert(true) {
return
}
}

View File

@@ -1,6 +1,8 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError({ "text" }())
throw AssertionError({
return
}())
}
}

View File

@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true, {
val value = 1
"text and $value"
})
}

View File

@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError({
val value = 1
"text and $value"
}())
}
}

View File

@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true) {
if (false) return
"text"
}
}

View File

@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun foo() {
if (!true) {
throw AssertionError({
if (false) return
"text"
}())
}
}

View File

@@ -1,4 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert((true && false), "text")
<caret>assert((true && false)) { "text" }
}

View File

@@ -1,4 +1,4 @@
// WITH_RUNTIME
fun foo() {
<caret>assert(true, "text")
<caret>assert(true) { "text" }
}

View File

@@ -1,5 +1,5 @@
// WITH_RUNTIME
fun foo() {
val f = "text"
<caret>assert(true, f)
<caret>assert(true) { f }
}

View File

@@ -0,0 +1,9 @@
// "Replace with 'b()'" "true"
@Deprecated("b!", ReplaceWith("b()"), DeprecationLevel.ERROR)
fun a() {}
fun b() {}
fun usage() {
<caret>a()
}

View File

@@ -0,0 +1,9 @@
// "Replace with 'b()'" "true"
@Deprecated("b!", ReplaceWith("b()"), DeprecationLevel.ERROR)
fun a() {}
fun b() {}
fun usage() {
<caret>b()
}

View File

@@ -0,0 +1,20 @@
// "Replace usages of 'contains(String) on C: Boolean' in whole project" "true"
class C
@Deprecated("", ReplaceWith("checkContains(s)"))
operator fun C.contains(s: String) = true
fun C.checkContains(s: String) = true
fun f(c: C) {
if ("" <caret>!in c) {
}
}
fun g(c: C) {
if ("" in c) {
}
}

View File

@@ -0,0 +1,20 @@
// "Replace usages of 'contains(String) on C: Boolean' in whole project" "true"
class C
@Deprecated("", ReplaceWith("checkContains(s)"))
operator fun C.contains(s: String) = true
fun C.checkContains(s: String) = true
fun f(c: C) {
if (!c.checkContains("")) {
}
}
fun g(c: C) {
if (c.checkContains("")) {
}
}

View File

@@ -0,0 +1,12 @@
// "Replace with 'add(c)'" "true"
class C
@Deprecated("", ReplaceWith("add(c)"))
operator fun C.plus(c: C) = C()
fun C.add(c: C) = C()
fun f() {
var c1 = C()
c1 <caret>+= C()
}

View File

@@ -0,0 +1,12 @@
// "Replace with 'add(c)'" "true"
class C
@Deprecated("", ReplaceWith("add(c)"))
operator fun C.plus(c: C) = C()
fun C.add(c: C) = C()
fun f() {
var c1 = C()
c1 = c1.add(C())
}

View File

@@ -71,13 +71,13 @@ public abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTest
setTestDataPath("${KotlinTestUtils.getHomeDirectory()}/$srcDir")
val afterFiles = srcDir.listFiles { it.name == "inspectionData" }?.single()?.listFiles { it.extension == "after" } ?: emptyArray()
val psiFiles = srcDir.walkTopDown().filter { it.name != "inspectionData" }.map {
val psiFiles = srcDir.walkTopDown().treeFilter { it.name != "inspectionData" }.map {
file ->
if (file.isDirectory) {
null
}
else if (file.extension != "kt") {
val filePath = file.getPath().substringAfter(srcDir.getPath()).replace("\\", "/")
val filePath = file.relativeTo(srcDir).replace('\\', '/')
configureByFile(filePath)
}
else {
@@ -86,10 +86,10 @@ public abstract class AbstractInspectionTest : KotlinLightCodeInsightFixtureTest
if (text.startsWith("package"))
text
else
"package ${file.getName().removeSuffix(".kt")};$text"
configureByText(file.getName(), fileText)!!
"package ${file.nameWithoutExtension};$text"
configureByText(file.name, fileText)!!
}
}.filterNotNull().toArrayList()
}.filterNotNull().toList()
val isJs = srcDir.endsWith("js")

View File

@@ -3088,6 +3088,18 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("lambdaMultiStatementMessageInsideParentheses.kt")
public void testLambdaMultiStatementMessageInsideParentheses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertAssertToIf/lambdaMultiStatementMessageInsideParentheses.kt");
doTest(fileName);
}
@TestMetadata("lambdaMultiStatementMessageOutsideParentheses.kt")
public void testLambdaMultiStatementMessageOutsideParentheses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertAssertToIf/lambdaMultiStatementMessageOutsideParentheses.kt");
doTest(fileName);
}
@TestMetadata("lambdaVariable.kt")
public void testLambdaVariable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertAssertToIf/lambdaVariable.kt");

View File

@@ -3163,6 +3163,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("deprecationLevel.kt")
public void testDeprecationLevel() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/deprecationLevel.kt");
doTest(fileName);
}
@TestMetadata("doNotShortenUserReferences.kt")
public void testDoNotShortenUserReferences() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/doNotShortenUserReferences.kt");
@@ -3724,6 +3730,27 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class OperatorCalls extends AbstractQuickFixTest {
public void testAllFilesPresentInOperatorCalls() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("in.kt")
public void testIn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/in.kt");
doTest(fileName);
}
@TestMetadata("plusAssign.kt")
public void testPlusAssign() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/operatorCalls/plusAssign.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/optionalParameters")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)

View File

@@ -83,7 +83,7 @@ abstract class Element {
public var createdAt: String?
= if (saveCreationStacktraces)
Exception().getStackTrace().joinToString("\n")
Exception().stackTrace.joinToString("\n")
else
null

View File

@@ -70,7 +70,7 @@ public class CompilerRunnerUtil {
}
@Nullable
public static Object invokeExecMethod(
public synchronized static Object invokeExecMethod(
@NotNull String compilerClassName,
@NotNull String[] arguments,
@NotNull CompilerEnvironment environment,

View File

@@ -112,8 +112,9 @@ public object KotlinCompilerRunner {
val stream = ByteArrayOutputStream()
val out = PrintStream(stream)
if (System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY) == null)
System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "")
// Uncomment after resolving problems with parallel compilation and tests
// if (System.getProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY) == null)
// System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "")
val rc = CompilerRunnerUtil.invokeExecMethod(compilerClassName, argsArray, environment, messageCollector, out)

View File

@@ -53,7 +53,7 @@ fun getDirectoryString(dir: File, interestingPaths: List<String>): String {
val listFiles = dir.listFiles()
assertNotNull(listFiles)
val children = listFiles!!.sortedWith(compareBy ({ it.directory }, { it.name } ))
val children = listFiles!!.sortedWith(compareBy ({ it.isDirectory }, { it.name } ))
for (child in children) {
if (child.isDirectory()) {
p.println(child.name)

View File

@@ -110,7 +110,7 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
* replacement for that match.
*/
public inline fun replace(input: CharSequence, transform: (MatchResult) -> CharSequence): String {
var match = match(input)
var match = find(input)
if (match == null) return input.toString()
var lastStart = 0
@@ -148,7 +148,7 @@ public class Regex(pattern: String, options: Set<RegexOption>) {
*/
public fun split(input: CharSequence, limit: Int = 0): List<String> {
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
val matches = matchAll(input).let { if (limit == 0) it else it.take(limit - 1) }
val matches = findAll(input).let { if (limit == 0) it else it.take(limit - 1) }
val result = ArrayList<String>()
var lastStart = 0

View File

@@ -10600,7 +10600,6 @@ public fun BooleanArray.asList(): List<Boolean> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Boolean): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Boolean> = this@asList.iterator() as MutableIterator<Boolean>
override fun get(index: Int): Boolean = this@asList[index]
override fun indexOf(o: Boolean): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Boolean): Int = this@asList.lastIndexOf(o)
@@ -10616,7 +10615,6 @@ public fun ByteArray.asList(): List<Byte> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Byte): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Byte> = this@asList.iterator() as MutableIterator<Byte>
override fun get(index: Int): Byte = this@asList[index]
override fun indexOf(o: Byte): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Byte): Int = this@asList.lastIndexOf(o)
@@ -10632,7 +10630,6 @@ public fun CharArray.asList(): List<Char> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Char): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Char> = this@asList.iterator() as MutableIterator<Char>
override fun get(index: Int): Char = this@asList[index]
override fun indexOf(o: Char): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Char): Int = this@asList.lastIndexOf(o)
@@ -10648,7 +10645,6 @@ public fun DoubleArray.asList(): List<Double> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Double): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Double> = this@asList.iterator() as MutableIterator<Double>
override fun get(index: Int): Double = this@asList[index]
override fun indexOf(o: Double): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Double): Int = this@asList.lastIndexOf(o)
@@ -10664,7 +10660,6 @@ public fun FloatArray.asList(): List<Float> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Float): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Float> = this@asList.iterator() as MutableIterator<Float>
override fun get(index: Int): Float = this@asList[index]
override fun indexOf(o: Float): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Float): Int = this@asList.lastIndexOf(o)
@@ -10680,7 +10675,6 @@ public fun IntArray.asList(): List<Int> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Int): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Int> = this@asList.iterator() as MutableIterator<Int>
override fun get(index: Int): Int = this@asList[index]
override fun indexOf(o: Int): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Int): Int = this@asList.lastIndexOf(o)
@@ -10696,7 +10690,6 @@ public fun LongArray.asList(): List<Long> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Long): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Long> = this@asList.iterator() as MutableIterator<Long>
override fun get(index: Int): Long = this@asList[index]
override fun indexOf(o: Long): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Long): Int = this@asList.lastIndexOf(o)
@@ -10712,7 +10705,6 @@ public fun ShortArray.asList(): List<Short> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: Short): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<Short> = this@asList.iterator() as MutableIterator<Short>
override fun get(index: Int): Short = this@asList[index]
override fun indexOf(o: Short): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: Short): Int = this@asList.lastIndexOf(o)

View File

@@ -6,7 +6,7 @@ package kotlin
import java.io.Serializable
import java.util.*
private object EmptyMap : Map<Any, Nothing>, Serializable {
private object EmptyMap : Map<Any?, Nothing>, Serializable {
override fun equals(other: Any?): Boolean = other is Map<*,*> && other.isEmpty()
override fun hashCode(): Int = 0
override fun toString(): String = "{}"
@@ -14,11 +14,11 @@ private object EmptyMap : Map<Any, Nothing>, Serializable {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun containsKey(key: Any): Boolean = false
override fun containsKey(key: Any?): Boolean = false
override fun containsValue(value: Nothing): Boolean = false
override fun get(key: Any): Nothing? = null
override val entries: Set<Map.Entry<Any, Nothing>> get() = EmptySet
override val keys: Set<Any> get() = EmptySet
override fun get(key: Any?): Nothing? = null
override val entries: Set<Map.Entry<Any?, Nothing>> get() = EmptySet
override val keys: Set<Any?> get() = EmptySet
override val values: Collection<Nothing> get() = EmptyList
private fun readResolve(): Any = EmptyMap

View File

@@ -14,13 +14,19 @@ import java.util.concurrent.ConcurrentMap
* Allows to use the index operator for storing values in a mutable map.
*/
// this code is JVM-specific, because JS has native set function
public operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): V? = put(key, value)
public operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit {
put(key, value)
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("set")
public fun <K, V> MutableMap<K, V>.set(key: K, value: V): V? = put(key, value)
/**
* getOrPut is not supported on [ConcurrentMap] since it cannot be implemented correctly in terms of concurrency.
* Use [concurrentGetOrPut] instead, or cast this to a [MutableMap] if you want to sacrifice the concurrent-safety.
*/
@Deprecated("Use concurrentGetOrPut instead or cast this map to MutableMap.")
@Deprecated("Use concurrentGetOrPut instead or cast this map to MutableMap.", level = DeprecationLevel.ERROR)
public inline fun <K, V> ConcurrentMap<K, V>.getOrPut(key: K, defaultValue: () -> V): Nothing =
throw UnsupportedOperationException("getOrPut is not supported on ConcurrentMap.")

View File

@@ -61,10 +61,7 @@ public fun ByteArray.inputStream(offset: Int, length: Int) : ByteArrayInputStrea
* @param bufferSize the buffer size to use.
*/
public fun InputStream.buffered(bufferSize: Int = defaultBufferSize): InputStream
= if (this is BufferedInputStream)
this
else
BufferedInputStream(this, bufferSize)
= if (this is BufferedInputStream) this else BufferedInputStream(this, bufferSize)
/** Creates a reader on this input stream using UTF-8 or the specified [charset]. */
public fun InputStream.reader(charset: Charset = Charsets.UTF_8): InputStreamReader = InputStreamReader(this, charset)

View File

@@ -48,12 +48,6 @@ public fun String.reader(): StringReader = StringReader(this)
*/
public fun BufferedReader.lineSequence(): Sequence<String> = LinesSequence(this).constrainOnce()
@Deprecated("Use lineSequence() instead to avoid conflict with JDK8 lines() method.", ReplaceWith("lineSequence()"))
public fun BufferedReader.lines(): Sequence<String> = lineSequence()
@Deprecated("Use lineSequence() function which returns Sequence<String>")
public fun BufferedReader.lineIterator(): Iterator<String> = lineSequence().iterator()
private class LinesSequence(private val reader: BufferedReader) : Sequence<String> {
override public fun iterator(): Iterator<String> {
return object : Iterator<String> {

View File

@@ -211,16 +211,6 @@ public class FileTreeWalk(private val start: File,
return FileTreeWalk(start, direction, enter, leave, function, filter, maxDepth)
}
/**
* Sets tree filter [predicate].
* Tree filter [predicate] function is called before visiting files and entering directories.
* If it returns `false`, file is not visited, directory is not entered and all its content is also not visited.
* If it returns `true`, everything goes in the regular way.
*/
@Deprecated("Use treeFilter instead", ReplaceWith("treeFilter(predicate)"))
public fun filter(predicate: (File) -> Boolean): FileTreeWalk {
return FileTreeWalk(start, direction, enter, leave, fail, predicate, maxDepth)
}
/**
* Sets tree filter [predicate].
@@ -295,7 +285,7 @@ public fun File.walkBottomUp(): FileTreeWalk = walk(FileWalkDirection.BOTTOM_UP)
*
* @param function the function to call on each file.
*/
@Deprecated("It's recommended to use walkTopDown() / walkBottomUp()", ReplaceWith("walkTopDown().forEach(function)"))
@Deprecated("It's recommended to use walkTopDown() / walkBottomUp()", ReplaceWith("walkTopDown().forEach(function)"), DeprecationLevel.ERROR)
public fun File.recurse(function: (File) -> Unit): Unit {
walkTopDown().forEach(function)
}

View File

@@ -54,31 +54,10 @@ public val File.directory: File
/**
* Returns parent of this abstract path name, or `null` if it has no parent.
*/
@Deprecated("Use parentFile", ReplaceWith("parentFile"))
@Deprecated("Use parentFile", ReplaceWith("parentFile"), DeprecationLevel.ERROR)
public val File.parent: File?
get() = parentFile
/**
* Returns the canonical path of this file.
*/
@Deprecated("Is replaced with automatic synthetic extension", ReplaceWith("canonicalPath"), level = DeprecationLevel.HIDDEN)
public val File.canonicalPath: String
get() = getCanonicalPath()
/**
* Returns the file name.
*/
@Deprecated("Is replaced with automatic synthetic extension", ReplaceWith("name"), level = DeprecationLevel.HIDDEN)
public val File.name: String
get() = getName()
/**
* Returns the file path.
*/
@Deprecated("Is replaced with automatic synthetic extension", ReplaceWith("path"), level = DeprecationLevel.HIDDEN)
public val File.path: String
get() = getPath()
/**
* Returns the extension of this file (not including the dot), or an empty string if it doesn't have one.
*/

View File

@@ -117,7 +117,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
/** Indicates whether the regular expression can find at least one match in the specified [input]. */
public fun containsMatchIn(input: CharSequence): Boolean = nativePattern.matcher(input).find()
@Deprecated("Use containsMatchIn() or 'in' operator instead.", ReplaceWith("this in input"))
@Deprecated("Use containsMatchIn() or 'in' operator instead.", ReplaceWith("this in input"), DeprecationLevel.ERROR)
public fun hasMatch(input: CharSequence): Boolean = containsMatchIn(input)
/**
@@ -128,7 +128,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
*/
public fun find(input: CharSequence, startIndex: Int = 0): MatchResult? = nativePattern.matcher(input).findNext(startIndex, input)
@Deprecated("Use find() instead.", ReplaceWith("find(input, startIndex)"))
@Deprecated("Use find() instead.", ReplaceWith("find(input, startIndex)"), DeprecationLevel.ERROR)
public fun match(input: CharSequence, startIndex: Int = 0): MatchResult? = find(input, startIndex)
/**
@@ -136,7 +136,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
*/
public fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = sequence({ find(input, startIndex) }, { match -> match.next() })
@Deprecated("Use findAll() instead.", ReplaceWith("findAll(input, startIndex)"))
@Deprecated("Use findAll() instead.", ReplaceWith("findAll(input, startIndex)"), DeprecationLevel.ERROR)
public fun matchAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult> = findAll(input, startIndex)
/**

View File

@@ -5,7 +5,7 @@ package kotlin
private object _Assertions
@Deprecated("Must be public to make assert() inlinable")
@Deprecated("Not supposed to be used directly, exposed to make assert() inlinable.")
public val ASSERTIONS_ENABLED: Boolean = _Assertions.javaClass.desiredAssertionStatus()
/**
@@ -20,8 +20,9 @@ public fun assert(value: Boolean) {
* Throws an [AssertionError] with an optional [message] if the [value] is false
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
*/
@Deprecated("Use assert with lazy message instead.", ReplaceWith("assert(value) { message }"))
@Deprecated("Use assert with lazy message instead.", ReplaceWith("assert(value) { message }"), DeprecationLevel.ERROR)
public fun assert(value: Boolean, message: Any = "Assertion failed") {
@Suppress("DEPRECATION")
if (ASSERTIONS_ENABLED) {
if (!value) {
throw AssertionError(message)
@@ -34,6 +35,7 @@ public fun assert(value: Boolean, message: Any = "Assertion failed") {
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
*/
public inline fun assert(value: Boolean, lazyMessage: () -> Any) {
@Suppress("DEPRECATION")
if (ASSERTIONS_ENABLED) {
if (!value) {
val message = lazyMessage()

View File

@@ -25,7 +25,7 @@ import kotlin.reflect.KClass
* @property exceptionClasses the list of checked exception classes that may be thrown by the function.
*/
@Retention(AnnotationRetention.SOURCE)
@Deprecated("Use 'kotlin.jvm.Throws' instead", ReplaceWith("kotlin.jvm.Throws"))
@Deprecated("Use 'kotlin.jvm.Throws' instead", ReplaceWith("kotlin.jvm.Throws"), DeprecationLevel.ERROR)
public annotation class throws(public vararg val exceptionClasses: KClass<out Throwable>)
/**

View File

@@ -19,9 +19,6 @@ package kotlin
import java.util.Comparator
@Deprecated("Use compareValuesBy", ReplaceWith("compareValuesBy(a, b, *selectors)"), level = DeprecationLevel.HIDDEN)
public fun <T> compareValuesByNullable(a: T, b: T, vararg selectors: (T) -> Comparable<*>?): Int = compareValuesBy(a, b, *selectors)
/**
* Compares two values using the specified functions [selectors] to calculate the result of the comparison.
* The functions are called sequentially, receive the given values [a] and [b] and return [Comparable]

View File

@@ -16,7 +16,7 @@ public fun require(value: Boolean): Unit = require(value) { "Failed requirement"
*
* @sample test.collections.PreconditionsTest.failingRequireWithMessage
*/
@Deprecated("Use require with lazy message instead.", ReplaceWith("require(value) { message }"))
@Deprecated("Use require with lazy message instead.", ReplaceWith("require(value) { message }"), DeprecationLevel.ERROR)
public fun require(value: Boolean, message: Any = "Failed requirement"): Unit {
if (!value) {
throw IllegalArgumentException(message.toString())
@@ -46,7 +46,7 @@ public fun <T:Any> requireNotNull(value: T?): T = requireNotNull(value) { "Requi
*
* @sample test.collections.PreconditionsTest.requireNotNull
*/
@Deprecated("Use requireNotNull with lazy message instead.", ReplaceWith("requireNotNull(value) { message }"))
@Deprecated("Use requireNotNull with lazy message instead.", ReplaceWith("requireNotNull(value) { message }"), DeprecationLevel.ERROR)
public fun <T:Any> requireNotNull(value: T?, message: Any = "Required value was null"): T {
if (value == null) {
throw IllegalArgumentException(message.toString())
@@ -80,7 +80,7 @@ public fun check(value: Boolean): Unit = check(value) { "Check failed" }
*
* @sample test.collections.PreconditionsTest.failingCheckWithMessage
*/
@Deprecated("Use check with lazy message instead.", ReplaceWith("check(value) { message }"))
@Deprecated("Use check with lazy message instead.", ReplaceWith("check(value) { message }"), DeprecationLevel.ERROR)
public fun check(value: Boolean, message: Any = "Check failed"): Unit {
if (!value) {
throw IllegalStateException(message.toString())
@@ -111,7 +111,7 @@ public fun <T:Any> checkNotNull(value: T?): T = checkNotNull(value) { "Required
*
* @sample test.collections.PreconditionsTest.checkNotNull
*/
@Deprecated("Use checkNotNull with lazy message instead.", ReplaceWith("checkNotNull(value) { message }"))
@Deprecated("Use checkNotNull with lazy message instead.", ReplaceWith("checkNotNull(value) { message }"), DeprecationLevel.ERROR)
public fun <T:Any> checkNotNull(value: T?, message: Any = "Required value was null"): T {
if (value == null) {
throw IllegalStateException(message.toString())

View File

@@ -20,17 +20,6 @@ class PreconditionsTest() {
assertNotNull(error.getMessage())
}
@test fun passingRequireWithMessage() {
require(true, "Hello")
}
@test fun failingRequireWithMessage() {
val error = assertFailsWith(IllegalArgumentException::class) {
require(false, "Hello")
}
assertEquals("Hello", error.getMessage())
}
@test fun failingRequireWithLazyMessage() {
val error = assertFailsWith(IllegalArgumentException::class) {
require(false) { "Hello" }
@@ -53,17 +42,6 @@ class PreconditionsTest() {
assertNotNull(error.getMessage())
}
@test fun passingCheckWithMessage() {
check(true, "Hello")
}
@test fun failingCheckWithMessage() {
val error = assertFailsWith(IllegalStateException::class) {
check(false, "Hello")
}
assertEquals("Hello", error.getMessage())
}
@test fun failingCheckWithLazyMessage() {
val error = assertFailsWith(IllegalStateException::class) {
check(false) { "Hello" }
@@ -144,12 +122,12 @@ class PreconditionsTest() {
}
@test fun passingAssertWithMessage() {
assert(true, "Hello")
assert(true) { "Hello" }
}
@test fun failingAssertWithMessage() {
val error = assertFails {
assert(false, "Hello")
assert(false) { "Hello" }
}
if (error is AssertionError) {
assertEquals("Hello", error.getMessage())

View File

@@ -1,5 +1,6 @@
package test.collections
import test.collections.behaviors.listBehavior
import java.util.*
import kotlin.test.*
import org.junit.Test as test
@@ -443,12 +444,12 @@ class ArraysTest {
}
@test fun asList() {
assertEquals(listOf(1, 2, 3), intArrayOf(1, 2, 3).asList())
assertEquals(listOf<Byte>(1, 2, 3), byteArrayOf(1, 2, 3).asList())
assertEquals(listOf(true, false), booleanArrayOf(true, false).asList())
compare(listOf(1, 2, 3), intArrayOf(1, 2, 3).asList()) { listBehavior() }
compare(listOf<Byte>(1, 2, 3), byteArrayOf(1, 2, 3).asList()) { listBehavior() }
compare(listOf(true, false), booleanArrayOf(true, false).asList()) { listBehavior() }
assertEquals(listOf(1, 2, 3), arrayOf(1, 2, 3).asList())
assertEquals(listOf("abc", "def"), arrayOf("abc", "def").asList())
compare(listOf(1, 2, 3), arrayOf(1, 2, 3).asList()) { listBehavior() }
compare(listOf("abc", "def"), arrayOf("abc", "def").asList()) { listBehavior() }
val ints = intArrayOf(1, 5, 7)
val intsAsList = ints.asList()

View File

@@ -89,6 +89,10 @@ public fun <K, V> CompareContext<Map<K, V>>.mapBehavior() {
if (expected.isEmpty().not())
propertyEquals { contains(keySet().first()) }
propertyEquals { containsKeyRaw(keys.firstOrNull()) }
propertyEquals { containsValueRaw(values.firstOrNull()) }
propertyEquals { getRaw(null) }
compareProperty( { keySet() }, { setBehavior("keySet") } )
compareProperty( { entrySet() }, { setBehavior("entrySet") } )
compareProperty( { values() }, { collectionBehavior("values") })

View File

@@ -44,9 +44,8 @@ class MapJVMTest {
@test fun getOrPutFailsOnConcurrentMap() {
val map = ConcurrentHashMap<String, Int>()
assertFails {
map.getOrPut("x") { 1 }
}
// now this is an error
// map.getOrPut("x") { 1 }
expect(1) {
map.concurrentGetOrPut("x") { 1 }
}

View File

@@ -333,7 +333,7 @@ class FilesTest {
}
fun visitFile(file: File) {
assert(stack.last().listFiles().contains(file), file)
assert(stack.last().listFiles().contains(file)) { file }
files.add(file.relativeTo(basedir))
}
@@ -347,10 +347,10 @@ class FilesTest {
assert(stack.isEmpty())
val sep = File.separator
for (fileName in arrayOf("", "1", "1${sep}2", "1${sep}3", "6", "8")) {
assert(dirs.contains(fileName), fileName)
assert(dirs.contains(fileName)) { fileName }
}
for (fileName in arrayOf("1${sep}3${sep}4.txt", "1${sep}3${sep}4.txt", "7.txt", "8${sep}9.txt")) {
assert(files.contains(fileName), fileName)
assert(files.contains(fileName)) { fileName }
}
//limit maxDepth
@@ -359,9 +359,9 @@ class FilesTest {
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).maxDepth(1).
forEach { it -> if (it != basedir) visitFile(it) }
assert(stack.isEmpty())
assert(dirs.size() == 1 && dirs.contains(""), dirs.size())
assert(dirs.size() == 1 && dirs.contains("")) { dirs.size() }
for (file in arrayOf("1", "6", "7.txt", "8")) {
assert(files.contains(file), file)
assert(files.contains(file)) { file }
}
//restrict access
@@ -372,14 +372,14 @@ class FilesTest {
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
assert(stack.isEmpty())
assert(failed.size() == 1 && failed.contains("1"), failed.size())
assert(dirs.size() == 4, dirs.size())
assert(failed.size() == 1 && failed.contains("1")) { failed.size() }
assert(dirs.size() == 4) { dirs.size() }
for (dir in arrayOf("", "1", "6", "8")) {
assert(dirs.contains(dir), dir)
assert(dirs.contains(dir)) { dir }
}
assert(files.size() == 2, files.size())
assert(files.size() == 2) { files.size() }
for (file in arrayOf("7.txt", "8${sep}9.txt")) {
assert(files.contains(file), file)
assert(files.contains(file)) { file }
}
} finally {
File(basedir, "1").setReadable(true)
@@ -397,12 +397,12 @@ class FilesTest {
try {
val visited = HashSet<File>()
val block: (File) -> Unit = {
assert(!visited.contains(it), it)
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it)
assert(!visited.contains(it)) { it }
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile())) { it }
visited.add(it)
}
basedir.walkTopDown().forEach(block)
assert(visited.size() == 10, visited.size())
assert(visited.size() == 10) { visited.size() }
} finally {
basedir.deleteRecursively()
@@ -416,12 +416,12 @@ class FilesTest {
if (restricted.setReadable(false)) {
val visited = HashSet<File>()
val block: (File) -> Unit = {
assert(!visited.contains(it), it)
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile()), it)
assert(!visited.contains(it)) { it }
assert(it == basedir && visited.isEmpty() || visited.contains(it.getParentFile())) { it }
visited.add(it)
}
basedir.walkTopDown().forEach(block)
assert(visited.size() == 6, visited.size())
assert(visited.size() == 6) { visited.size() }
}
} finally {
restricted.setReadable(true)
@@ -521,12 +521,6 @@ class FilesTest {
}
}
@test fun recurse() {
val set: MutableSet<String> = HashSet()
val dir = createTestFiles()
dir.recurse { set.add(it.path) }
assertEquals(10, set.size())
}
}
@test fun listFilesWithFilter() {

View File

@@ -65,9 +65,9 @@ class KotlinGradleIT: BaseGradleIT() {
project.build(userVariantArg, "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
assertSuccessful()
val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(([+-]?\\d+) kb\\)".toRegex().find(output)
assert(matches != null && matches.groups.size() == 3, "Used memory after build is not reported by plugin")
assert(matches != null && matches.groups.size() == 3) { "Used memory after build is not reported by plugin" }
val reportedGrowth = matches!!.groups.get(2)!!.value.removePrefix("+").toInt()
assert(reportedGrowth <= 700, "Used memory growth $reportedGrowth > 700")
assert(reportedGrowth <= 700) { "Used memory growth $reportedGrowth > 700" }
}
}

View File

@@ -250,7 +250,6 @@ fun specialJVM(): List<GenericFunction> {
override val size: Int get() = this@asList.size()
override fun isEmpty(): Boolean = this@asList.isEmpty()
override fun contains(o: T): Boolean = this@asList.contains(o)
override fun iterator(): MutableIterator<T> = this@asList.iterator() as MutableIterator<T>
override fun get(index: Int): T = this@asList[index]
override fun indexOf(o: T): Int = this@asList.indexOf(o)
override fun lastIndexOf(o: T): Int = this@asList.lastIndexOf(o)

View File

@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
import org.jetbrains.kotlin.types.lowerIfFlexible
import org.jetbrains.org.objectweb.asm.Label
@@ -248,7 +250,7 @@ public class AndroidExpressionCodegenExtension : ExpressionCodegenExtension {
context.generateClearCacheFunction()
if (androidClassType.fragment) {
val classMembers = descriptor.unsubstitutedMemberScope.getContributedDescriptors()
val classMembers = descriptor.unsubstitutedMemberScope.getDescriptorsWithReflection()
val onDestroy = classMembers.firstOrNull { it is FunctionDescriptor && it.isOnDestroyFunction() }
if (onDestroy == null) {
context.generateOnDestroyFunctionForFragment()
@@ -258,6 +260,18 @@ public class AndroidExpressionCodegenExtension : ExpressionCodegenExtension {
classBuilder.newField(JvmDeclarationOrigin.NO_ORIGIN, ACC_PRIVATE, PROPERTY_NAME, "Ljava/util/HashMap;", null, null)
}
private fun MemberScope.getDescriptorsWithReflection(): Collection<DeclarationDescriptor> {
val gcDescriptorsMethod = javaClass.declaredMethods.firstOrNull { it.name == "getContributedDescriptors" } ?: return emptyList()
val memberScopeCompanionClass = MemberScope.Companion::class.java
val allNameFilterField = memberScopeCompanionClass.declaredMethods.firstOrNull { it.name == "getALL_NAME_FILTER" }
?: return emptyList()
val memberScopeCompanion = memberScopeCompanionClass.getDeclaredField("INSTANCE").get(null)
val allNameFilter = allNameFilterField.invoke(memberScopeCompanion)
@Suppress("UNCHECKED_CAST")
return gcDescriptorsMethod.invoke(this, DescriptorKindFilter.ALL, allNameFilter) as? Collection<DeclarationDescriptor> ?: emptyList()
}
private fun FunctionDescriptor.isOnDestroyFunction(): Boolean {
return kind == CallableMemberDescriptor.Kind.DECLARATION
&& name.asString() == ON_DESTROY_METHOD_NAME

View File

@@ -4,8 +4,8 @@
<property name="ideaVersion" value="143.379.11"/>
<property name="kotlin.bootstrap.branch" value=""/>
<property name="kotlin.bootstrap.branch.locator" value=""/>
<property name="kotlin.bootstrap.branch" value="beta2"/>
<property name="kotlin.bootstrap.branch.locator" value=",branch:beta2"/>
<property name="kotlin.bootstrap.locator" value="buildType:bt345,tag:bootstrap,status:SUCCESS${kotlin.bootstrap.branch.locator}"/>
<property name="kotlin.bootstrap.locator.force" value="false"/>
@@ -14,9 +14,7 @@
<property name="bootstrap.build.no.tests" value="false"/>
<!-- Uncomment to enable force version increment in branch. Set override.version.disabled to temporary disable feature without commits -->
<!--
<property name="override.version.url" value="https://teamcity.jetbrains.com/guestAuth/app/rest/builds/?locator=buildType:bt345,status:SUCCESS,count:1${kotlin.bootstrap.branch.locator}"/>
-->
<property name="override.version.url" value="https://teamcity.jetbrains.com/guestAuth/app/rest/builds/?locator=buildType:bt345,count:1${kotlin.bootstrap.branch.locator}"/>
<!--<property name="override.version.disabled" value="true"/>-->
<condition property="isWindows">