mirror of
https://github.com/fankes/moshi.git
synced 2025-10-18 23:49:21 +08:00
Update plugin spotless to v6.14.0 (#1620)
* Update plugin spotless to v6.14.0 * Update Spotless version and apply --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Jake Wharton <jw@squareup.com>
This commit is contained in:
@@ -34,7 +34,7 @@ tasks.withType<Test>().configureEach {
|
||||
"--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
|
||||
"--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
|
||||
"--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
|
||||
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
|
||||
"--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ val shadowJar = tasks.shadowJar.apply {
|
||||
relocate("com.squareup.kotlinpoet.metadata", "com.squareup.moshi.kotlinpoet.metadata")
|
||||
relocate(
|
||||
"com.squareup.kotlinpoet.classinspector",
|
||||
"com.squareup.moshi.kotlinpoet.classinspector"
|
||||
"com.squareup.moshi.kotlinpoet.classinspector",
|
||||
)
|
||||
relocate("kotlinx.metadata", "com.squareup.moshi.kotlinx.metadata")
|
||||
transformers.add(ServiceFileTransformer())
|
||||
|
@@ -54,14 +54,14 @@ private const val TO_STRING_SIZE_BASE = TO_STRING_PREFIX.length + 1 // 1 is the
|
||||
@InternalMoshiCodegenApi
|
||||
public class AdapterGenerator(
|
||||
private val target: TargetType,
|
||||
private val propertyList: List<PropertyGenerator>
|
||||
private val propertyList: List<PropertyGenerator>,
|
||||
) {
|
||||
|
||||
private companion object {
|
||||
private val INT_TYPE_BLOCK = CodeBlock.of("%T::class.javaPrimitiveType", INT)
|
||||
private val DEFAULT_CONSTRUCTOR_MARKER_TYPE_BLOCK = CodeBlock.of(
|
||||
"%M",
|
||||
MemberName(MOSHI_UTIL_PACKAGE, "DEFAULT_CONSTRUCTOR_MARKER")
|
||||
MemberName(MOSHI_UTIL_PACKAGE, "DEFAULT_CONSTRUCTOR_MARKER"),
|
||||
)
|
||||
private val CN_MOSHI = Moshi::class.asClassName()
|
||||
private val CN_TYPE = Type::class.asClassName()
|
||||
@@ -89,13 +89,13 @@ public class AdapterGenerator(
|
||||
"PLATFORM_CLASS_MAPPED_TO_KOTLIN",
|
||||
// Cover for calling fromJson() on a Nothing property type. Theoretically nonsensical but we
|
||||
// support it
|
||||
"IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION"
|
||||
"IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION",
|
||||
).let { suppressions ->
|
||||
AnnotationSpec.builder(Suppress::class)
|
||||
.useSiteTarget(FILE)
|
||||
.addMember(
|
||||
suppressions.indices.joinToString { "%S" },
|
||||
*suppressions
|
||||
*suppressions,
|
||||
)
|
||||
.build()
|
||||
}
|
||||
@@ -116,54 +116,55 @@ public class AdapterGenerator(
|
||||
|
||||
private val moshiParam = ParameterSpec.builder(
|
||||
nameAllocator.newName("moshi"),
|
||||
CN_MOSHI
|
||||
CN_MOSHI,
|
||||
).build()
|
||||
private val typesParam = ParameterSpec.builder(
|
||||
nameAllocator.newName("types"),
|
||||
ARRAY.parameterizedBy(CN_TYPE)
|
||||
ARRAY.parameterizedBy(CN_TYPE),
|
||||
)
|
||||
.build()
|
||||
private val readerParam = ParameterSpec.builder(
|
||||
nameAllocator.newName("reader"),
|
||||
JsonReader::class
|
||||
JsonReader::class,
|
||||
)
|
||||
.build()
|
||||
private val writerParam = ParameterSpec.builder(
|
||||
nameAllocator.newName("writer"),
|
||||
JsonWriter::class
|
||||
JsonWriter::class,
|
||||
)
|
||||
.build()
|
||||
|
||||
// Don't use NameAllocator here because it will add `_` to the name since it's a keyword, and that
|
||||
// results in it warning about not matching the overridden function's params.
|
||||
// https://github.com/square/moshi/issues/1502
|
||||
private val valueParam = ParameterSpec.builder(
|
||||
"value",
|
||||
originalTypeName.copy(nullable = true)
|
||||
originalTypeName.copy(nullable = true),
|
||||
)
|
||||
.build()
|
||||
private val jsonAdapterTypeName = JsonAdapter::class.asClassName().parameterizedBy(
|
||||
originalTypeName
|
||||
originalTypeName,
|
||||
)
|
||||
|
||||
// selectName() API setup
|
||||
private val optionsProperty = PropertySpec.builder(
|
||||
nameAllocator.newName("options"),
|
||||
JsonReader.Options::class.asTypeName(),
|
||||
KModifier.PRIVATE
|
||||
KModifier.PRIVATE,
|
||||
)
|
||||
.initializer(
|
||||
"%T.of(%L)",
|
||||
JsonReader.Options::class.asTypeName(),
|
||||
nonTransientProperties
|
||||
.map { CodeBlock.of("%S", it.jsonName) }
|
||||
.joinToCode(", ")
|
||||
.joinToCode(", "),
|
||||
)
|
||||
.build()
|
||||
|
||||
private val constructorProperty = PropertySpec.builder(
|
||||
nameAllocator.newName("constructorRef"),
|
||||
Constructor::class.asClassName().parameterizedBy(originalTypeName).copy(nullable = true),
|
||||
KModifier.PRIVATE
|
||||
KModifier.PRIVATE,
|
||||
)
|
||||
.addAnnotation(Volatile::class)
|
||||
.mutable(true)
|
||||
@@ -245,10 +246,10 @@ public class AdapterGenerator(
|
||||
" ${if (typeVariables.size == 1) "type" else "types"} for generic type variables [",
|
||||
typeVariables.joinToString(", ") { it.name },
|
||||
"], but received ",
|
||||
"${typesParam.name}.size"
|
||||
"${typesParam.name}.size",
|
||||
)
|
||||
.endControlFlow()
|
||||
.build()
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -274,8 +275,8 @@ public class AdapterGenerator(
|
||||
nameAllocator,
|
||||
typeRenderer,
|
||||
moshiParam,
|
||||
uniqueAdapter.name
|
||||
)
|
||||
uniqueAdapter.name,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -309,7 +310,7 @@ public class AdapterGenerator(
|
||||
size,
|
||||
TO_STRING_PREFIX,
|
||||
name,
|
||||
")"
|
||||
")",
|
||||
)
|
||||
.build()
|
||||
}
|
||||
@@ -425,7 +426,7 @@ public class AdapterGenerator(
|
||||
"%N = %N.fromJson(%N)",
|
||||
property.localName,
|
||||
nameAllocator[property.delegateKey],
|
||||
readerParam
|
||||
readerParam,
|
||||
)
|
||||
} else {
|
||||
val exception = unexpectedNull(property, readerParam)
|
||||
@@ -434,7 +435,7 @@ public class AdapterGenerator(
|
||||
property.localName,
|
||||
nameAllocator[property.delegateKey],
|
||||
readerParam,
|
||||
exception
|
||||
exception,
|
||||
)
|
||||
}
|
||||
if (property.hasConstructorDefault) {
|
||||
@@ -446,7 +447,7 @@ public class AdapterGenerator(
|
||||
result.addStatement(
|
||||
"%1L = %1L and 0x%2L.toInt()",
|
||||
maskNames[maskNameIndex],
|
||||
Integer.toHexString(inverted)
|
||||
Integer.toHexString(inverted),
|
||||
)
|
||||
} else {
|
||||
// Presence tracker for a mutable property
|
||||
@@ -460,7 +461,7 @@ public class AdapterGenerator(
|
||||
propertyIndex,
|
||||
property.localName,
|
||||
nameAllocator[property.delegateKey],
|
||||
readerParam
|
||||
readerParam,
|
||||
)
|
||||
} else {
|
||||
val exception = unexpectedNull(property, readerParam)
|
||||
@@ -470,7 +471,7 @@ public class AdapterGenerator(
|
||||
property.localName,
|
||||
nameAllocator[property.delegateKey],
|
||||
readerParam,
|
||||
exception
|
||||
exception,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -550,7 +551,7 @@ public class AdapterGenerator(
|
||||
val coreLookupBlock = CodeBlock.of(
|
||||
"%T::class.java.getDeclaredConstructor(%L)",
|
||||
originalRawTypeName,
|
||||
args
|
||||
args,
|
||||
)
|
||||
val lookupBlock = if (originalTypeName is ParameterizedTypeName) {
|
||||
CodeBlock.of("(%L·as·%T)", coreLookupBlock, nonNullConstructorType)
|
||||
@@ -560,16 +561,16 @@ public class AdapterGenerator(
|
||||
val initializerBlock = CodeBlock.of(
|
||||
"this.%1N·?: %2L.also·{ this.%1N·= it }",
|
||||
constructorProperty,
|
||||
lookupBlock
|
||||
lookupBlock,
|
||||
)
|
||||
val localConstructorProperty = PropertySpec.builder(
|
||||
nameAllocator.newName("localConstructor"),
|
||||
nonNullConstructorType
|
||||
nonNullConstructorType,
|
||||
)
|
||||
.addAnnotation(
|
||||
AnnotationSpec.builder(Suppress::class)
|
||||
.addMember("%S", "UNCHECKED_CAST")
|
||||
.build()
|
||||
.build(),
|
||||
)
|
||||
.initializer(initializerBlock)
|
||||
.build()
|
||||
@@ -577,7 +578,7 @@ public class AdapterGenerator(
|
||||
result.addCode(
|
||||
"«%L%N.newInstance(",
|
||||
returnOrResultAssignment,
|
||||
localConstructorProperty
|
||||
localConstructorProperty,
|
||||
)
|
||||
} else {
|
||||
// Standard constructor call. Don't omit generics for parameterized types even if they can be
|
||||
@@ -597,7 +598,7 @@ public class AdapterGenerator(
|
||||
result.addCode(
|
||||
"/*·%L·*/·%L",
|
||||
input.parameter.name,
|
||||
input.type.rawType().defaultPrimitiveValue()
|
||||
input.type.rawType().defaultPrimitiveValue(),
|
||||
)
|
||||
} else {
|
||||
result.addCode("%N", (input as ParameterProperty).property.localName)
|
||||
@@ -638,7 +639,7 @@ public class AdapterGenerator(
|
||||
"%N.%N = %N",
|
||||
resultName,
|
||||
property.name,
|
||||
property.localName
|
||||
property.localName,
|
||||
)
|
||||
result.endControlFlow()
|
||||
} else {
|
||||
@@ -646,7 +647,7 @@ public class AdapterGenerator(
|
||||
"%1N.%2N = %3N ?: %1N.%2N",
|
||||
resultName,
|
||||
property.name,
|
||||
property.localName
|
||||
property.localName,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -663,7 +664,7 @@ public class AdapterGenerator(
|
||||
MemberName(MOSHI_UTIL_PACKAGE, "unexpectedNull"),
|
||||
property.localName,
|
||||
property.jsonName,
|
||||
reader
|
||||
reader,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -677,7 +678,7 @@ public class AdapterGenerator(
|
||||
result.addStatement(
|
||||
"throw·%T(%S)",
|
||||
NullPointerException::class,
|
||||
"${valueParam.name} was null! Wrap in .nullSafe() to write nullable values."
|
||||
"${valueParam.name} was null! Wrap in .nullSafe() to write nullable values.",
|
||||
)
|
||||
result.endControlFlow()
|
||||
|
||||
@@ -690,7 +691,7 @@ public class AdapterGenerator(
|
||||
nameAllocator[property.delegateKey],
|
||||
writerParam,
|
||||
valueParam,
|
||||
property.name
|
||||
property.name,
|
||||
)
|
||||
}
|
||||
result.addStatement("%N.endObject()", writerParam)
|
||||
@@ -706,7 +707,7 @@ private fun FunSpec.Builder.addMissingPropertyCheck(property: PropertyGenerator,
|
||||
MemberName(MOSHI_UTIL_PACKAGE, "missingProperty"),
|
||||
property.localName,
|
||||
property.jsonName,
|
||||
readerParam
|
||||
readerParam,
|
||||
)
|
||||
addCode(" ?: throw·%L", missingPropertyBlock)
|
||||
}
|
||||
@@ -753,20 +754,20 @@ private sealed class FromJsonComponent {
|
||||
abstract val type: TypeName
|
||||
|
||||
data class ParameterOnly(
|
||||
override val parameter: TargetParameter
|
||||
override val parameter: TargetParameter,
|
||||
) : FromJsonComponent(), ParameterComponent {
|
||||
override val type: TypeName = parameter.type
|
||||
}
|
||||
|
||||
data class PropertyOnly(
|
||||
override val property: PropertyGenerator
|
||||
override val property: PropertyGenerator,
|
||||
) : FromJsonComponent(), PropertyComponent {
|
||||
override val type: TypeName = property.target.type
|
||||
}
|
||||
|
||||
data class ParameterProperty(
|
||||
override val parameter: TargetParameter,
|
||||
override val property: PropertyGenerator
|
||||
override val property: PropertyGenerator,
|
||||
) : FromJsonComponent(), ParameterComponent, PropertyComponent {
|
||||
override val type: TypeName = parameter.type
|
||||
}
|
||||
|
@@ -46,20 +46,20 @@ public data class DelegateKey(
|
||||
nameAllocator: NameAllocator,
|
||||
typeRenderer: TypeRenderer,
|
||||
moshiParameter: ParameterSpec,
|
||||
propertyName: String
|
||||
propertyName: String,
|
||||
): PropertySpec {
|
||||
val qualifierNames = jsonQualifiers.joinToString("") {
|
||||
"At${it.typeName.rawType().simpleName}"
|
||||
}
|
||||
val adapterName = nameAllocator.newName(
|
||||
"${type.toVariableName().replaceFirstChar { it.lowercase(Locale.US) }}${qualifierNames}Adapter",
|
||||
this
|
||||
this,
|
||||
)
|
||||
|
||||
val adapterTypeName = JsonAdapter::class.asClassName().parameterizedBy(type)
|
||||
val standardArgs = arrayOf(
|
||||
moshiParameter,
|
||||
typeRenderer.render(type)
|
||||
typeRenderer.render(type),
|
||||
)
|
||||
|
||||
val (initializerString, args) = when {
|
||||
@@ -81,7 +81,7 @@ private fun AnnotationSpec.asInstantiationExpression(): CodeBlock {
|
||||
return CodeBlock.of(
|
||||
"%T(%L)",
|
||||
typeName,
|
||||
members.joinToCode()
|
||||
members.joinToCode(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,6 @@ package com.squareup.moshi.kotlin.codegen.api
|
||||
@Retention(value = AnnotationRetention.BINARY)
|
||||
@RequiresOptIn(
|
||||
level = RequiresOptIn.Level.WARNING,
|
||||
message = "This is an internal API and may change at any time."
|
||||
message = "This is an internal API and may change at any time.",
|
||||
)
|
||||
public annotation class InternalMoshiCodegenApi
|
||||
|
@@ -47,6 +47,6 @@ public object Options {
|
||||
|
||||
public val POSSIBLE_GENERATED_NAMES: Map<String, ClassName> = arrayOf(
|
||||
ClassName("javax.annotation.processing", "Generated"),
|
||||
ClassName("javax.annotation", "Generated")
|
||||
ClassName("javax.annotation", "Generated"),
|
||||
).associateBy { it.canonicalName }
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ import com.squareup.kotlinpoet.PropertySpec
|
||||
public class PropertyGenerator(
|
||||
public val target: TargetProperty,
|
||||
public val delegateKey: DelegateKey,
|
||||
public val isTransient: Boolean = false
|
||||
public val isTransient: Boolean = false,
|
||||
) {
|
||||
public val name: String = target.name
|
||||
public val jsonName: String = target.jsonName ?: target.name
|
||||
|
@@ -22,7 +22,7 @@ import com.squareup.kotlinpoet.KModifier
|
||||
public data class TargetConstructor(
|
||||
val parameters: LinkedHashMap<String, TargetParameter>,
|
||||
val visibility: KModifier,
|
||||
val signature: String?
|
||||
val signature: String?,
|
||||
) {
|
||||
init {
|
||||
visibility.checkIsVisibility()
|
||||
|
@@ -27,5 +27,5 @@ public data class TargetParameter(
|
||||
val hasDefault: Boolean,
|
||||
val jsonName: String? = null,
|
||||
val jsonIgnore: Boolean = false,
|
||||
val qualifiers: Set<AnnotationSpec>? = null
|
||||
val qualifiers: Set<AnnotationSpec>? = null,
|
||||
)
|
||||
|
@@ -26,7 +26,7 @@ public data class TargetProperty(
|
||||
val parameter: TargetParameter?,
|
||||
val visibility: KModifier,
|
||||
val jsonName: String?,
|
||||
val jsonIgnore: Boolean
|
||||
val jsonIgnore: Boolean,
|
||||
) {
|
||||
val name: String get() = propertySpec.name
|
||||
val type: TypeName get() = propertySpec.type
|
||||
|
@@ -63,7 +63,7 @@ internal abstract class TypeRenderer {
|
||||
CodeBlock.of(
|
||||
"%T.arrayOf(%L)",
|
||||
Types::class,
|
||||
renderObjectType(typeName.typeArguments[0])
|
||||
renderObjectType(typeName.typeArguments[0]),
|
||||
)
|
||||
} else {
|
||||
val builder = CodeBlock.builder().apply {
|
||||
@@ -97,7 +97,7 @@ internal abstract class TypeRenderer {
|
||||
method = "subtypeOf"
|
||||
}
|
||||
else -> throw IllegalArgumentException(
|
||||
"Unrepresentable wildcard type. Cannot have more than one bound: $typeName"
|
||||
"Unrepresentable wildcard type. Cannot have more than one bound: $typeName",
|
||||
)
|
||||
}
|
||||
CodeBlock.of("%T.%L(%L)", Types::class, method, render(target, forceBox = true))
|
||||
|
@@ -95,7 +95,7 @@ internal fun TypeName.asTypeBlock(): CodeBlock {
|
||||
CodeBlock.of(
|
||||
"%T.newInstance(%L, 0).javaClass",
|
||||
Array::class.java.asClassName(),
|
||||
componentType.rawType.asTypeBlock()
|
||||
componentType.rawType.asTypeBlock(),
|
||||
)
|
||||
} else {
|
||||
CodeBlock.of("%T::class.java", copy(nullable = false))
|
||||
@@ -148,7 +148,7 @@ internal fun TypeName.stripTypeVarVariance(resolver: TypeVariableResolver): Type
|
||||
}
|
||||
|
||||
internal fun ParameterizedTypeName.deepCopy(
|
||||
transform: (TypeName) -> TypeName
|
||||
transform: (TypeName) -> TypeName,
|
||||
): ParameterizedTypeName {
|
||||
return rawType.parameterizedBy(typeArguments.map { transform(it) })
|
||||
.copy(nullable = isNullable, annotations = annotations, tags = tags)
|
||||
@@ -156,7 +156,7 @@ internal fun ParameterizedTypeName.deepCopy(
|
||||
|
||||
internal fun TypeVariableName.deepCopy(
|
||||
variance: KModifier? = this.variance,
|
||||
transform: (TypeName) -> TypeName
|
||||
transform: (TypeName) -> TypeName,
|
||||
): TypeVariableName {
|
||||
return TypeVariableName(name = name, bounds = bounds.map { transform(it) }, variance = variance)
|
||||
.copy(nullable = isNullable, annotations = annotations, tags = tags)
|
||||
@@ -184,7 +184,7 @@ internal fun LambdaTypeName.deepCopy(transform: (TypeName) -> TypeName): TypeNam
|
||||
return LambdaTypeName.get(
|
||||
receiver?.let(transform),
|
||||
parameters.map { it.toBuilder(type = transform(it.type)).build() },
|
||||
transform(returnType)
|
||||
transform(returnType),
|
||||
).copy(nullable = isNullable, annotations = annotations, suspending = isSuspending)
|
||||
}
|
||||
|
||||
|
@@ -31,13 +31,13 @@ private val OBJECT_CLASS = ClassName("java.lang", "Object")
|
||||
*/
|
||||
internal class AppliedType private constructor(
|
||||
val element: TypeElement,
|
||||
private val mirror: DeclaredType
|
||||
private val mirror: DeclaredType,
|
||||
) {
|
||||
/** Returns all supertypes of this, recursively. Only [CLASS] is used as we can't really use other types. */
|
||||
@OptIn(DelicateKotlinPoetApi::class)
|
||||
fun superclasses(
|
||||
types: Types,
|
||||
result: LinkedHashSet<AppliedType> = LinkedHashSet()
|
||||
result: LinkedHashSet<AppliedType> = LinkedHashSet(),
|
||||
): LinkedHashSet<AppliedType> {
|
||||
result.add(this)
|
||||
for (supertype in types.directSupertypes(mirror)) {
|
||||
|
@@ -73,7 +73,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() {
|
||||
generatedType = processingEnv.options[OPTION_GENERATED]?.let {
|
||||
POSSIBLE_GENERATED_NAMES[it] ?: error(
|
||||
"Invalid option value for $OPTION_GENERATED. Found $it, " +
|
||||
"allowable values are $POSSIBLE_GENERATED_NAMES."
|
||||
"allowable values are $POSSIBLE_GENERATED_NAMES.",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() {
|
||||
messager.printMessage(
|
||||
Diagnostic.Kind.ERROR,
|
||||
"@JsonClass can't be applied to $type: must be a Kotlin class",
|
||||
type
|
||||
type,
|
||||
)
|
||||
continue
|
||||
}
|
||||
@@ -115,10 +115,10 @@ public class JsonClassCodegenProcessor : AbstractProcessor() {
|
||||
AnnotationSpec.builder(generatedClassName)
|
||||
.addMember(
|
||||
"value = [%S]",
|
||||
JsonClassCodegenProcessor::class.java.canonicalName
|
||||
JsonClassCodegenProcessor::class.java.canonicalName,
|
||||
)
|
||||
.addMember("comments = %S", "https://github.com/square/moshi")
|
||||
.build()
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() {
|
||||
|
||||
private fun adapterGenerator(
|
||||
element: TypeElement,
|
||||
cachedClassInspector: MoshiCachedClassInspector
|
||||
cachedClassInspector: MoshiCachedClassInspector,
|
||||
): AdapterGenerator? {
|
||||
val type = targetType(
|
||||
messager,
|
||||
@@ -159,7 +159,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() {
|
||||
messager.printMessage(
|
||||
Diagnostic.Kind.ERROR,
|
||||
"No property for required constructor parameter $name",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ private val VISIBILITY_MODIFIERS = setOf(
|
||||
KModifier.INTERNAL,
|
||||
KModifier.PRIVATE,
|
||||
KModifier.PROTECTED,
|
||||
KModifier.PUBLIC
|
||||
KModifier.PUBLIC,
|
||||
)
|
||||
|
||||
private fun Collection<KModifier>.visibility(): KModifier {
|
||||
@@ -78,7 +78,7 @@ internal fun primaryConstructor(
|
||||
targetElement: TypeElement,
|
||||
kotlinApi: TypeSpec,
|
||||
elements: Elements,
|
||||
messager: Messager
|
||||
messager: Messager,
|
||||
): TargetConstructor? {
|
||||
val primaryConstructor = kotlinApi.primaryConstructor ?: return null
|
||||
|
||||
@@ -101,14 +101,14 @@ internal fun primaryConstructor(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"No KmConstructor found for primary constructor.",
|
||||
targetElement
|
||||
targetElement,
|
||||
)
|
||||
null
|
||||
}
|
||||
return TargetConstructor(
|
||||
parameters,
|
||||
primaryConstructor.modifiers.visibility(),
|
||||
kmConstructorSignature
|
||||
kmConstructorSignature,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must be a Kotlin class",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -138,7 +138,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must be a Class type",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -148,7 +148,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass with 'generateAdapter = \"true\"' can't be applied to $element: code gen for enums is not supported or necessary",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -156,7 +156,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must be a Kotlin class",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -164,7 +164,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must not be an inner class",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -172,7 +172,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must not be sealed",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -180,7 +180,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must not be abstract",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -188,7 +188,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must not be local",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -196,7 +196,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: must be internal or public",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -211,7 +211,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"No primary constructor found on $element",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -220,7 +220,7 @@ internal fun targetType(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: " +
|
||||
"primary constructor is not internal or public",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -234,7 +234,7 @@ internal fun targetType(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"@JsonClass can't be applied to $element: supertype $superclass is not a Kotlin type",
|
||||
element
|
||||
element,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -272,7 +272,7 @@ internal fun targetType(
|
||||
.cast<TypeVariableName>()
|
||||
.map(TypeVariableName::name)
|
||||
.zip(apiSuperClass.typeArguments.asSequence())
|
||||
.associate { it }
|
||||
.associate { it },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ internal fun targetType(
|
||||
kotlinApi = supertypeApi,
|
||||
allowedTypeVars = typeVariables.toSet(),
|
||||
currentClass = appliedClassName,
|
||||
resolvedTypes = resolvedTypes
|
||||
resolvedTypes = resolvedTypes,
|
||||
)
|
||||
for ((name, property) in supertypeProperties) {
|
||||
properties.putIfAbsent(name, property)
|
||||
@@ -328,7 +328,7 @@ private fun resolveTypeArgs(
|
||||
propertyType: TypeName,
|
||||
resolvedTypes: List<ResolvedTypeMapping>,
|
||||
allowedTypeVars: Set<TypeVariableName>,
|
||||
entryStartIndex: Int = resolvedTypes.indexOfLast { it.target == targetClass }
|
||||
entryStartIndex: Int = resolvedTypes.indexOfLast { it.target == targetClass },
|
||||
): TypeName {
|
||||
val unwrappedType = propertyType.unwrapTypeAlias()
|
||||
|
||||
@@ -370,7 +370,7 @@ private fun declaredProperties(
|
||||
kotlinApi: TypeSpec,
|
||||
allowedTypeVars: Set<TypeVariableName>,
|
||||
currentClass: ClassName,
|
||||
resolvedTypes: List<ResolvedTypeMapping>
|
||||
resolvedTypes: List<ResolvedTypeMapping>,
|
||||
): Map<String, TargetProperty> {
|
||||
val result = mutableMapOf<String, TargetProperty>()
|
||||
for (initialProperty in kotlinApi.propertySpecs) {
|
||||
@@ -378,7 +378,7 @@ private fun declaredProperties(
|
||||
targetClass = currentClass,
|
||||
propertyType = initialProperty.type,
|
||||
resolvedTypes = resolvedTypes,
|
||||
allowedTypeVars = allowedTypeVars
|
||||
allowedTypeVars = allowedTypeVars,
|
||||
)
|
||||
val property = initialProperty.toBuilder(type = resolvedType).build()
|
||||
val name = property.name
|
||||
@@ -391,7 +391,7 @@ private fun declaredProperties(
|
||||
parameter = parameter,
|
||||
visibility = property.modifiers.visibility(),
|
||||
jsonName = parameter?.jsonName ?: property.annotations.jsonName() ?: name,
|
||||
jsonIgnore = isIgnored
|
||||
jsonIgnore = isIgnored,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ internal fun TargetProperty.generator(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"No default value for transient/ignored property $name",
|
||||
sourceElement
|
||||
sourceElement,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -431,7 +431,7 @@ internal fun TargetProperty.generator(
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"property $name is not visible",
|
||||
sourceElement
|
||||
sourceElement,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -452,7 +452,7 @@ internal fun TargetProperty.generator(
|
||||
if (it.value != RetentionPolicy.RUNTIME) {
|
||||
messager.printMessage(
|
||||
ERROR,
|
||||
"JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention"
|
||||
"JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -466,13 +466,13 @@ internal fun TargetProperty.generator(
|
||||
|
||||
return PropertyGenerator(
|
||||
this,
|
||||
DelegateKey(type, jsonQualifierSpecs)
|
||||
DelegateKey(type, jsonQualifierSpecs),
|
||||
)
|
||||
}
|
||||
|
||||
private fun List<AnnotationSpec>?.qualifiers(
|
||||
messager: Messager,
|
||||
elements: Elements
|
||||
elements: Elements,
|
||||
): Set<AnnotationSpec> {
|
||||
if (this == null) return setOf()
|
||||
return filterTo(mutableSetOf()) {
|
||||
|
@@ -32,7 +32,7 @@ private val OBJECT_CLASS = java.lang.Object::class.asClassName()
|
||||
*/
|
||||
internal class AppliedType private constructor(
|
||||
val type: KSClassDeclaration,
|
||||
val typeName: TypeName = type.toClassName()
|
||||
val typeName: TypeName = type.toClassName(),
|
||||
) {
|
||||
|
||||
/** Returns all super classes of this, recursively. Only [CLASS] is used as we can't really use other types. */
|
||||
|
@@ -48,7 +48,7 @@ public class JsonClassSymbolProcessorProvider : SymbolProcessorProvider {
|
||||
}
|
||||
|
||||
private class JsonClassSymbolProcessor(
|
||||
environment: SymbolProcessorEnvironment
|
||||
environment: SymbolProcessorEnvironment,
|
||||
) : SymbolProcessor {
|
||||
|
||||
private companion object {
|
||||
@@ -103,7 +103,7 @@ private class JsonClassSymbolProcessor(
|
||||
preparedAdapter.proguardConfig?.writeTo(codeGenerator, originatingFile)
|
||||
} catch (e: Exception) {
|
||||
logger.error(
|
||||
"Error preparing ${type.simpleName.asString()}: ${e.stackTrace.joinToString("\n")}"
|
||||
"Error preparing ${type.simpleName.asString()}: ${e.stackTrace.joinToString("\n")}",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -152,7 +152,7 @@ private fun ProguardConfig.writeTo(codeGenerator: CodeGenerator, originatingKSFi
|
||||
dependencies = Dependencies(aggregating = false, originatingKSFile),
|
||||
packageName = "",
|
||||
fileName = outputFilePathWithoutExtension(targetClass.canonicalName),
|
||||
extensionName = "pro"
|
||||
extensionName = "pro",
|
||||
)
|
||||
// Don't use writeTo(file) because that tries to handle directories under the hood
|
||||
OutputStreamWriter(file, StandardCharsets.UTF_8)
|
||||
|
@@ -89,8 +89,9 @@ private fun addValueToBlock(value: Any, resolver: Resolver, member: CodeBlock.Bu
|
||||
}
|
||||
is KSName ->
|
||||
member.add(
|
||||
"%T.%L", ClassName.bestGuess(value.getQualifier()),
|
||||
value.getShortName()
|
||||
"%T.%L",
|
||||
ClassName.bestGuess(value.getQualifier()),
|
||||
value.getShortName(),
|
||||
)
|
||||
is KSAnnotation -> member.add("%L", value.toAnnotationSpec(resolver))
|
||||
else -> member.add(memberForValue(value))
|
||||
|
@@ -48,7 +48,7 @@ internal fun TargetProperty.generator(
|
||||
if (!hasDefault) {
|
||||
logger.error(
|
||||
"No default value for transient/ignored property $name",
|
||||
originalType
|
||||
originalType,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -58,7 +58,7 @@ internal fun TargetProperty.generator(
|
||||
if (!isVisible) {
|
||||
logger.error(
|
||||
"property $name is not visible",
|
||||
originalType
|
||||
originalType,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -76,7 +76,7 @@ internal fun TargetProperty.generator(
|
||||
annotationElement.findAnnotationWithType<Retention>()?.let {
|
||||
if (it.value != AnnotationRetention.RUNTIME) {
|
||||
logger.error(
|
||||
"JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention"
|
||||
"JsonQualifier @${qualifierRawType.simpleName} must have RUNTIME retention",
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ internal fun TargetProperty.generator(
|
||||
|
||||
return PropertyGenerator(
|
||||
this,
|
||||
DelegateKey(type, jsonQualifierSpecs)
|
||||
DelegateKey(type, jsonQualifierSpecs),
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -86,7 +86,7 @@ internal fun targetType(
|
||||
}
|
||||
|
||||
val classTypeParamsResolver = type.typeParameters.toTypeParameterResolver(
|
||||
sourceTypeHint = type.qualifiedName!!.asString()
|
||||
sourceTypeHint = type.qualifiedName!!.asString(),
|
||||
)
|
||||
val typeVariables = type.typeParameters.map { it.toTypeVariableName(classTypeParamsResolver) }
|
||||
val appliedType = AppliedType(type)
|
||||
@@ -100,7 +100,7 @@ internal fun targetType(
|
||||
logger.error(
|
||||
"@JsonClass can't be applied to $type: " +
|
||||
"primary constructor is not internal or public",
|
||||
type
|
||||
type,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -117,7 +117,7 @@ internal fun targetType(
|
||||
Origin=${classDecl.origin}
|
||||
Annotations=${classDecl.annotations.joinToString(prefix = "[", postfix = "]") { it.shortName.getShortName() }}
|
||||
""".trimIndent(),
|
||||
type
|
||||
type,
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -127,7 +127,7 @@ internal fun targetType(
|
||||
classDecl = classDecl,
|
||||
resolver = resolver,
|
||||
typeParameterResolver = classDecl.typeParameters
|
||||
.toTypeParameterResolver(classTypeParamsResolver)
|
||||
.toTypeParameterResolver(classTypeParamsResolver),
|
||||
)
|
||||
for ((name, property) in supertypeProperties) {
|
||||
properties.putIfAbsent(name, property)
|
||||
@@ -169,7 +169,7 @@ internal fun primaryConstructor(
|
||||
resolver: Resolver,
|
||||
targetType: KSClassDeclaration,
|
||||
typeParameterResolver: TypeParameterResolver,
|
||||
logger: KSPLogger
|
||||
logger: KSPLogger,
|
||||
): TargetConstructor? {
|
||||
val primaryConstructor = targetType.primaryConstructor ?: return null
|
||||
|
||||
@@ -182,7 +182,7 @@ internal fun primaryConstructor(
|
||||
type = parameter.type.toTypeName(typeParameterResolver),
|
||||
hasDefault = parameter.hasDefault,
|
||||
qualifiers = parameter.qualifiers(resolver),
|
||||
jsonName = parameter.jsonName()
|
||||
jsonName = parameter.jsonName(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ internal fun primaryConstructor(
|
||||
return TargetConstructor(
|
||||
parameters,
|
||||
primaryConstructor.getVisibility().toKModifier() ?: KModifier.PUBLIC,
|
||||
kmConstructorSignature
|
||||
kmConstructorSignature,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ private fun declaredProperties(
|
||||
parameter = parameter,
|
||||
visibility = property.getVisibility().toKModifier() ?: KModifier.PUBLIC,
|
||||
jsonName = parameter?.jsonName ?: property.jsonName() ?: name,
|
||||
jsonIgnore = isTransient || parameter?.jsonIgnore == true || property.jsonIgnore()
|
||||
jsonIgnore = isTransient || parameter?.jsonIgnore == true || property.jsonIgnore(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -254,11 +254,11 @@ private fun declaredProperties(
|
||||
private fun KSPropertyDeclaration.toPropertySpec(
|
||||
resolver: Resolver,
|
||||
resolvedType: KSType,
|
||||
typeParameterResolver: TypeParameterResolver
|
||||
typeParameterResolver: TypeParameterResolver,
|
||||
): PropertySpec {
|
||||
return PropertySpec.builder(
|
||||
name = simpleName.getShortName(),
|
||||
type = resolvedType.toTypeName(typeParameterResolver).unwrapTypeAlias()
|
||||
type = resolvedType.toTypeName(typeParameterResolver).unwrapTypeAlias(),
|
||||
)
|
||||
.mutable(isMutable)
|
||||
.addModifiers(modifiers.map { KModifier.valueOf(it.name) })
|
||||
@@ -273,7 +273,7 @@ private fun KSPropertyDeclaration.toPropertySpec(
|
||||
null
|
||||
}
|
||||
}
|
||||
.asIterable()
|
||||
.asIterable(),
|
||||
)
|
||||
}
|
||||
.build()
|
||||
|
@@ -56,7 +56,7 @@ private fun <T : Annotation> KSAnnotation.toAnnotation(annotationClass: Class<T>
|
||||
return Proxy.newProxyInstance(
|
||||
annotationClass.classLoader,
|
||||
arrayOf(annotationClass),
|
||||
createInvocationHandler(annotationClass)
|
||||
createInvocationHandler(annotationClass),
|
||||
) as T
|
||||
}
|
||||
|
||||
@@ -119,8 +119,9 @@ private fun KSAnnotation.asAnnotation(
|
||||
annotationInterface: Class<*>,
|
||||
): Any {
|
||||
return Proxy.newProxyInstance(
|
||||
this.javaClass.classLoader, arrayOf(annotationInterface),
|
||||
this.createInvocationHandler(annotationInterface)
|
||||
this.javaClass.classLoader,
|
||||
arrayOf(annotationInterface),
|
||||
this.createInvocationHandler(annotationInterface),
|
||||
) as Proxy
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ private fun List<*>.asArray(method: Method) =
|
||||
private fun List<*>.toArray(method: Method, valueProvider: (Any) -> Any): Array<Any?> {
|
||||
val array: Array<Any?> = java.lang.reflect.Array.newInstance(
|
||||
method.returnType.componentType,
|
||||
this.size
|
||||
this.size,
|
||||
) as Array<Any?>
|
||||
for (r in 0 until this.size) {
|
||||
array[r] = this[r]?.let { valueProvider.invoke(it) }
|
||||
@@ -176,7 +177,7 @@ private fun <T> Any.asEnum(returnType: Class<T>): T =
|
||||
this.declaration.simpleName.getShortName()
|
||||
} else {
|
||||
this.toString()
|
||||
}
|
||||
},
|
||||
) as T
|
||||
|
||||
private fun Any.asByte(): Byte = if (this is Int) this.toByte() else this as Byte
|
||||
|
@@ -39,7 +39,8 @@ import kotlin.reflect.full.declaredMemberProperties
|
||||
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
||||
class JsonClassCodegenProcessorTest {
|
||||
|
||||
@Rule @JvmField val temporaryFolder: TemporaryFolder = TemporaryFolder()
|
||||
@Rule @JvmField
|
||||
val temporaryFolder: TemporaryFolder = TemporaryFolder()
|
||||
|
||||
@Test
|
||||
fun privateConstructor() {
|
||||
@@ -57,8 +58,8 @@ class JsonClassCodegenProcessorTest {
|
||||
fun newInstance(a: Int, b: Int) = PrivateConstructor(a, b)
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("constructor is not internal or public")
|
||||
@@ -74,8 +75,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class PrivateConstructorParameter(private var a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("property a is not visible")
|
||||
@@ -94,8 +95,8 @@ class JsonClassCodegenProcessorTest {
|
||||
private var a: Int = -1
|
||||
private var b: Int = -1
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("property a is not visible")
|
||||
@@ -111,12 +112,12 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
interface Interface
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to Interface: must be a Kotlin class"
|
||||
"error: @JsonClass can't be applied to Interface: must be a Kotlin class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -130,8 +131,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true, generator="customGenerator")
|
||||
interface Interface
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
}
|
||||
@@ -146,12 +147,12 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
abstract class AbstractClass(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to AbstractClass: must not be abstract"
|
||||
"error: @JsonClass can't be applied to AbstractClass: must not be abstract",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -165,12 +166,12 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
sealed class SealedClass(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to SealedClass: must not be sealed"
|
||||
"error: @JsonClass can't be applied to SealedClass: must not be sealed",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -186,12 +187,12 @@ class JsonClassCodegenProcessorTest {
|
||||
@JsonClass(generateAdapter = true)
|
||||
inner class InnerClass(val a: Int)
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to Outer.InnerClass: must not be an inner class"
|
||||
"error: @JsonClass can't be applied to Outer.InnerClass: must not be an inner class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -207,12 +208,12 @@ class JsonClassCodegenProcessorTest {
|
||||
enum class KotlinEnum {
|
||||
A, B
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass with 'generateAdapter = \"true\"' can't be applied to KotlinEnum: code gen for enums is not supported or necessary"
|
||||
"error: @JsonClass with 'generateAdapter = \"true\"' can't be applied to KotlinEnum: code gen for enums is not supported or necessary",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -230,12 +231,12 @@ class JsonClassCodegenProcessorTest {
|
||||
@JsonClass(generateAdapter = true)
|
||||
class LocalClass(val a: Int)
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to LocalClass: must not be local"
|
||||
"error: @JsonClass can't be applied to LocalClass: must not be local",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -249,12 +250,12 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
private class PrivateClass(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to PrivateClass: must be internal or public"
|
||||
"error: @JsonClass can't be applied to PrivateClass: must be internal or public",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -270,12 +271,12 @@ class JsonClassCodegenProcessorTest {
|
||||
object ObjectDeclaration {
|
||||
var a = 5
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to ObjectDeclaration: must be a Kotlin class"
|
||||
"error: @JsonClass can't be applied to ObjectDeclaration: must be a Kotlin class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -291,12 +292,12 @@ class JsonClassCodegenProcessorTest {
|
||||
val expression = object : Any() {
|
||||
var a = 5
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: @JsonClass can't be applied to getExpression\$annotations(): must be a Kotlin class"
|
||||
"error: @JsonClass can't be applied to getExpression\$annotations(): must be a Kotlin class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -310,12 +311,12 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class RequiredTransientConstructorParameter(@Transient var a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: No default value for transient/ignored property a"
|
||||
"error: No default value for transient/ignored property a",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -330,12 +331,12 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class RequiredIgnoredConstructorParameter(@Json(ignore = true) var a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: No default value for transient/ignored property a"
|
||||
"error: No default value for transient/ignored property a",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -349,12 +350,12 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class NonPropertyConstructorParameter(a: Int, val b: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"error: No property for required constructor parameter a"
|
||||
"error: No property for required constructor parameter a",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -368,15 +369,16 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Foo(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
).apply {
|
||||
kaptArgs[OPTION_GENERATED] = "javax.annotation.GeneratedBlerg"
|
||||
}.compile()
|
||||
assertThat(result.messages).contains(
|
||||
"Invalid option value for $OPTION_GENERATED"
|
||||
"Invalid option value for $OPTION_GENERATED",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun disableProguardRulesGenerating() {
|
||||
val result = prepareCompilation(
|
||||
@@ -387,8 +389,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Foo(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
).apply {
|
||||
kaptArgs[OPTION_GENERATE_PROGUARD_RULES] = "false"
|
||||
}.compile()
|
||||
@@ -408,8 +410,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class Class2(private var c: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("property a is not visible")
|
||||
@@ -427,8 +429,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ExtendsPlatformClass(var a: Int) : Date()
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.messages).contains("supertype java.util.Date is not a Kotlin type")
|
||||
}
|
||||
@@ -444,8 +446,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ExtendsJavaType(var b: Int) : JavaSuperclass()
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages)
|
||||
@@ -472,8 +474,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ClassWithQualifier(@UpperCase val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
// We instantiate directly so doesn't need to be FIELD
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
@@ -500,8 +502,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ClassWithQualifier(@UpperCase val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("JsonQualifier @UpperCase must have RUNTIME retention")
|
||||
@@ -520,8 +522,8 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Person(val firstName: FirstName, val lastName: LastName, val hairColor: String)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
|
||||
@@ -530,7 +532,7 @@ class JsonClassCodegenProcessorTest {
|
||||
val adapterClass = result.classLoader.loadClass("PersonJsonAdapter").kotlin
|
||||
assertThat(adapterClass.declaredMemberProperties.map { it.returnType }).containsExactly(
|
||||
JsonReader.Options::class.createType(),
|
||||
JsonAdapter::class.parameterizedBy(String::class)
|
||||
JsonAdapter::class.parameterizedBy(String::class),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -648,8 +650,8 @@ class JsonClassCodegenProcessorTest {
|
||||
val arg64: Long = 64,
|
||||
val arg65: Long = 65
|
||||
)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
|
||||
@@ -663,7 +665,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keep class testPackage.AliasesJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.Simple" -> assertThat(generatedFile.readText()).contains(
|
||||
"""
|
||||
@@ -673,7 +675,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keep class testPackage.SimpleJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.Generic" -> assertThat(generatedFile.readText()).contains(
|
||||
"""
|
||||
@@ -683,7 +685,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keep class testPackage.GenericJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi,java.lang.reflect.Type[]);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.UsingQualifiers" -> {
|
||||
assertThat(generatedFile.readText()).contains(
|
||||
@@ -694,7 +696,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keep class testPackage.UsingQualifiersJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
"moshi-testPackage.MixedTypes" -> assertThat(generatedFile.readText()).contains(
|
||||
@@ -705,7 +707,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keep class testPackage.MixedTypesJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.DefaultParams" -> assertThat(generatedFile.readText()).contains(
|
||||
"""
|
||||
@@ -721,7 +723,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keepclassmembers class testPackage.DefaultParams {
|
||||
public synthetic <init>(java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.Complex" -> {
|
||||
assertThat(generatedFile.readText()).contains(
|
||||
@@ -738,7 +740,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keepclassmembers class testPackage.Complex {
|
||||
public synthetic <init>(java.lang.String,java.util.List,java.lang.Object,int,kotlin.jvm.internal.DefaultConstructorMarker);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
"moshi-testPackage.MultipleMasks" -> assertThat(generatedFile.readText()).contains(
|
||||
@@ -755,7 +757,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keepclassmembers class testPackage.MultipleMasks {
|
||||
public synthetic <init>(long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,int,int,int,kotlin.jvm.internal.DefaultConstructorMarker);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.NestedType.NestedSimple" -> {
|
||||
assertThat(generatedFile.readText()).contains(
|
||||
@@ -766,7 +768,7 @@ class JsonClassCodegenProcessorTest {
|
||||
-keep class testPackage.NestedType_NestedSimpleJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
else -> error("Unexpected proguard file! ${generatedFile.name}")
|
||||
@@ -795,7 +797,7 @@ class JsonClassCodegenProcessorTest {
|
||||
|
||||
private fun KClassifier.parameterizedBy(vararg types: KType): KType {
|
||||
return createType(
|
||||
types.map { it.asProjection() }
|
||||
types.map { it.asProjection() },
|
||||
)
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,8 @@ import org.junit.rules.TemporaryFolder
|
||||
/** Execute kotlinc to confirm that either files are generated or errors are printed. */
|
||||
class JsonClassSymbolProcessorTest {
|
||||
|
||||
@Rule @JvmField val temporaryFolder: TemporaryFolder = TemporaryFolder()
|
||||
@Rule @JvmField
|
||||
val temporaryFolder: TemporaryFolder = TemporaryFolder()
|
||||
|
||||
@Test
|
||||
fun privateConstructor() {
|
||||
@@ -53,8 +54,8 @@ class JsonClassSymbolProcessorTest {
|
||||
fun newInstance(a: Int, b: Int) = PrivateConstructor(a, b)
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("constructor is not internal or public")
|
||||
@@ -71,8 +72,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class PrivateConstructorParameter(private var a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("property a is not visible")
|
||||
@@ -92,8 +93,8 @@ class JsonClassSymbolProcessorTest {
|
||||
private var a: Int = -1
|
||||
private var b: Int = -1
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("property a is not visible")
|
||||
@@ -110,12 +111,12 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
interface Interface
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to test.Interface: must be a Kotlin class"
|
||||
"@JsonClass can't be applied to test.Interface: must be a Kotlin class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -130,8 +131,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true, generator="customGenerator")
|
||||
interface Interface
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
}
|
||||
@@ -147,12 +148,12 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
abstract class AbstractClass(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to test.AbstractClass: must not be abstract"
|
||||
"@JsonClass can't be applied to test.AbstractClass: must not be abstract",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -167,12 +168,12 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
sealed class SealedClass(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to test.SealedClass: must not be sealed"
|
||||
"@JsonClass can't be applied to test.SealedClass: must not be sealed",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -189,12 +190,12 @@ class JsonClassSymbolProcessorTest {
|
||||
@JsonClass(generateAdapter = true)
|
||||
inner class InnerClass(val a: Int)
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to test.Outer.InnerClass: must not be an inner class"
|
||||
"@JsonClass can't be applied to test.Outer.InnerClass: must not be an inner class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -211,12 +212,12 @@ class JsonClassSymbolProcessorTest {
|
||||
enum class KotlinEnum {
|
||||
A, B
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass with 'generateAdapter = \"true\"' can't be applied to test.KotlinEnum: code gen for enums is not supported or necessary"
|
||||
"@JsonClass with 'generateAdapter = \"true\"' can't be applied to test.KotlinEnum: code gen for enums is not supported or necessary",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -235,12 +236,12 @@ class JsonClassSymbolProcessorTest {
|
||||
@JsonClass(generateAdapter = true)
|
||||
class LocalClass(val a: Int)
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to LocalClass: must not be local"
|
||||
"@JsonClass can't be applied to LocalClass: must not be local",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -255,12 +256,12 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
private class PrivateClass(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to test.PrivateClass: must be internal or public"
|
||||
"@JsonClass can't be applied to test.PrivateClass: must be internal or public",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -277,12 +278,12 @@ class JsonClassSymbolProcessorTest {
|
||||
object ObjectDeclaration {
|
||||
var a = 5
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to test.ObjectDeclaration: must be a Kotlin class"
|
||||
"@JsonClass can't be applied to test.ObjectDeclaration: must be a Kotlin class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -299,12 +300,12 @@ class JsonClassSymbolProcessorTest {
|
||||
val expression = object : Any() {
|
||||
var a = 5
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"@JsonClass can't be applied to test.expression: must be a Kotlin class"
|
||||
"@JsonClass can't be applied to test.expression: must be a Kotlin class",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -319,12 +320,12 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class RequiredTransientConstructorParameter(@Transient var a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"No default value for transient/ignored property a"
|
||||
"No default value for transient/ignored property a",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -340,12 +341,12 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class RequiredTransientConstructorParameter(@Json(ignore = true) var a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"No default value for transient/ignored property a"
|
||||
"No default value for transient/ignored property a",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -360,12 +361,12 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class NonPropertyConstructorParameter(a: Int, val b: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains(
|
||||
"No property for required constructor parameter a"
|
||||
"No property for required constructor parameter a",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -380,13 +381,13 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Foo(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
).apply {
|
||||
kspArgs[OPTION_GENERATED] = "javax.annotation.GeneratedBlerg"
|
||||
}.compile()
|
||||
assertThat(result.messages).contains(
|
||||
"Invalid option value for $OPTION_GENERATED"
|
||||
"Invalid option value for $OPTION_GENERATED",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -401,8 +402,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Foo(val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
).apply {
|
||||
kspArgs[OPTION_GENERATE_PROGUARD_RULES] = "false"
|
||||
}
|
||||
@@ -425,8 +426,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class Class2(private var c: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("property a is not visible")
|
||||
@@ -445,8 +446,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ExtendsPlatformClass(var a: Int) : Date()
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.messages).contains("supertype java.util.Date is not a Kotlin type")
|
||||
}
|
||||
@@ -463,7 +464,7 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ExtendsJavaType(var b: Int) : JavaSuperclass()
|
||||
"""
|
||||
""",
|
||||
),
|
||||
java(
|
||||
"JavaSuperclass.java",
|
||||
@@ -472,8 +473,8 @@ class JsonClassSymbolProcessorTest {
|
||||
public class JavaSuperclass {
|
||||
public int a = 1;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages)
|
||||
@@ -501,8 +502,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ClassWithQualifier(@UpperCase val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
// We instantiate directly, no FIELD site target necessary
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
@@ -530,8 +531,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class ClassWithQualifier(@UpperCase val a: Int)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
|
||||
assertThat(result.messages).contains("JsonQualifier @UpperCase must have RUNTIME retention")
|
||||
@@ -551,8 +552,8 @@ class JsonClassSymbolProcessorTest {
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Person(val firstName: FirstName, val lastName: LastName, val hairColor: String)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
|
||||
@@ -680,8 +681,8 @@ class JsonClassSymbolProcessorTest {
|
||||
val arg64: Long = 64,
|
||||
val arg65: Long = 65
|
||||
)
|
||||
"""
|
||||
)
|
||||
""",
|
||||
),
|
||||
)
|
||||
val result = compilation.compile()
|
||||
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)
|
||||
@@ -696,7 +697,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keep class testPackage.AliasesJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.Simple" -> assertThat(generatedFile.readText()).contains(
|
||||
"""
|
||||
@@ -706,7 +707,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keep class testPackage.SimpleJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.Generic" -> assertThat(generatedFile.readText()).contains(
|
||||
"""
|
||||
@@ -716,7 +717,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keep class testPackage.GenericJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi,java.lang.reflect.Type[]);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.UsingQualifiers" -> {
|
||||
assertThat(generatedFile.readText()).contains(
|
||||
@@ -727,7 +728,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keep class testPackage.UsingQualifiersJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
"moshi-testPackage.MixedTypes" -> assertThat(generatedFile.readText()).contains(
|
||||
@@ -738,7 +739,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keep class testPackage.MixedTypesJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.DefaultParams" -> assertThat(generatedFile.readText()).contains(
|
||||
"""
|
||||
@@ -754,7 +755,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keepclassmembers class testPackage.DefaultParams {
|
||||
public synthetic <init>(java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.Complex" -> {
|
||||
assertThat(generatedFile.readText()).contains(
|
||||
@@ -771,7 +772,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keepclassmembers class testPackage.Complex {
|
||||
public synthetic <init>(java.lang.String,java.util.List,java.lang.Object,int,kotlin.jvm.internal.DefaultConstructorMarker);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
"moshi-testPackage.MultipleMasks" -> assertThat(generatedFile.readText()).contains(
|
||||
@@ -788,7 +789,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keepclassmembers class testPackage.MultipleMasks {
|
||||
public synthetic <init>(long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,long,int,int,int,kotlin.jvm.internal.DefaultConstructorMarker);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
"moshi-testPackage.NestedType.NestedSimple" -> {
|
||||
assertThat(generatedFile.readText()).contains(
|
||||
@@ -799,7 +800,7 @@ class JsonClassSymbolProcessorTest {
|
||||
-keep class testPackage.NestedType_NestedSimpleJsonAdapter {
|
||||
public <init>(com.squareup.moshi.Moshi);
|
||||
}
|
||||
""".trimIndent()
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
else -> error("Unexpected proguard file! ${generatedFile.name}")
|
||||
|
Reference in New Issue
Block a user