Skip to content

Commit

Permalink
Rename ExcludeProperty to Exclude, rename LikableDataClass to Likable.
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyroid committed Jul 22, 2024
1 parent 210a395 commit 467eafb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
5 changes: 5 additions & 0 deletions annotation/src/main/java/com/m3u/annotation/Exclude.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.m3u.annotation

@Target(AnnotationTarget.FIELD)
@Retention(AnnotationRetention.SOURCE)
annotation class Exclude

This file was deleted.

5 changes: 5 additions & 0 deletions annotation/src/main/java/com/m3u/annotation/Likable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.m3u.annotation

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class Likable

This file was deleted.

16 changes: 8 additions & 8 deletions data/src/main/java/com/m3u/data/database/model/Channel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.compose.runtime.Immutable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.m3u.annotation.ExcludeProperty
import com.m3u.annotation.LikableDataClass
import com.m3u.annotation.Exclude
import com.m3u.annotation.Likable
import com.m3u.data.parser.xtream.XtreamChannelInfo
import io.ktor.http.URLBuilder
import io.ktor.http.Url
Expand All @@ -18,7 +18,7 @@ import kotlinx.serialization.Serializable
)
@Immutable
@Serializable
@LikableDataClass
@Likable
data class Channel(
@ColumnInfo(name = "url")
// playable url
Expand All @@ -39,20 +39,20 @@ data class Channel(
val licenseKey: String? = null,
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
@ExcludeProperty
@Exclude
val id: Int = 0,
// extra fields
@ColumnInfo(name = "favourite", index = true)
@ExcludeProperty
@Exclude
val favourite: Boolean = false,
@ColumnInfo(name = "hidden", defaultValue = "0")
@ExcludeProperty
@Exclude
val hidden: Boolean = false,
@ColumnInfo(name = "seen", defaultValue = "0")
@ExcludeProperty
@Exclude
val seen: Long = 0L,
@ColumnInfo(name = "channel_id", defaultValue = "NULL")
@ExcludeProperty
@Exclude
// if it is from m3u, it may be tvg-id
// if it is xtream live, it may be epgChannelId
// if it is xtream vod, it may be streamId
Expand Down
16 changes: 8 additions & 8 deletions data/src/main/java/com/m3u/data/database/model/Playlist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.Relation
import com.m3u.annotation.ExcludeProperty
import com.m3u.annotation.LikableDataClass
import com.m3u.annotation.Exclude
import com.m3u.annotation.Likable
import com.m3u.core.util.basic.startsWithAny
import com.m3u.data.parser.xtream.XtreamInput
import com.m3u.data.parser.xtream.XtreamParser
Expand All @@ -24,7 +24,7 @@ import kotlinx.serialization.encoding.Encoder
@Entity(tableName = "playlists")
@Immutable
@Serializable
@LikableDataClass
@Likable
data class Playlist(
@ColumnInfo(name = "title")
val title: String,
Expand All @@ -40,23 +40,23 @@ data class Playlist(
val url: String,
// extra fields
@ColumnInfo(name = "pinned_groups", defaultValue = "[]")
@ExcludeProperty
@Exclude
val pinnedCategories: List<String> = emptyList(),
@ColumnInfo(name = "hidden_groups", defaultValue = "[]")
@ExcludeProperty
@Exclude
val hiddenCategories: List<String> = emptyList(),
@ColumnInfo(name = "source", defaultValue = "0")
@Serializable(with = DataSourceSerializer::class)
val source: DataSource = DataSource.M3U,
@ColumnInfo(name = "user_agent", defaultValue = "NULL")
@ExcludeProperty
@Exclude
val userAgent: String? = null,
// epg playlist urls
@ColumnInfo(name = "epg_urls", defaultValue = "[]")
@ExcludeProperty
@Exclude
val epgUrls: List<String> = emptyList(),
@ColumnInfo(name = "auto_refresh_programmes", defaultValue = "0")
@ExcludeProperty
@Exclude
val autoRefreshProgrammes: Boolean = false
) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.m3u.processor.likable

import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.getDeclaredProperties
import com.google.devtools.ksp.isAnnotationPresent
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.processing.Resolver
Expand All @@ -10,8 +12,8 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSVisitorVoid
import com.google.devtools.ksp.symbol.Modifier
import com.google.devtools.ksp.validate
import com.m3u.annotation.ExcludeProperty
import com.m3u.annotation.LikableDataClass
import com.m3u.annotation.Exclude
import com.m3u.annotation.Likable
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FileSpec
Expand All @@ -28,7 +30,9 @@ class LikableSymbolProcessor(
private val codeGenerator: CodeGenerator
) : SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(LikableDataClass::class.qualifiedName!!)
val likableAnnotationName = requireNotNull(Likable::class.qualifiedName)
val symbols = resolver.getSymbolsWithAnnotation(likableAnnotationName)

val unableToProcess = symbols.filterNot { it.validate() }
symbols.forEach { symbol ->
symbol.accept(Visitor(), Unit)
Expand All @@ -37,8 +41,8 @@ class LikableSymbolProcessor(
}

private inner class Visitor : KSVisitorVoid() {
@OptIn(KspExperimental::class)
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) {
val qualifiedName = classDeclaration.qualifiedName?.asString() ?: return
val isDataClass = Modifier.DATA in classDeclaration.modifiers
if (!isDataClass) {
logger.error("@Likeable can only target data class.", classDeclaration)
Expand All @@ -48,7 +52,7 @@ class LikableSymbolProcessor(
val fileName = classDeclaration.simpleName.asString() + "Likeable"
val properties = classDeclaration
.getDeclaredProperties()
.filterNot { it.annotations.any { it.shortName.getShortName() == ExcludeProperty::class.simpleName } }
.filterNot { property -> property.isAnnotationPresent(Exclude::class) }
.toList()
val typeName = classDeclaration.asType(emptyList()).toTypeName()
val fileSpec = FileSpec.builder(packageName, fileName)
Expand Down

0 comments on commit 467eafb

Please sign in to comment.