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 { kotlinOptions {
jvmTarget = '1.8' jvmTarget = '1.8'
freeCompilerArgs += [ freeCompilerArgs += [
'-opt-in=kotlin.RequiresOptIn',
'-opt-in=kotlin.contracts.ExperimentalContracts', '-opt-in=kotlin.contracts.ExperimentalContracts',
'-opt-in=org.koitharu.kotatsu.parsers.InternalParsersApi',
] ]
} }
} }
@ -25,7 +27,9 @@ compileTestKotlin {
kotlinOptions { kotlinOptions {
jvmTarget = '1.8' jvmTarget = '1.8'
freeCompilerArgs += [ freeCompilerArgs += [
'-opt-in=kotlin.RequiresOptIn',
'-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi', '-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 [MangaChapter.id]
* @see [MangaPage.id] * @see [MangaPage.id]
*/ */
@InternalParsersApi
protected fun generateUid(url: String): Long { protected fun generateUid(url: String): Long {
var h = 1125899906842597L var h = 1125899906842597L
source.name.forEach { c -> source.name.forEach { c ->
@ -107,6 +108,7 @@ abstract class MangaParser(val source: MangaSource) {
* @see [MangaChapter.id] * @see [MangaChapter.id]
* @see [MangaPage.id] * @see [MangaPage.id]
*/ */
@InternalParsersApi
protected fun generateUid(id: Long): Long { protected fun generateUid(id: Long): Long {
var h = 1125899906842597L var h = 1125899906842597L
source.name.forEach { c -> source.name.forEach { c ->
@ -127,6 +129,7 @@ abstract class MangaParser(val source: MangaSource) {
return toAbsoluteUrl(domain) return toAbsoluteUrl(domain)
} }
@InternalParsersApi
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
protected inline fun parseFailed(message: String? = null): Nothing { protected inline fun parseFailed(message: String? = null): Nothing {
throw ParseException(message, null) throw ParseException(message, null)

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

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

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

@ -1,6 +1,9 @@
package org.koitharu.kotatsu.parsers.model 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 { fun anyWordIn(dateString: String): Boolean = words.any {
dateString.contains(it, ignoreCase = true) dateString.contains(it, ignoreCase = true)

Loading…
Cancel
Save