Skip to content

Commit

Permalink
Misc cleanups and updates (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Jul 16, 2021
1 parent 4897c5c commit 77997de
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Expand Up @@ -28,9 +28,9 @@ buildscript {
plugins {
kotlin("jvm") version Dependencies.Kotlin.version apply false
id("org.jetbrains.dokka") version Dependencies.Kotlin.dokkaVersion apply false
id("com.vanniktech.maven.publish") version "0.15.1" apply false
id("com.diffplug.spotless") version "5.12.4"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.5.0"
id("com.vanniktech.maven.publish") version "0.17.0" apply false
id("com.diffplug.spotless") version "5.14.1"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.6.0"
}

apiValidation {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Expand Up @@ -39,7 +39,7 @@ object Dependencies {
const val metadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0"
val compilerEmbeddable = "org.jetbrains.kotlin:kotlin-compiler-embeddable:$version"
const val jvmTarget = "1.8"
val defaultFreeCompilerArgs = listOf("-Xjsr305=strict", "-progressive")
val defaultFreeCompilerArgs = listOf("-Xjsr305=strict", "-progressive", "-Xopt-in=kotlin.RequiresOptIn")

object Ksp {
const val version = "1.5.21-1.0.0-beta05"
Expand Down
Expand Up @@ -238,7 +238,7 @@ private fun KSPropertyDeclaration.toPropertySpec(
.addModifiers(modifiers.map { KModifier.valueOf(it.name) })
.apply {
if (hasAnnotation(resolver.getClassDeclarationByName<Transient>().asType())) {
addAnnotation(Transient::class.java)
addAnnotation(Transient::class)
}
addAnnotations(
this@toPropertySpec.annotations
Expand Down
Expand Up @@ -23,6 +23,7 @@ import com.squareup.kotlinpoet.CHAR
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.DOUBLE
import com.squareup.kotlinpoet.DelicateKotlinPoetApi
import com.squareup.kotlinpoet.FLOAT
import com.squareup.kotlinpoet.INT
import com.squareup.kotlinpoet.KModifier
Expand Down Expand Up @@ -79,6 +80,7 @@ internal fun TypeName.defaultPrimitiveValue(): CodeBlock =
else -> CodeBlock.of("null")
}

@OptIn(DelicateKotlinPoetApi::class)
internal fun TypeName.asTypeBlock(): CodeBlock {
if (annotations.isNotEmpty()) {
return copy(annotations = emptyList()).asTypeBlock()
Expand Down
Expand Up @@ -19,6 +19,7 @@ import com.google.auto.service.AutoService
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.DelicateKotlinPoetApi
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
Expand Down Expand Up @@ -123,6 +124,7 @@ public class MoshiSealedProcessor : AbstractProcessor() {
private lateinit var options: Map<String, String>
private var generatedAnnotation: AnnotationSpec? = null

@OptIn(DelicateKotlinPoetApi::class)
override fun init(processingEnv: ProcessingEnvironment) {
super.init(processingEnv)
filer = processingEnv.filer
Expand All @@ -136,7 +138,6 @@ public class MoshiSealedProcessor : AbstractProcessor() {
}
elements.getTypeElement(it)
}?.let {
@Suppress("DEPRECATION")
AnnotationSpec.builder(it.asClassName())
.addMember("value = [%S]", MoshiSealedProcessor::class.java.canonicalName)
.addMember("comments = %S", "https://github.com/ZacSweers/moshi-sealed")
Expand Down Expand Up @@ -181,6 +182,7 @@ public class MoshiSealedProcessor : AbstractProcessor() {
return false
}

@OptIn(DelicateKotlinPoetApi::class)
private fun prepareAdapter(element: TypeElement, typeLabel: String, kmClass: ImmutableKmClass): PreparedAdapter? {
val sealedSubtypes = kmClass.sealedSubclasses
.map {
Expand All @@ -192,12 +194,10 @@ public class MoshiSealedProcessor : AbstractProcessor() {
it.getAnnotation(Metadata::class.java).toImmutableKmClass()
}
val defaultCodeBlockBuilder = CodeBlock.builder()
@Suppress("DEPRECATION")
val adapterName = ClassName.bestGuess(generatedJsonAdapterName(element.asClassName().reflectionName())).simpleName
val visibilityModifier = if (element.toImmutableKmClass().flags.isInternal) KModifier.INTERNAL else KModifier.PUBLIC
val allocator = NameAllocator()

@Suppress("DEPRECATION")
val targetType = element.asClassName()
val moshiClass = Moshi::class
val moshiParam = ParameterSpec.builder(allocator.newName("moshi"), moshiClass).build()
Expand Down Expand Up @@ -255,7 +255,6 @@ public class MoshiSealedProcessor : AbstractProcessor() {
return null
}

@Suppress("DEPRECATION")
val className = type.asClassName()
val mainLabel = labelAnnotation.label
seenLabels.put(mainLabel, className)?.let { prev ->
Expand Down

0 comments on commit 77997de

Please sign in to comment.