|
|
|
@ -15,19 +15,20 @@ class ParserProcessor(
|
|
|
|
private val logger: KSPLogger,
|
|
|
|
private val logger: KSPLogger,
|
|
|
|
private val options: Map<String, String>,
|
|
|
|
private val options: Map<String, String>,
|
|
|
|
) : SymbolProcessor {
|
|
|
|
) : SymbolProcessor {
|
|
|
|
|
|
|
|
|
|
|
|
private val availableLocales = Locale.getAvailableLocales().toSet()
|
|
|
|
private val availableLocales = Locale.getAvailableLocales().toSet()
|
|
|
|
private val sourceNamePattern = Regex("[A-Z_][A-Z0-9_]{3,}")
|
|
|
|
private val sourceNamePattern = Regex("[A-Z_][A-Z0-9_]{3,}")
|
|
|
|
|
|
|
|
|
|
|
|
override fun process(resolver: Resolver): List<KSAnnotated> {
|
|
|
|
override fun process(resolver: Resolver): List<KSAnnotated> {
|
|
|
|
val symbols = resolver
|
|
|
|
val symbols =
|
|
|
|
|
|
|
|
resolver
|
|
|
|
.getSymbolsWithAnnotation("org.koitharu.kotatsu.parsers.MangaSourceParser")
|
|
|
|
.getSymbolsWithAnnotation("org.koitharu.kotatsu.parsers.MangaSourceParser")
|
|
|
|
val ret = symbols.filterNot { it.validate() }.toList()
|
|
|
|
val ret = symbols.filterNot { it.validate() }.toList()
|
|
|
|
if (!symbols.iterator().hasNext()) {
|
|
|
|
if (!symbols.iterator().hasNext()) {
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val dependencies = Dependencies.ALL_FILES
|
|
|
|
val dependencies = Dependencies.ALL_FILES
|
|
|
|
val factoryFile = try {
|
|
|
|
val factoryFile =
|
|
|
|
|
|
|
|
try {
|
|
|
|
codeGenerator.createNewFile(
|
|
|
|
codeGenerator.createNewFile(
|
|
|
|
dependencies = dependencies,
|
|
|
|
dependencies = dependencies,
|
|
|
|
packageName = "org.koitharu.kotatsu.parsers",
|
|
|
|
packageName = "org.koitharu.kotatsu.parsers",
|
|
|
|
@ -37,7 +38,8 @@ class ParserProcessor(
|
|
|
|
logger.warn(e.toString(), null)
|
|
|
|
logger.warn(e.toString(), null)
|
|
|
|
null
|
|
|
|
null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
val sourcesFile = try {
|
|
|
|
val sourcesFile =
|
|
|
|
|
|
|
|
try {
|
|
|
|
codeGenerator.createNewFile(
|
|
|
|
codeGenerator.createNewFile(
|
|
|
|
dependencies = dependencies,
|
|
|
|
dependencies = dependencies,
|
|
|
|
packageName = "org.koitharu.kotatsu.parsers.model",
|
|
|
|
packageName = "org.koitharu.kotatsu.parsers.model",
|
|
|
|
@ -88,6 +90,7 @@ class ParserProcessor(
|
|
|
|
val isBroken: Boolean,
|
|
|
|
val isBroken: Boolean,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
LOCAL("Local", "", ContentType.OTHER, false),
|
|
|
|
LOCAL("Local", "", ContentType.OTHER, false),
|
|
|
|
|
|
|
|
UNKNOWN("Unknown", "", ContentType.OTHER, true),
|
|
|
|
|
|
|
|
|
|
|
|
""".trimIndent(),
|
|
|
|
""".trimIndent(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -99,8 +102,9 @@ class ParserProcessor(
|
|
|
|
|
|
|
|
|
|
|
|
factoryWriter?.write(
|
|
|
|
factoryWriter?.write(
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
MangaSource.LOCAL -> throw NotImplementedError("Local manga parser is not supported")
|
|
|
|
MangaSource.LOCAL,
|
|
|
|
MangaSource.DUMMY -> throw NotImplementedError("Dummy manga parser cannot be instantiated")
|
|
|
|
MangaSource.UNKNOWN,
|
|
|
|
|
|
|
|
MangaSource.DUMMY -> throw NotImplementedError("Manga parser ${'$'}name cannot be instantiated")
|
|
|
|
}.also {
|
|
|
|
}.also {
|
|
|
|
require(it.source == this) {
|
|
|
|
require(it.source == this) {
|
|
|
|
"Cannot instantiate manga parser: ${'$'}name mapped to ${'$'}{it.source}"
|
|
|
|
"Cannot instantiate manga parser: ${'$'}name mapped to ${'$'}{it.source}"
|
|
|
|
@ -121,10 +125,12 @@ class ParserProcessor(
|
|
|
|
private val sourcesWriter: Writer?,
|
|
|
|
private val sourcesWriter: Writer?,
|
|
|
|
private val factoryWriter: Writer?,
|
|
|
|
private val factoryWriter: Writer?,
|
|
|
|
) : KSVisitorVoid() {
|
|
|
|
) : KSVisitorVoid() {
|
|
|
|
|
|
|
|
|
|
|
|
private val titles = HashMap<String, String>()
|
|
|
|
private val titles = HashMap<String, String>()
|
|
|
|
|
|
|
|
|
|
|
|
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) {
|
|
|
|
override fun visitClassDeclaration(
|
|
|
|
|
|
|
|
classDeclaration: KSClassDeclaration,
|
|
|
|
|
|
|
|
data: Unit,
|
|
|
|
|
|
|
|
) {
|
|
|
|
if (classDeclaration.classKind != ClassKind.CLASS || classDeclaration.isAbstract()) {
|
|
|
|
if (classDeclaration.classKind != ClassKind.CLASS || classDeclaration.isAbstract()) {
|
|
|
|
logger.error("Only non-abstract can be annotated with @MangaSourceParser", classDeclaration)
|
|
|
|
logger.error("Only non-abstract can be annotated with @MangaSourceParser", classDeclaration)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -161,13 +167,21 @@ class ParserProcessor(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
factoryWriter?.write("\tMangaSource.$name -> $className(context)\n")
|
|
|
|
factoryWriter?.write("\tMangaSource.$name -> $className(context)\n")
|
|
|
|
val deprecationString = if (deprecation != null) {
|
|
|
|
val deprecationString =
|
|
|
|
val reason = deprecation.arguments
|
|
|
|
if (deprecation != null) {
|
|
|
|
.find { it.name?.asString() == "message" }?.value?.toString() ?: "Unknown reason"
|
|
|
|
val reason =
|
|
|
|
|
|
|
|
deprecation.arguments
|
|
|
|
|
|
|
|
.find { it.name?.asString() == "message" }
|
|
|
|
|
|
|
|
?.value
|
|
|
|
|
|
|
|
?.toString() ?: "Unknown reason"
|
|
|
|
"@Deprecated(\"$reason\") "
|
|
|
|
"@Deprecated(\"$reason\") "
|
|
|
|
} else ""
|
|
|
|
} else {
|
|
|
|
|
|
|
|
""
|
|
|
|
|
|
|
|
}
|
|
|
|
val localeComment = localeTitle?.toTitleCase(localeObj)?.let { " /* $it */" }.orEmpty()
|
|
|
|
val localeComment = localeTitle?.toTitleCase(localeObj)?.let { " /* $it */" }.orEmpty()
|
|
|
|
sourcesWriter?.write("\t$deprecationString$name(\"$title\", $localeString$localeComment, ContentType.$type, $isBroken),\n")
|
|
|
|
sourcesWriter?.write(
|
|
|
|
|
|
|
|
"\t$deprecationString$name(\"$title\", $localeString$localeComment, ContentType.$type, $isBroken),\n",
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|