[core] Add common JvmFile for compatibility

This commit is contained in:
Him188 2023-05-08 12:19:48 +01:00
parent 44e9bb118c
commit 64e3d6c0f2
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
3 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,54 @@
/*
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.jvm
import io.ktor.utils.io.errors.*
@CompatibilityOnlyJvmFile
public expect class JvmFile {
public constructor(pathname: String)
public constructor(parent: String, child: String)
public fun getName(): String?
public fun getParent(): String?
public fun getParentFile(): JvmFile?
public fun getPath(): String
public fun isAbsolute(): Boolean
public fun getAbsolutePath(): String
public fun getAbsoluteFile(): JvmFile
@Throws(IOException::class)
public fun getCanonicalPath(): String
@Throws(IOException::class)
public fun getCanonicalFile(): JvmFile?
@Throws(IOException::class)
public fun createNewFile(): Boolean
public fun length(): Long
public fun delete(): Boolean
public fun listFiles(): Array<JvmFile>?
public fun mkdir(): Boolean
public fun mkdirs(): Boolean
public fun renameTo(file: JvmFile): Boolean
}
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS, AnnotationTarget.FUNCTION)
@RequiresOptIn(
"JvmFile is only used for compatibility and for simplifying expect/actual structure. " +
"It allows you to use java.io.File in commonMain and is intended only for maintaining compatibility with legacy code in commonMain." +
"JvmFile is not implemented in Native and you must deprecate the implementation on nativeMain as HIDDEN." +
"Do not design new APIs using JvmFile."
)
public annotation class CompatibilityOnlyJvmFile

View File

@ -0,0 +1,13 @@
/*
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.jvm
@CompatibilityOnlyJvmFile
public actual typealias JvmFile = java.io.File

View File

@ -0,0 +1,58 @@
/*
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.mirai.utils.jvm
import io.ktor.utils.io.errors.*
@Suppress("DEPRECATION_ERROR")
@Deprecated("JvmFile is not implemented on native", level = DeprecationLevel.HIDDEN)
@CompatibilityOnlyJvmFile
public actual class JvmFile {
public actual fun getName(): String? = throw NotImplementedError()
public actual fun getParent(): String? = throw NotImplementedError()
public actual fun getParentFile(): JvmFile? = throw NotImplementedError()
public actual fun getPath(): String = throw NotImplementedError()
public actual fun isAbsolute(): Boolean = throw NotImplementedError()
public actual fun getAbsolutePath(): String = throw NotImplementedError()
public actual fun getAbsoluteFile(): JvmFile = throw NotImplementedError()
@Throws(IOException::class)
public actual fun getCanonicalPath(): String = throw NotImplementedError()
@Throws(IOException::class)
public actual fun getCanonicalFile(): JvmFile? = throw NotImplementedError()
@Throws(IOException::class)
public actual fun createNewFile(): Boolean = throw NotImplementedError()
public actual fun length(): Long = throw NotImplementedError()
public actual fun delete(): Boolean = throw NotImplementedError()
public actual fun listFiles(): Array<JvmFile>? = throw NotImplementedError()
public actual fun mkdir(): Boolean = throw NotImplementedError()
public actual fun mkdirs(): Boolean = throw NotImplementedError()
public actual fun renameTo(file: JvmFile): Boolean = throw NotImplementedError()
public actual constructor(pathname: String) {
throw NotImplementedError()
}
public actual constructor(parent: String, child: String) {
throw NotImplementedError()
}
}