mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
add excluding of impls
This commit is contained in:
parent
6b94215a7c
commit
ad5cc6ade6
@ -49,7 +49,7 @@ sealed interface AbleToAddInAttachmentMenuChat : Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializable(PreviewChatSerializer::class)
|
@Serializable(PreviewChatSerializer::class)
|
||||||
@ClassCastsIncluded
|
@ClassCastsIncluded(excludeRegex = ".*Impl.kt")
|
||||||
sealed interface Chat {
|
sealed interface Chat {
|
||||||
val id: IdChatIdentifier
|
val id: IdChatIdentifier
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,13 @@ package dev.inmo.tgbotapi.types.chat
|
|||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.JsonObject
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use ExtendedChannelChat due")
|
||||||
data class ExtendedChannelChatImpl(
|
data class ExtendedChannelChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
@ -33,6 +35,7 @@ data class ExtendedChannelChatImpl(
|
|||||||
) : ExtendedChannelChat
|
) : ExtendedChannelChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use ExtendedGroupChat due")
|
||||||
data class ExtendedGroupChatImpl(
|
data class ExtendedGroupChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
@ -54,6 +57,7 @@ data class ExtendedGroupChatImpl(
|
|||||||
) : ExtendedGroupChat
|
) : ExtendedGroupChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use ExtendedPrivateChat due")
|
||||||
data class ExtendedPrivateChatImpl(
|
data class ExtendedPrivateChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: UserId,
|
override val id: UserId,
|
||||||
@ -80,6 +84,7 @@ data class ExtendedPrivateChatImpl(
|
|||||||
typealias ExtendedUser = ExtendedPrivateChatImpl
|
typealias ExtendedUser = ExtendedPrivateChatImpl
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use ExtendedSupergroupChat due")
|
||||||
data class ExtendedSupergroupChatImpl(
|
data class ExtendedSupergroupChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
@ -121,6 +126,7 @@ data class ExtendedSupergroupChatImpl(
|
|||||||
) : ExtendedSupergroupChat
|
) : ExtendedSupergroupChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use ExtendedForumChat due")
|
||||||
data class ExtendedForumChatImpl(
|
data class ExtendedForumChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: IdChatIdentifier,
|
override val id: IdChatIdentifier,
|
||||||
|
@ -4,10 +4,12 @@ import dev.inmo.micro_utils.language_codes.IetfLanguageCode
|
|||||||
import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer
|
import dev.inmo.micro_utils.language_codes.IetfLanguageCodeSerializer
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode
|
import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use GroupChat due")
|
||||||
data class GroupChatImpl(
|
data class GroupChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
@ -16,6 +18,7 @@ data class GroupChatImpl(
|
|||||||
) : GroupChat
|
) : GroupChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use PrivateChat due")
|
||||||
data class PrivateChatImpl(
|
data class PrivateChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: UserId,
|
override val id: UserId,
|
||||||
@ -28,6 +31,7 @@ data class PrivateChatImpl(
|
|||||||
) : PrivateChat
|
) : PrivateChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use SupergroupChat due")
|
||||||
data class SupergroupChatImpl(
|
data class SupergroupChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
@ -38,6 +42,7 @@ data class SupergroupChatImpl(
|
|||||||
) : SupergroupChat
|
) : SupergroupChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use ForumChat due")
|
||||||
data class ForumChatImpl(
|
data class ForumChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: IdChatIdentifier,
|
override val id: IdChatIdentifier,
|
||||||
@ -48,6 +53,7 @@ data class ForumChatImpl(
|
|||||||
) : ForumChat
|
) : ForumChat
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@RiskFeature("This class is a subject of changes. It is better to use ChannelChat due")
|
||||||
data class ChannelChatImpl(
|
data class ChannelChatImpl(
|
||||||
@SerialName(idField)
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@ -2,4 +2,4 @@ package dev.inmo.tgbotapi.utils.internal
|
|||||||
|
|
||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.SOURCE)
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
internal annotation class ClassCastsIncluded
|
internal annotation class ClassCastsIncluded(val typesRegex: String = ".*", val excludeRegex: String = "")
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package dev.inmo.tgbotapi.ksp.processor
|
package dev.inmo.tgbotapi.ksp.processor
|
||||||
|
|
||||||
import com.google.devtools.ksp.getAllSuperTypes
|
import com.google.devtools.ksp.getAllSuperTypes
|
||||||
|
import com.google.devtools.ksp.getAnnotationsByType
|
||||||
import com.google.devtools.ksp.processing.*
|
import com.google.devtools.ksp.processing.*
|
||||||
import com.google.devtools.ksp.symbol.KSAnnotated
|
import com.google.devtools.ksp.symbol.KSAnnotated
|
||||||
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
import com.google.devtools.ksp.symbol.KSClassDeclaration
|
||||||
import com.squareup.kotlinpoet.AnnotationSpec
|
import com.squareup.kotlinpoet.AnnotationSpec
|
||||||
|
import com.squareup.kotlinpoet.ClassName
|
||||||
import com.squareup.kotlinpoet.FileSpec
|
import com.squareup.kotlinpoet.FileSpec
|
||||||
|
import com.squareup.kotlinpoet.ksp.toClassName
|
||||||
import com.squareup.kotlinpoet.ksp.writeTo
|
import com.squareup.kotlinpoet.ksp.writeTo
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -15,17 +18,37 @@ class TelegramBotAPISymbolProcessor(
|
|||||||
private val outputFile: String = "Output",
|
private val outputFile: String = "Output",
|
||||||
private val outputFolder: String? = null
|
private val outputFolder: String? = null
|
||||||
) : SymbolProcessor {
|
) : SymbolProcessor {
|
||||||
|
private val classCastsIncludedClassName = ClassName("dev.inmo.tgbotapi.utils.internal", "ClassCastsIncluded")
|
||||||
override fun process(resolver: Resolver): List<KSAnnotated> {
|
override fun process(resolver: Resolver): List<KSAnnotated> {
|
||||||
val classes = resolver.getSymbolsWithAnnotation("dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded").filterIsInstance<KSClassDeclaration>()
|
val classes = resolver.getSymbolsWithAnnotation(classCastsIncludedClassName.canonicalName).filterIsInstance<KSClassDeclaration>()
|
||||||
|
val classesRegexes: Map<KSClassDeclaration, Pair<Regex, Regex?>> = classes.mapNotNull {
|
||||||
|
it to (it.annotations.firstNotNullOfOrNull {
|
||||||
|
runCatching {
|
||||||
|
if (it.annotationType.resolve().toClassName() == classCastsIncludedClassName) {
|
||||||
|
val regex = it.arguments.first().value as? String ?: return@runCatching null
|
||||||
|
val negativeRegex = (it.arguments.first().value as? String) ?.takeIf { it.isNotEmpty() }
|
||||||
|
Regex(regex) to (negativeRegex ?.let(::Regex))
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}.getOrNull()
|
||||||
|
} ?: return@mapNotNull null)
|
||||||
|
}.toMap()
|
||||||
val classesSubtypes = mutableMapOf<KSClassDeclaration, MutableSet<KSClassDeclaration>>()
|
val classesSubtypes = mutableMapOf<KSClassDeclaration, MutableSet<KSClassDeclaration>>()
|
||||||
|
|
||||||
resolver.getAllFiles().forEach {
|
resolver.getAllFiles().forEach {
|
||||||
it.declarations.forEach { potentialSubtype ->
|
it.declarations.forEach { potentialSubtype ->
|
||||||
if (potentialSubtype is KSClassDeclaration) {
|
if (potentialSubtype is KSClassDeclaration) {
|
||||||
val allSupertypes = potentialSubtype.getAllSuperTypes().map { it.declaration }
|
val allSupertypes = potentialSubtype.getAllSuperTypes().map { it.declaration }
|
||||||
classes.forEach {
|
|
||||||
if (it in allSupertypes) {
|
for (currentClass in classes) {
|
||||||
classesSubtypes.getOrPut(it) { mutableSetOf() }.add(potentialSubtype)
|
val regexes = classesRegexes[currentClass]
|
||||||
|
when {
|
||||||
|
currentClass in allSupertypes
|
||||||
|
&& regexes ?.first ?.matches(potentialSubtype.simpleName.toString()) != false
|
||||||
|
&& regexes ?.second ?.matches(potentialSubtype.simpleName.toString()) != true-> {
|
||||||
|
classesSubtypes.getOrPut(currentClass) { mutableSetOf() }.add(potentialSubtype)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user