Replace internal keyword with opt-in annotations

pull/19/head
Koitharu 4 years ago
parent 4a2f899a64
commit 25e26f1c62
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -16,7 +16,9 @@ compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += [
'-opt-in=kotlin.RequiresOptIn',
'-opt-in=kotlin.contracts.ExperimentalContracts',
'-opt-in=org.koitharu.kotatsu.parsers.InternalParsersApi',
]
}
}
@ -25,7 +27,9 @@ compileTestKotlin {
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += [
'-opt-in=kotlin.RequiresOptIn',
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi',
'-opt-in=org.koitharu.kotatsu.parsers.InternalParsersApi',
]
}
}

@ -0,0 +1,14 @@
package org.koitharu.kotatsu.parsers
/**
* This marker distinguishes the internal API and is used to opt-in for that feature when parsers developing.
*
* Any usage of a declaration annotated with `@InternalParsersApi` must be accepted either by
* annotating that usage with the [OptIn] annotation, e.g. `@OptIn(InternalParsersApi::class)`,
* or by using the compiler argument `-opt-in=org.koitharu.kotatsu.parsers.InternalParsersApi`.
*/
@Retention(AnnotationRetention.BINARY)
@SinceKotlin("1.3")
@RequiresOptIn
@MustBeDocumented
annotation class InternalParsersApi()

@ -89,6 +89,7 @@ abstract class MangaParser(val source: MangaSource) {
* @see [MangaChapter.id]
* @see [MangaPage.id]
*/
@InternalParsersApi
protected fun generateUid(url: String): Long {
var h = 1125899906842597L
source.name.forEach { c ->
@ -107,6 +108,7 @@ abstract class MangaParser(val source: MangaSource) {
* @see [MangaChapter.id]
* @see [MangaPage.id]
*/
@InternalParsersApi
protected fun generateUid(id: Long): Long {
var h = 1125899906842597L
source.name.forEach { c ->
@ -127,6 +129,7 @@ abstract class MangaParser(val source: MangaSource) {
return toAbsoluteUrl(domain)
}
@InternalParsersApi
@Suppress("NOTHING_TO_INLINE")
protected inline fun parseFailed(message: String? = null): Nothing {
throw ParseException(message, null)

@ -1,10 +1,11 @@
package org.koitharu.kotatsu.parsers.exception
import org.koitharu.kotatsu.parsers.InternalParsersApi
import org.koitharu.kotatsu.parsers.model.MangaSource
/**
* Authorization is required for access to the requested content
*/
class AuthRequiredException(
class AuthRequiredException @InternalParsersApi constructor(
val source: MangaSource,
) : RuntimeException("Authorization required")

@ -1,6 +1,8 @@
package org.koitharu.kotatsu.parsers.exception
class ParseException @JvmOverloads constructor(
import org.koitharu.kotatsu.parsers.InternalParsersApi
class ParseException @InternalParsersApi @JvmOverloads constructor(
message: String?,
cause: Throwable? = null,
) : RuntimeException(message, cause)

@ -1,5 +1,7 @@
package org.koitharu.kotatsu.parsers.model
import org.koitharu.kotatsu.parsers.InternalParsersApi
class Manga(
/**
* Unique identifier for manga
@ -74,7 +76,8 @@ class Manga(
val hasRating: Boolean
get() = rating in 0f..1f
internal fun copy(
@InternalParsersApi
fun copy(
title: String = this.title,
altTitle: String? = this.altTitle,
publicUrl: String = this.publicUrl,

@ -1,6 +1,9 @@
package org.koitharu.kotatsu.parsers.model
internal class WordSet(private vararg val words: String) {
import org.koitharu.kotatsu.parsers.InternalParsersApi
@InternalParsersApi
class WordSet(private vararg val words: String) {
fun anyWordIn(dateString: String): Boolean = words.any {
dateString.contains(it, ignoreCase = true)

Loading…
Cancel
Save