diff --git a/build.gradle b/build.gradle index b0eaaa9b..9b9107ed 100644 --- a/build.gradle +++ b/build.gradle @@ -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', ] } } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/InternalParsersApi.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/InternalParsersApi.kt new file mode 100644 index 00000000..676dae33 --- /dev/null +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/InternalParsersApi.kt @@ -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() \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt index c50aa3ea..c2453568 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/MangaParser.kt @@ -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) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/AuthRequiredException.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/AuthRequiredException.kt index 9a9f1a36..d94770e4 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/AuthRequiredException.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/AuthRequiredException.kt @@ -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") \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/ParseException.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/ParseException.kt index 5499fdfb..c0415ac4 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/ParseException.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/exception/ParseException.kt @@ -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) \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt index 49066162..c346518e 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/Manga.kt @@ -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, diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/WordSet.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/WordSet.kt index 3f2c0c68..c2e91358 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/model/WordSet.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/model/WordSet.kt @@ -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)