diff options
author | renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> | 2022-07-21 16:38:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-21 16:38:37 -0400 |
commit | a1163dafc72e5724c947c07a3bd006f6baba695d (patch) | |
tree | 042ffda7446c414a6f388d6f3b48d2cc7f403128 /interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet | |
parent | fa73840b97028731291d2d93206d7ebf3642ff3d (diff) | |
download | kotlinpoet-a1163dafc72e5724c947c07a3bd006f6baba695d.tar.gz |
Update plugin spotless to v6.8.0 (#1302)
* Update plugin spotless to v6.8.0
* ktlint 0.46.1
* Fix violations
* Fix violations
* Disable rule that breaks API compat + revert changes
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Egor Andreevici <egor@squareup.com>
Diffstat (limited to 'interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet')
17 files changed, 223 insertions, 139 deletions
diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/flags.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/Flags.kt index 78b0cc98..4745dda0 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/flags.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/Flags.kt @@ -30,142 +30,203 @@ import kotlinx.metadata.KmValueParameter // Common flags for any element with flags. @KotlinPoetMetadataPreview public val Flags.hasAnnotations: Boolean get() = Flag.HAS_ANNOTATIONS(this) + @KotlinPoetMetadataPreview public val Flags.isAbstract: Boolean get() = Flag.IS_ABSTRACT(this) + @KotlinPoetMetadataPreview public val Flags.isFinal: Boolean get() = Flag.IS_FINAL(this) + @KotlinPoetMetadataPreview public val Flags.isInternal: Boolean get() = Flag.IS_INTERNAL(this) + @KotlinPoetMetadataPreview public val Flags.isLocal: Boolean get() = Flag.IS_LOCAL(this) + @KotlinPoetMetadataPreview public val Flags.isOpen: Boolean get() = Flag.IS_OPEN(this) + @KotlinPoetMetadataPreview public val Flags.isPrivate: Boolean get() = Flag.IS_PRIVATE(this) + @KotlinPoetMetadataPreview public val Flags.isPrivate_to_this: Boolean get() = Flag.IS_PRIVATE_TO_THIS(this) + @KotlinPoetMetadataPreview public val Flags.isProtected: Boolean get() = Flag.IS_PROTECTED(this) + @KotlinPoetMetadataPreview public val Flags.isPublic: Boolean get() = Flag.IS_PUBLIC(this) + @KotlinPoetMetadataPreview public val Flags.isSealed: Boolean get() = Flag.IS_SEALED(this) // Type flags. @KotlinPoetMetadataPreview public val Flags.isNullableType: Boolean get() = Flag.Type.IS_NULLABLE(this) + @KotlinPoetMetadataPreview public val Flags.isSuspendType: Boolean get() = Flag.Type.IS_SUSPEND(this) // Class flags. @KotlinPoetMetadataPreview public val Flags.isAnnotationClass: Boolean get() = Flag.Class.IS_ANNOTATION_CLASS(this) + @KotlinPoetMetadataPreview public val Flags.isClass: Boolean get() = Flag.Class.IS_CLASS(this) + @KotlinPoetMetadataPreview public val Flags.isCompanionObjectClass: Boolean get() = Flag.Class.IS_COMPANION_OBJECT(this) + @KotlinPoetMetadataPreview public val Flags.isDataClass: Boolean get() = Flag.Class.IS_DATA(this) + @KotlinPoetMetadataPreview public val Flags.isEnumClass: Boolean get() = Flag.Class.IS_ENUM_CLASS(this) + @KotlinPoetMetadataPreview public val Flags.isEnumEntryClass: Boolean get() = Flag.Class.IS_ENUM_ENTRY(this) + @KotlinPoetMetadataPreview public val Flags.isExpectClass: Boolean get() = Flag.Class.IS_EXPECT(this) + @KotlinPoetMetadataPreview public val Flags.isExternalClass: Boolean get() = Flag.Class.IS_EXTERNAL(this) + @KotlinPoetMetadataPreview public val Flags.isValueClass: Boolean get() = Flag.Class.IS_VALUE(this) + @KotlinPoetMetadataPreview public val Flags.isInnerClass: Boolean get() = Flag.Class.IS_INNER(this) + @KotlinPoetMetadataPreview public val Flags.isObjectClass: Boolean get() = Flag.Class.IS_OBJECT(this) + @KotlinPoetMetadataPreview public val Flags.isInterface: Boolean get() = Flag.Class.IS_INTERFACE(this) + @KotlinPoetMetadataPreview public val Flags.isFun: Boolean get() = Flag.Class.IS_FUN(this) + @KotlinPoetMetadataPreview public val KmClass.isAnnotation: Boolean get() = flags.isAnnotationClass + @KotlinPoetMetadataPreview public val KmClass.isClass: Boolean get() = flags.isClass + @KotlinPoetMetadataPreview public val KmClass.isCompanionObject: Boolean get() = flags.isCompanionObjectClass + @KotlinPoetMetadataPreview public val KmClass.isData: Boolean get() = flags.isDataClass + @KotlinPoetMetadataPreview public val KmClass.isEnum: Boolean get() = flags.isEnumClass + @KotlinPoetMetadataPreview public val KmClass.isEnumEntry: Boolean get() = flags.isEnumEntryClass + @KotlinPoetMetadataPreview public val KmClass.isExpect: Boolean get() = flags.isExpectClass + @KotlinPoetMetadataPreview public val KmClass.isExternal: Boolean get() = flags.isExternalClass + @KotlinPoetMetadataPreview public val KmClass.isValue: Boolean get() = flags.isValueClass + @KotlinPoetMetadataPreview public val KmClass.isInner: Boolean get() = flags.isInnerClass + @KotlinPoetMetadataPreview public val KmClass.isObject: Boolean get() = flags.isObjectClass + @KotlinPoetMetadataPreview public val KmClass.isInterface: Boolean get() = flags.isInterface + @KotlinPoetMetadataPreview public val KmClass.isFun: Boolean get() = flags.isFun + @KotlinPoetMetadataPreview public val KmType.isSuspend: Boolean get() = flags.isSuspendType + @KotlinPoetMetadataPreview public val KmType.isNullable: Boolean get() = flags.isNullableType // Constructor flags. @KotlinPoetMetadataPreview public val Flags.isPrimaryConstructor: Boolean get() = !Flag.Constructor.IS_SECONDARY(this) + @KotlinPoetMetadataPreview public val KmConstructor.isPrimary: Boolean get() = flags.isPrimaryConstructor + @KotlinPoetMetadataPreview public val KmConstructor.isSecondary: Boolean get() = !isPrimary // Function flags. @KotlinPoetMetadataPreview public val Flags.isDeclarationFunction: Boolean get() = Flag.Function.IS_DECLARATION(this) + @KotlinPoetMetadataPreview public val Flags.isFakeOverrideFunction: Boolean get() = Flag.Function.IS_FAKE_OVERRIDE(this) + @KotlinPoetMetadataPreview public val Flags.isDelegationFunction: Boolean get() = Flag.Function.IS_DELEGATION(this) + @KotlinPoetMetadataPreview public val Flags.isSynthesizedFunction: Boolean get() = Flag.Function.IS_SYNTHESIZED(this) + @KotlinPoetMetadataPreview public val Flags.isOperatorFunction: Boolean get() = Flag.Function.IS_OPERATOR(this) + @KotlinPoetMetadataPreview public val Flags.isInfixFunction: Boolean get() = Flag.Function.IS_INFIX(this) + @KotlinPoetMetadataPreview public val Flags.isInlineFunction: Boolean get() = Flag.Function.IS_INLINE(this) + @KotlinPoetMetadataPreview public val Flags.isTailRecFunction: Boolean get() = Flag.Function.IS_TAILREC(this) + @KotlinPoetMetadataPreview public val Flags.isExternalFunction: Boolean get() = Flag.Function.IS_EXTERNAL(this) + @KotlinPoetMetadataPreview public val Flags.isSuspendFunction: Boolean get() = Flag.Function.IS_SUSPEND(this) + @KotlinPoetMetadataPreview public val Flags.isExpectFunction: Boolean get() = Flag.Function.IS_EXPECT(this) + @KotlinPoetMetadataPreview public val KmFunction.isDeclaration: Boolean get() = flags.isDeclarationFunction + @KotlinPoetMetadataPreview public val KmFunction.isFakeOverride: Boolean get() = flags.isFakeOverrideFunction + @KotlinPoetMetadataPreview public val KmFunction.isDelegation: Boolean get() = flags.isDelegationFunction + @KotlinPoetMetadataPreview public val KmFunction.isSynthesized: Boolean get() = flags.isSynthesizedFunction + @KotlinPoetMetadataPreview public val KmFunction.isOperator: Boolean get() = flags.isOperatorFunction + @KotlinPoetMetadataPreview public val KmFunction.isInfix: Boolean get() = flags.isInfixFunction + @KotlinPoetMetadataPreview public val KmFunction.isInline: Boolean get() = flags.isInlineFunction + @KotlinPoetMetadataPreview public val KmFunction.isTailRec: Boolean get() = flags.isTailRecFunction + @KotlinPoetMetadataPreview public val KmFunction.isExternal: Boolean get() = flags.isExternalFunction + @KotlinPoetMetadataPreview public val KmFunction.isSuspend: Boolean get() = flags.isSuspendFunction + @KotlinPoetMetadataPreview public val KmFunction.isExpect: Boolean get() = flags.isExpectFunction @@ -173,40 +234,56 @@ public val KmFunction.isExpect: Boolean get() = flags.isExpectFunction @KotlinPoetMetadataPreview public val KmValueParameter.declaresDefaultValue: Boolean get() = Flag.ValueParameter.DECLARES_DEFAULT_VALUE(flags) + @KotlinPoetMetadataPreview public val KmValueParameter.isCrossInline: Boolean get() = Flag.ValueParameter.IS_CROSSINLINE(flags) + @KotlinPoetMetadataPreview public val KmValueParameter.isNoInline: Boolean get() = Flag.ValueParameter.IS_NOINLINE(flags) // Property flags. @KotlinPoetMetadataPreview public val Flags.isFakeOverrideProperty: Boolean get() = Flag.Property.IS_FAKE_OVERRIDE(this) + @KotlinPoetMetadataPreview public val KmProperty.hasConstant: Boolean get() = Flag.Property.HAS_CONSTANT(flags) + @KotlinPoetMetadataPreview public val KmProperty.hasGetter: Boolean get() = Flag.Property.HAS_GETTER(flags) + @KotlinPoetMetadataPreview public val KmProperty.hasSetter: Boolean get() = Flag.Property.HAS_SETTER(flags) + @KotlinPoetMetadataPreview public val KmProperty.isConst: Boolean get() = Flag.Property.IS_CONST(flags) + @KotlinPoetMetadataPreview public val KmProperty.isDeclaration: Boolean get() = Flag.Property.IS_DECLARATION(flags) + @KotlinPoetMetadataPreview public val KmProperty.isDelegated: Boolean get() = Flag.Property.IS_DELEGATED(flags) + @KotlinPoetMetadataPreview public val KmProperty.isDelegation: Boolean get() = Flag.Property.IS_DELEGATION(flags) + @KotlinPoetMetadataPreview public val KmProperty.isExpect: Boolean get() = Flag.Property.IS_EXPECT(flags) + @KotlinPoetMetadataPreview public val KmProperty.isExternal: Boolean get() = Flag.Property.IS_EXTERNAL(flags) + @KotlinPoetMetadataPreview public val KmProperty.isFakeOverride: Boolean get() = flags.isFakeOverrideProperty + @KotlinPoetMetadataPreview public val KmProperty.isLateinit: Boolean get() = Flag.Property.IS_LATEINIT(flags) + @KotlinPoetMetadataPreview public val KmProperty.isSynthesized: Boolean get() = Flag.Property.IS_SYNTHESIZED(flags) + @KotlinPoetMetadataPreview public val KmProperty.isVar: Boolean get() = Flag.Property.IS_VAR(flags) + @KotlinPoetMetadataPreview public val KmProperty.isVal: Boolean get() = !isVar @@ -214,9 +291,11 @@ public val KmProperty.isVal: Boolean get() = !isVar @KotlinPoetMetadataPreview public val Flags.isPropertyAccessorExternal: Boolean get() = Flag.PropertyAccessor.IS_EXTERNAL(this) + @KotlinPoetMetadataPreview public val Flags.isPropertyAccessorInline: Boolean get() = Flag.PropertyAccessor.IS_INLINE(this) + @KotlinPoetMetadataPreview public val Flags.isPropertyAccessorNotDefault: Boolean get() = Flag.PropertyAccessor.IS_NOT_DEFAULT(this) diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/KotlinPoetMetadata.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/KotlinPoetMetadata.kt index d1223e71..6cb3c91d 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/KotlinPoetMetadata.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/KotlinPoetMetadata.kt @@ -107,6 +107,6 @@ private fun Metadata.asClassHeader(): KotlinClassHeader { data2 = data2, extraString = extraString, packageName = packageName, - extraInt = extraInt + extraInt = extraInt, ) } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ClassInspectorUtil.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ClassInspectorUtil.kt index a1e739b5..d9caa834 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ClassInspectorUtil.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ClassInspectorUtil.kt @@ -60,7 +60,7 @@ internal object ClassInspectorUtil { private val IMPLICIT_FIELD_ANNOTATIONS = setOf( JVM_FIELD, JVM_TRANSIENT, - JVM_VOLATILE + JVM_VOLATILE, ) private val NOT_NULL = NotNull::class.asClassName() private val NULLABLE = Nullable::class.asClassName() @@ -68,7 +68,7 @@ internal object ClassInspectorUtil { private val KOTLIN_INTRINSIC_ANNOTATIONS = setOf( NOT_NULL, NULLABLE, - EXTENSION_FUNCTION_TYPE + EXTENSION_FUNCTION_TYPE, ) val KOTLIN_INTRINSIC_INTERFACES: Set<ClassName> = setOf( @@ -85,16 +85,16 @@ internal object ClassInspectorUtil { MUTABLE_LIST, MUTABLE_SET, MUTABLE_MAP, - MUTABLE_MAP_ENTRY + MUTABLE_MAP_ENTRY, ) private val KOTLIN_NULLABILITY_ANNOTATIONS = setOf( "org.jetbrains.annotations.NotNull", - "org.jetbrains.annotations.Nullable" + "org.jetbrains.annotations.Nullable", ) fun filterOutNullabilityAnnotations( - annotations: List<AnnotationSpec> + annotations: List<AnnotationSpec>, ): List<AnnotationSpec> { return annotations.filterNot { val typeName = it.typeName @@ -123,7 +123,7 @@ internal object ClassInspectorUtil { isCompanionObject: Boolean, hasGetter: Boolean, hasSetter: Boolean, - hasField: Boolean + hasField: Boolean, ): Boolean { return if (!hasGetter && !hasSetter && @@ -142,7 +142,7 @@ internal object ClassInspectorUtil { */ fun createAnnotations( siteTarget: UseSiteTarget? = null, - body: MutableCollection<AnnotationSpec>.() -> Unit + body: MutableCollection<AnnotationSpec>.() -> Unit, ): Collection<AnnotationSpec> { val result = mutableSetOf<AnnotationSpec>() .apply(body) @@ -173,13 +173,13 @@ internal object ClassInspectorUtil { */ fun createThrowsSpec( exceptions: Collection<TypeName>, - useSiteTarget: UseSiteTarget? = null + useSiteTarget: UseSiteTarget? = null, ): AnnotationSpec { return AnnotationSpec.builder(Throws::class) .addMember( "exceptionClasses = %L", exceptions.map { CodeBlock.of("%T::class", it) } - .joinToCode(prefix = "[", suffix = "]") + .joinToCode(prefix = "[", suffix = "]"), ) .useSiteTarget(useSiteTarget) .build() @@ -202,11 +202,11 @@ internal object ClassInspectorUtil { // Nested A: package/of/class/MyClass.NestedClass val simpleName = kotlinMetadataName.substringAfterLast( '/', // Drop the package name, e.g. "package/of/class/" - '.' // Drop any enclosing classes, e.g. "MyClass." + '.', // Drop any enclosing classes, e.g. "MyClass." ) val packageName = kotlinMetadataName.substringBeforeLast( delimiter = "/", - missingDelimiterValue = "" + missingDelimiterValue = "", ) val simpleNames = kotlinMetadataName.removeSuffix(simpleName) .removeSuffix(".") // Trailing "." if any @@ -224,7 +224,7 @@ internal object ClassInspectorUtil { return ClassName( packageName = packageName.replace("/", "."), - simpleNames = simpleNames + simpleNames = simpleNames, ) } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ElementsClassInspector.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ElementsClassInspector.kt index 9a3a9a28..d4f77860 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ElementsClassInspector.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ElementsClassInspector.kt @@ -93,7 +93,7 @@ private typealias ElementsModifier = javax.lang.model.element.Modifier @KotlinPoetMetadataPreview public class ElementsClassInspector private constructor( private val elements: Elements, - private val types: Types + private val types: Types, ) : ClassInspector { private val typeElementCache = ConcurrentHashMap<ClassName, Optional<TypeElement>>() private val methodCache = ConcurrentHashMap<Pair<TypeElement, String>, Optional<ExecutableElement>>() @@ -140,14 +140,14 @@ public class ElementsClassInspector private constructor( private fun lookupMethod( className: ClassName, methodSignature: JvmMethodSignature, - elementFilter: (Iterable<Element>) -> List<ExecutableElement> + elementFilter: (Iterable<Element>) -> List<ExecutableElement>, ): ExecutableElement? { return lookupTypeElement(className)?.lookupMethod(methodSignature, elementFilter) } private fun TypeElement.lookupMethod( methodSignature: JvmMethodSignature, - elementFilter: (Iterable<Element>) -> List<ExecutableElement> + elementFilter: (Iterable<Element>) -> List<ExecutableElement>, ): ExecutableElement? { val signatureString = methodSignature.asString() return methodCache.getOrPut(this to signatureString) { @@ -170,7 +170,7 @@ public class ElementsClassInspector private constructor( private fun VariableElement.annotationSpecs(): List<AnnotationSpec> { @Suppress("DEPRECATION") return filterOutNullabilityAnnotations( - annotationMirrors.map { AnnotationSpec.get(it) } + annotationMirrors.map { AnnotationSpec.get(it) }, ) } @@ -188,7 +188,7 @@ public class ElementsClassInspector private constructor( private fun ExecutableElement.annotationSpecs(): List<AnnotationSpec> { @Suppress("DEPRECATION") return filterOutNullabilityAnnotations( - annotationMirrors.map { AnnotationSpec.get(it) } + annotationMirrors.map { AnnotationSpec.get(it) }, ) } @@ -215,7 +215,7 @@ public class ElementsClassInspector private constructor( return EnumEntryData( declarationContainer = declarationContainer, - annotations = entry.annotationSpecs() + annotations = entry.annotationSpecs(), ) } @@ -270,7 +270,7 @@ public class ElementsClassInspector private constructor( */ private fun TypeElement.getAllMethods( pkg: PackageElement, - methodsAccumulator: SetMultimap<String, ExecutableElement> + methodsAccumulator: SetMultimap<String, ExecutableElement>, ) { for (superInterface in interfaces) { MoreTypes.asTypeElement(superInterface).getAllMethods(pkg, methodsAccumulator) @@ -306,7 +306,7 @@ public class ElementsClassInspector private constructor( override fun containerData( declarationContainer: KmDeclarationContainer, className: ClassName, - parentClassName: ClassName? + parentClassName: ClassName?, ): ContainerData { val typeElement: TypeElement = lookupTypeElement(className) ?: error("No class found for: $className.") val isCompanionObject = when (declarationContainer) { @@ -340,7 +340,7 @@ public class ElementsClassInspector private constructor( isCompanionObject = isCompanionObject, hasGetter = property.getterSignature != null, hasSetter = property.setterSignature != null, - hasField = property.fieldSignature != null + hasField = property.fieldSignature != null, ) val fieldData = property.fieldSignature?.let fieldDataLet@{ fieldSignature -> @@ -387,7 +387,7 @@ public class ElementsClassInspector private constructor( // JvmField companion objects don't need JvmStatic, it's implicit isCompanionObject && isJvmField && it == JvmFieldModifier.STATIC }, - constant = constant + constant = constant, ) } @@ -398,7 +398,7 @@ public class ElementsClassInspector private constructor( hasAnnotations = property.getterFlags.hasAnnotations, jvmInformationMethod = classIfCompanion.takeIf { it != typeElement } ?.lookupMethod(getterSignature, ElementFilter::methodsIn) - ?: method + ?: method, ) ?: return@let MethodData.SYNTHETIC } @@ -411,7 +411,7 @@ public class ElementsClassInspector private constructor( jvmInformationMethod = classIfCompanion.takeIf { it != typeElement } ?.lookupMethod(setterSignature, ElementFilter::methodsIn) ?: method, - knownIsOverride = getterData?.isOverride + knownIsOverride = getterData?.isOverride, ) ?: return@let MethodData.SYNTHETIC } @@ -435,10 +435,10 @@ public class ElementsClassInspector private constructor( if (isCompanionObject && JvmFieldModifier.STATIC in modifiers) { finalFieldData = fieldData.copy( jvmModifiers = fieldData.jvmModifiers - .filterNotTo(LinkedHashSet()) { it == JvmFieldModifier.STATIC } + .filterNotTo(LinkedHashSet()) { it == JvmFieldModifier.STATIC }, ) annotations += AnnotationSpec.builder( - JVM_STATIC + JVM_STATIC, ).build() } } @@ -448,7 +448,7 @@ public class ElementsClassInspector private constructor( fieldData = finalFieldData, getterData = getterData, setterData = setterData, - isJvmField = isJvmField + isJvmField = isJvmField, ) } @@ -462,7 +462,7 @@ public class ElementsClassInspector private constructor( hasAnnotations = kmFunction.flags.hasAnnotations, jvmInformationMethod = classIfCompanion.takeIf { it != typeElement } ?.lookupMethod(signature, ElementFilter::methodsIn) - ?: method + ?: method, ) ?: return@associateWithTo MethodData.SYNTHETIC } else { @@ -496,7 +496,7 @@ public class ElementsClassInspector private constructor( parameterAnnotations = constructor.parameters.indexedAnnotationSpecs(), isSynthetic = false, jvmModifiers = constructor.jvmModifiers(), - exceptions = constructor.exceptionTypeNames() + exceptions = constructor.exceptionTypeNames(), ) } else { ConstructorData.EMPTY @@ -515,7 +515,7 @@ public class ElementsClassInspector private constructor( }, properties = propertyData, constructors = constructorData, - methods = methodData + methods = methodData, ) } is KmPackage -> { @@ -534,7 +534,7 @@ public class ElementsClassInspector private constructor( } @Suppress("DEPRECATION") AnnotationSpec.get(it) - } + }, ) } return FileData( @@ -543,7 +543,7 @@ public class ElementsClassInspector private constructor( properties = propertyData, methods = methodData, className = className, - jvmName = jvmName + jvmName = jvmName, ) } else -> TODO("Not implemented yet: ${declarationContainer.javaClass.simpleName}") @@ -560,7 +560,7 @@ public class ElementsClassInspector private constructor( typeElement: TypeElement, hasAnnotations: Boolean, jvmInformationMethod: ExecutableElement = this, - knownIsOverride: Boolean? = null + knownIsOverride: Boolean? = null, ): MethodData { return MethodData( annotations = if (hasAnnotations) annotationSpecs() else emptyList(), @@ -568,7 +568,7 @@ public class ElementsClassInspector private constructor( isSynthetic = false, jvmModifiers = jvmInformationMethod.jvmModifiers(), isOverride = knownIsOverride ?: isOverriddenIn(typeElement), - exceptions = exceptionTypeNames() + exceptions = exceptionTypeNames(), ) } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/JvmDescriptorUtils.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/JvmDescriptorUtils.kt index 41717abc..235e5e87 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/JvmDescriptorUtils.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/JvmDescriptorUtils.kt @@ -182,10 +182,12 @@ internal object JvmDescriptorTypeVisitor : AbstractTypeVisitor6<String, Types>() override fun visitTypeVariable(t: TypeVariable, types: Types): String = t.descriptor(types) override fun visitNull(t: NullType, types: Types): String = visitUnknown( - t, types + t, + types, ) override fun visitError(t: ErrorType, types: Types): String = visitUnknown( - t, types + t, + types, ) override fun visitUnknown(t: TypeMirror, types: Types): String = error("Unsupported type $t") diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/Optional.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/Optional.kt index 09c3e6fd..41935e36 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/Optional.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/Optional.kt @@ -21,5 +21,5 @@ package com.squareup.kotlinpoet.metadata.classinspectors internal data class Optional<out T : Any>(val nullableValue: T?) internal fun <T : Any> T?.toOptional(): Optional<T> = Optional( - this + this, ) diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ReflectiveClassInspector.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ReflectiveClassInspector.kt index 03c75913..fc31ba09 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ReflectiveClassInspector.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/classinspectors/ReflectiveClassInspector.kt @@ -75,7 +75,7 @@ import kotlinx.metadata.jvm.syntheticMethodForAnnotations @KotlinPoetMetadataPreview public class ReflectiveClassInspector private constructor( - private val classLoader: ClassLoader? + private val classLoader: ClassLoader?, ) : ClassInspector { private val classCache = ConcurrentHashMap<ClassName, Optional<Class<*>>>() @@ -134,7 +134,7 @@ public class ReflectiveClassInspector private constructor( } private fun Class<*>.lookupMethod( - methodSignature: JvmMethodSignature + methodSignature: JvmMethodSignature, ): Method? { val signatureString = methodSignature.asString() return methodCache.getOrPut(this to signatureString) { @@ -146,7 +146,7 @@ public class ReflectiveClassInspector private constructor( } private fun Class<*>.lookupConstructor( - constructorSignature: JvmMethodSignature + constructorSignature: JvmMethodSignature, ): Constructor<*>? { val signatureString = constructorSignature.asString() return constructorCache.getOrPut(this to signatureString) { @@ -173,13 +173,13 @@ public class ReflectiveClassInspector private constructor( private fun Field.annotationSpecs(): List<AnnotationSpec> { return filterOutNullabilityAnnotations( - declaredAnnotations.orEmpty().map { AnnotationSpec.get(it, includeDefaultValues = true) } + declaredAnnotations.orEmpty().map { AnnotationSpec.get(it, includeDefaultValues = true) }, ) } private fun Constructor<*>.annotationSpecs(): List<AnnotationSpec> { return filterOutNullabilityAnnotations( - declaredAnnotations.orEmpty().map { AnnotationSpec.get(it, true) } + declaredAnnotations.orEmpty().map { AnnotationSpec.get(it, true) }, ) } @@ -207,13 +207,13 @@ public class ReflectiveClassInspector private constructor( private fun Method.annotationSpecs(): List<AnnotationSpec> { return filterOutNullabilityAnnotations( - declaredAnnotations.orEmpty().map { AnnotationSpec.get(it, includeDefaultValues = true) } + declaredAnnotations.orEmpty().map { AnnotationSpec.get(it, includeDefaultValues = true) }, ) } private fun Parameter.annotationSpecs(): List<AnnotationSpec> { return filterOutNullabilityAnnotations( - declaredAnnotations.map { AnnotationSpec.get(it, includeDefaultValues = true) } + declaredAnnotations.map { AnnotationSpec.get(it, includeDefaultValues = true) }, ) } @@ -249,7 +249,7 @@ public class ReflectiveClassInspector private constructor( } else { enumEntry.javaClass.getAnnotation(Metadata::class.java)?.toKmClass() }, - annotations = clazz.getField(enumEntry.name).annotationSpecs() + annotations = clazz.getField(enumEntry.name).annotationSpecs(), ) } @@ -288,7 +288,7 @@ public class ReflectiveClassInspector private constructor( override fun containerData( declarationContainer: KmDeclarationContainer, className: ClassName, - parentClassName: ClassName? + parentClassName: ClassName?, ): ContainerData { val targetClass = lookupClass(className) ?: error("No class found for: $className.") val isCompanionObject: Boolean = when (declarationContainer) { @@ -322,7 +322,7 @@ public class ReflectiveClassInspector private constructor( isCompanionObject = isCompanionObject, hasGetter = property.getterSignature != null, hasSetter = property.setterSignature != null, - hasField = property.fieldSignature != null + hasField = property.fieldSignature != null, ) val fieldData = property.fieldSignature?.let { fieldSignature -> @@ -378,7 +378,7 @@ public class ReflectiveClassInspector private constructor( // JvmField companion objects don't need JvmStatic, it's implicit isCompanionObject && isJvmField && it == JvmFieldModifier.STATIC }, - constant = constant + constant = constant, ) } @@ -389,7 +389,7 @@ public class ReflectiveClassInspector private constructor( signature = getterSignature, hasAnnotations = property.getterFlags.hasAnnotations, jvmInformationMethod = classIfCompanion.takeIf { it != targetClass } - ?.lookupMethod(getterSignature) ?: method + ?.lookupMethod(getterSignature) ?: method, ) ?: error("No getter method $getterSignature found in $classIfCompanion.") } @@ -402,7 +402,7 @@ public class ReflectiveClassInspector private constructor( hasAnnotations = property.setterFlags.hasAnnotations, jvmInformationMethod = classIfCompanion.takeIf { it != targetClass } ?.lookupMethod(setterSignature) ?: method, - knownIsOverride = getterData?.isOverride + knownIsOverride = getterData?.isOverride, ) ?: error("No setter method $setterSignature found in $classIfCompanion.") } @@ -423,7 +423,7 @@ public class ReflectiveClassInspector private constructor( fieldData = fieldData, getterData = getterData, setterData = setterData, - isJvmField = isJvmField + isJvmField = isJvmField, ) } @@ -437,7 +437,7 @@ public class ReflectiveClassInspector private constructor( signature = signature, hasAnnotations = kmFunction.flags.hasAnnotations, jvmInformationMethod = classIfCompanion.takeIf { it != targetClass }?.lookupMethod(signature) - ?: method + ?: method, ) ?: error("No method $signature found in $targetClass.") } else { @@ -478,7 +478,7 @@ public class ReflectiveClassInspector private constructor( parameterAnnotations = constructor.parameters.indexedAnnotationSpecs(), isSynthetic = constructor.isSynthetic, jvmModifiers = constructor.jvmModifiers(), - exceptions = constructor.exceptionTypeNames() + exceptions = constructor.exceptionTypeNames(), ) } else { ConstructorData.EMPTY @@ -490,7 +490,7 @@ public class ReflectiveClassInspector private constructor( annotations = classAnnotations, properties = propertyData, constructors = constructorData, - methods = methodData + methods = methodData, ) } is KmPackage -> { @@ -507,7 +507,7 @@ public class ReflectiveClassInspector private constructor( annotations = fileAnnotations, properties = propertyData, methods = methodData, - className = className + className = className, ) } else -> TODO("Not implemented yet: ${declarationContainer.javaClass.simpleName}") @@ -525,7 +525,7 @@ public class ReflectiveClassInspector private constructor( signature: JvmMethodSignature, hasAnnotations: Boolean, jvmInformationMethod: Method = this, - knownIsOverride: Boolean? = null + knownIsOverride: Boolean? = null, ): MethodData { return MethodData( annotations = if (hasAnnotations) annotationSpecs() else emptyList(), @@ -533,7 +533,7 @@ public class ReflectiveClassInspector private constructor( isSynthetic = isSynthetic, jvmModifiers = jvmInformationMethod.jvmModifiers(), isOverride = knownIsOverride ?: signature.isOverriddenIn(clazz), - exceptions = exceptionTypeNames() + exceptions = exceptionTypeNames(), ) } @@ -568,7 +568,7 @@ public class ReflectiveClassInspector private constructor( get() = parameterTypes.joinToString( separator = "", prefix = "(", - postfix = ")${returnType.descriptor}" + postfix = ")${returnType.descriptor}", ) { it.descriptor } /** diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ClassInspector.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ClassInspector.kt index c5d3ab3a..14c019fd 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ClassInspector.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ClassInspector.kt @@ -43,7 +43,7 @@ public interface ClassInspector { public fun containerData( declarationContainer: KmDeclarationContainer, className: ClassName, - parentClassName: ClassName? + parentClassName: ClassName?, ): ContainerData /** @@ -94,7 +94,7 @@ public interface ClassInspector { @KotlinPoetMetadataPreview public fun ClassInspector.containerData( className: ClassName, - parentClassName: ClassName? + parentClassName: ClassName?, ): ContainerData { return containerData(declarationContainerFor(className), className, parentClassName) } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ConstructorData.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ConstructorData.kt index 63123ece..01c98390 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ConstructorData.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ConstructorData.kt @@ -36,7 +36,7 @@ public data class ConstructorData( val parameterAnnotations: Map<Int, Collection<AnnotationSpec>>, val isSynthetic: Boolean, val jvmModifiers: Set<JvmMethodModifier>, - val exceptions: List<TypeName> + val exceptions: List<TypeName>, ) { /** @@ -61,7 +61,7 @@ public data class ConstructorData( parameterAnnotations = emptyMap(), isSynthetic = false, jvmModifiers = emptySet(), - exceptions = emptyList() + exceptions = emptyList(), ) } } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ContainerData.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ContainerData.kt index bece1a8b..f1006d01 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ContainerData.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/ContainerData.kt @@ -60,7 +60,7 @@ public data class ClassData( override val annotations: Collection<AnnotationSpec>, override val properties: Map<KmProperty, PropertyData>, val constructors: Map<KmConstructor, ConstructorData>, - override val methods: Map<KmFunction, MethodData> + override val methods: Map<KmFunction, MethodData>, ) : ContainerData /** @@ -80,7 +80,7 @@ public data class FileData( override val methods: Map<KmFunction, MethodData>, val className: ClassName, val jvmName: String? = - if (!className.simpleName.endsWith("Kt")) className.simpleName else null + if (!className.simpleName.endsWith("Kt")) className.simpleName else null, ) : ContainerData { /** @@ -100,5 +100,5 @@ public data class FileData( @KotlinPoetMetadataPreview public data class EnumEntryData( val declarationContainer: KmClass?, - val annotations: Collection<AnnotationSpec> + val annotations: Collection<AnnotationSpec>, ) diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/FieldData.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/FieldData.kt index bcb9ef54..a000ddef 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/FieldData.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/FieldData.kt @@ -36,7 +36,7 @@ public data class FieldData( private val annotations: List<AnnotationSpec>, val isSynthetic: Boolean, val jvmModifiers: Set<JvmFieldModifier>, - val constant: CodeBlock? + val constant: CodeBlock?, ) { /** @@ -44,7 +44,7 @@ public data class FieldData( * and [isSynthetic]. */ val allAnnotations: Collection<AnnotationSpec> = ClassInspectorUtil.createAnnotations( - FIELD + FIELD, ) { addAll(annotations) if (isSynthetic) { @@ -58,7 +58,7 @@ public data class FieldData( annotations = emptyList(), isSynthetic = true, jvmModifiers = emptySet(), - constant = null + constant = null, ) } } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmFieldModifier.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmFieldModifier.kt index c749e8de..37792208 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmFieldModifier.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmFieldModifier.kt @@ -24,17 +24,17 @@ import com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview public enum class JvmFieldModifier : JvmModifier { STATIC { override fun annotationSpec(): AnnotationSpec = AnnotationSpec.builder( - JvmStatic::class.asClassName() + JvmStatic::class.asClassName(), ).build() }, TRANSIENT { override fun annotationSpec(): AnnotationSpec = AnnotationSpec.builder( - Transient::class.asClassName() + Transient::class.asClassName(), ).build() }, VOLATILE { override fun annotationSpec(): AnnotationSpec = AnnotationSpec.builder( - Volatile::class.asClassName() + Volatile::class.asClassName(), ).build() }; } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmMethodModifier.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmMethodModifier.kt index 71a74945..e9e2fe38 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmMethodModifier.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/JvmMethodModifier.kt @@ -24,12 +24,12 @@ import com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview public enum class JvmMethodModifier : JvmModifier { STATIC { override fun annotationSpec(): AnnotationSpec = AnnotationSpec.builder( - JvmStatic::class.asClassName() + JvmStatic::class.asClassName(), ).build() }, SYNCHRONIZED { override fun annotationSpec(): AnnotationSpec = AnnotationSpec.builder( - Synchronized::class.asClassName() + Synchronized::class.asClassName(), ).build() }, DEFAULT diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/kmTypes.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/KmTypes.kt index c556b830..cd12479c 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/kmTypes.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/KmTypes.kt @@ -73,7 +73,7 @@ internal fun KmVariance.toKModifier(): KModifier? { @KotlinPoetMetadataPreview internal fun KmTypeProjection.toTypeName( - typeParamResolver: TypeParameterResolver + typeParamResolver: TypeParameterResolver, ): TypeName { val typename = type?.toTypeName(typeParamResolver) ?: STAR return when (variance) { @@ -91,7 +91,7 @@ internal fun KmTypeProjection.toTypeName( */ @KotlinPoetMetadataPreview internal fun KmType.toTypeName( - typeParamResolver: TypeParameterResolver + typeParamResolver: TypeParameterResolver, ): TypeName { val argumentList = arguments.map { it.toTypeName(typeParamResolver) } val type: TypeName = when (val valClassifier = classifier) { @@ -125,13 +125,13 @@ internal fun KmType.toTypeName( LambdaTypeName.get( receiver = parameters[0], parameters = parameters.drop(1).toTypedArray(), - returnType = returnType + returnType = returnType, ) } else { LambdaTypeName.get( receiver = null, parameters = parameters, - returnType = returnType + returnType = returnType, ) } lambdaType.copy(suspending = isSuspend) @@ -159,20 +159,20 @@ internal fun KmType.toTypeName( // type in tags for reference. val abbreviatedTypeName = it.toTypeName(typeParamResolver) abbreviatedTypeName.copy( - tags = mapOf(TypeAliasTag::class to TypeAliasTag(finalType)) + tags = mapOf(TypeAliasTag::class to TypeAliasTag(finalType)), ) } ?: finalType } @KotlinPoetMetadataPreview internal fun KmTypeParameter.toTypeVariableName( - typeParamResolver: TypeParameterResolver + typeParamResolver: TypeParameterResolver, ): TypeVariableName { val finalVariance = variance.toKModifier() val typeVariableName = TypeVariableName( name = name, bounds = upperBounds.map { it.toTypeName(typeParamResolver) }, - variance = finalVariance + variance = finalVariance, ) val annotations = ClassInspectorUtil.createAnnotations { for (annotation in annotations) { @@ -182,13 +182,13 @@ internal fun KmTypeParameter.toTypeVariableName( return typeVariableName.copy( reified = isReified, tags = mapOf(KmTypeParameter::class to this), - annotations = annotations + annotations = annotations, ) } @KotlinPoetMetadataPreview private fun KmFlexibleTypeUpperBound.toTypeName( - typeParamResolver: TypeParameterResolver + typeParamResolver: TypeParameterResolver, ): TypeName { // TODO tag typeFlexibilityId somehow? return WildcardTypeName.producerOf(type.toTypeName(typeParamResolver)) @@ -209,7 +209,7 @@ internal interface TypeParameterResolver { @KotlinPoetMetadataPreview internal fun List<KmTypeParameter>.toTypeParameterResolver( - fallback: TypeParameterResolver? = null + fallback: TypeParameterResolver? = null, ): TypeParameterResolver { val parametersMap = LinkedHashMap<Int, TypeVariableName>() val typeParamResolver = { id: Int -> diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/KotlinPoetMetadataSpecs.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/KotlinPoetMetadataSpecs.kt index 37163e55..1f9e1af2 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/KotlinPoetMetadataSpecs.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/KotlinPoetMetadataSpecs.kt @@ -136,48 +136,48 @@ import kotlinx.metadata.jvm.signature /** @return a [TypeSpec] ABI representation of this [KClass]. */ @KotlinPoetMetadataPreview public fun KClass<*>.toTypeSpec( - classInspector: ClassInspector? = null + classInspector: ClassInspector? = null, ): TypeSpec = java.toTypeSpec(classInspector) /** @return a [TypeSpec] ABI representation of this [KClass]. */ @KotlinPoetMetadataPreview public fun Class<*>.toTypeSpec( - classInspector: ClassInspector? = null + classInspector: ClassInspector? = null, ): TypeSpec = toKmClass().toTypeSpec(classInspector, asClassName()) /** @return a [TypeSpec] ABI representation of this [TypeElement]. */ @Suppress("DEPRECATION") @KotlinPoetMetadataPreview public fun TypeElement.toTypeSpec( - classInspector: ClassInspector? = null + classInspector: ClassInspector? = null, ): TypeSpec = toKmClass().toTypeSpec(classInspector, asClassName()) /** @return a [FileSpec] ABI representation of this [KClass]. */ @KotlinPoetMetadataPreview public fun KClass<*>.toFileSpec( - classInspector: ClassInspector? = null + classInspector: ClassInspector? = null, ): FileSpec = java.toFileSpec(classInspector) /** @return a [FileSpec] ABI representation of this [KClass]. */ @KotlinPoetMetadataPreview public fun Class<*>.toFileSpec( - classInspector: ClassInspector? = null + classInspector: ClassInspector? = null, ): FileSpec = FileSpec.get(`package`.name, toTypeSpec(classInspector)) /** @return a [FileSpec] ABI representation of this [TypeElement]. */ @KotlinPoetMetadataPreview public fun TypeElement.toFileSpec( - classInspector: ClassInspector? = null + classInspector: ClassInspector? = null, ): FileSpec = FileSpec.get( packageName = packageName, - typeSpec = toTypeSpec(classInspector) + typeSpec = toTypeSpec(classInspector), ) /** @return a [TypeSpec] ABI representation of this [KmClass]. */ @KotlinPoetMetadataPreview public fun KmClass.toTypeSpec( classInspector: ClassInspector?, - className: ClassName = createClassName(name) + className: ClassName = createClassName(name), ): TypeSpec { return toTypeSpec(classInspector, className, null) } @@ -186,11 +186,11 @@ public fun KmClass.toTypeSpec( @KotlinPoetMetadataPreview public fun KmClass.toFileSpec( classInspector: ClassInspector?, - className: ClassName = createClassName(name) + className: ClassName = createClassName(name), ): FileSpec { return FileSpec.get( packageName = className.packageName, - typeSpec = toTypeSpec(classInspector, className) + typeSpec = toTypeSpec(classInspector, className), ) } @@ -198,7 +198,7 @@ public fun KmClass.toFileSpec( @KotlinPoetMetadataPreview public fun KmPackage.toFileSpec( classInspector: ClassInspector?, - className: ClassName + className: ClassName, ): FileSpec { val fileData = classInspector?.containerData(className, null) check(fileData is FileData?) { @@ -212,7 +212,7 @@ public fun KmPackage.toFileSpec( addAnnotation( AnnotationSpec.builder(ClassInspectorUtil.JVM_NAME) .addMember("name = %S", name) - .build() + .build(), ) } val fileAnnotations = createAnnotations(FILE) { @@ -229,8 +229,8 @@ public fun KmPackage.toFileSpec( classInspector = classInspector, containerData = fileData, methodData = methodData, - isInInterface = false - ) + isInInterface = false, + ), ) } for (property in properties) { @@ -240,8 +240,8 @@ public fun KmPackage.toFileSpec( classInspector = classInspector, containerData = fileData, propertyData = propertyData, - isInInterface = false - ) + isInInterface = false, + ), ) } for (alias in typeAliases) { @@ -257,7 +257,7 @@ private const val NOT_IMPLEMENTED = "throw·NotImplementedError(\"Stub!\")" private fun KmClass.toTypeSpec( classInspector: ClassInspector?, className: ClassName, - parentClassName: ClassName? + parentClassName: ClassName?, ): TypeSpec { val classTypeParamsResolver = typeParameters.toTypeParameterResolver() val jvmInternalName = name.jvmInternalName @@ -305,7 +305,7 @@ private fun KmClass.toTypeSpec( } else { TypeSpec.anonymousClassBuilder() .addKdoc( - "No ClassInspector was available during metadata parsing, so this entry may not be reflected accurately if it has a class body." + "No ClassInspector was available during metadata parsing, so this entry may not be reflected accurately if it has a class body.", ) .build() } @@ -319,7 +319,7 @@ private fun KmClass.toTypeSpec( *flags.modalities .filterNot { it == FINAL } // Default .filterNot { isInterface && it == ABSTRACT } // Abstract is a default on interfaces - .toTypedArray() + .toTypedArray(), ) if (isData) { builder.addModifiers(DATA) @@ -355,7 +355,7 @@ private fun KmClass.toTypeSpec( .filterNot { it == superClass } .map { it.toTypeName(classTypeParamsResolver) } .filterNot { it == ANY } - .asIterable() + .asIterable(), ) val primaryConstructorParams = mutableMapOf<String, ParameterSpec>() if (isClass || isAnnotation || isEnum) { @@ -378,7 +378,7 @@ private fun KmClass.toTypeSpec( } .map { (kmConstructor, constructorData) -> kmConstructor.toFunSpec(classTypeParamsResolver, constructorData) - } + }, ) } } @@ -394,10 +394,10 @@ private fun KmClass.toTypeSpec( isConstructorParam = property.name in primaryConstructorParams, classInspector = classInspector, containerData = classData, - propertyData = propertyData + propertyData = propertyData, ) } - .asIterable() + .asIterable(), ) companionObject?.let { objectName -> val companionType = if (classInspector != null) { @@ -407,7 +407,7 @@ private fun KmClass.toTypeSpec( } else { TypeSpec.companionObjectBuilder(companionObjectName(objectName)) .addKdoc( - "No ClassInspector was available during metadata parsing, so this companion object's API/contents may not be reflected accurately." + "No ClassInspector was available during metadata parsing, so this companion object's API/contents may not be reflected accurately.", ) .build() } @@ -433,8 +433,8 @@ private fun KmClass.toTypeSpec( return handler.methodExists( className.nestedClass("DefaultImpls"), signature.copy( - desc = "(L$jvmInternalName;$suffix" - ) + desc = "(L$jvmInternalName;$suffix", + ), ) } } @@ -456,13 +456,13 @@ private fun KmClass.toTypeSpec( if (methodData?.isSynthetic == true) { addKdoc( "Note: Since this is a synthetic function, some JVM information " + - "(annotations, modifiers) may be missing." + "(annotations, modifiers) may be missing.", ) } } .build() } - .asIterable() + .asIterable(), ) for (it in nestedClasses) { @@ -478,7 +478,7 @@ private fun KmClass.toTypeSpec( } else { TypeSpec.classBuilder(it) .addKdoc( - "No ClassInspector was available during metadata parsing, so this nested class's API/contents may not be reflected accurately." + "No ClassInspector was available during metadata parsing, so this nested class's API/contents may not be reflected accurately.", ) .build() } @@ -497,7 +497,7 @@ private fun companionObjectName(name: String): String? { @KotlinPoetMetadataPreview private fun KmConstructor.toFunSpec( typeParamResolver: TypeParameterResolver, - constructorData: ConstructorData? + constructorData: ConstructorData?, ): FunSpec { return FunSpec.constructorBuilder() .apply { @@ -510,9 +510,9 @@ private fun KmConstructor.toFunSpec( constructorData?.takeIf { it != ConstructorData.EMPTY } ?.parameterAnnotations ?.get(index) - .orEmpty() + .orEmpty(), ) - } + }, ) if (!isPrimary) { // TODO How do we know when to add callSuperConstructor()? @@ -535,10 +535,10 @@ private fun KmFunction.toFunSpec( classInspector: ClassInspector? = null, containerData: ContainerData? = null, methodData: MethodData? = null, - isInInterface: Boolean = containerData?.isInterface ?: false + isInInterface: Boolean = containerData?.isInterface ?: false, ): FunSpec { val typeParamsResolver = typeParameters.toTypeParameterResolver( - fallback = classTypeParamsResolver + fallback = classTypeParamsResolver, ) val mutableAnnotations = mutableListOf<AnnotationSpec>() if (classInspector != null && containerData != null) { @@ -567,7 +567,7 @@ private fun KmFunction.toFunSpec( flags.modalities .filterNot { it == FINAL && !isOverride } // Final is the default .filterNot { it == OPEN && isOverride } // Overrides are implicitly open - .filterNot { it == OPEN && isInInterface } // interface methods are implicitly open + .filterNot { it == OPEN && isInInterface }, // interface methods are implicitly open ) if (valueParameters.isNotEmpty()) { addParameters( @@ -575,9 +575,9 @@ private fun KmFunction.toFunSpec( param.toParameterSpec( typeParamsResolver, // This can be empty if the element is synthetic - methodData?.parameterAnnotations?.get(index).orEmpty() + methodData?.parameterAnnotations?.get(index).orEmpty(), ) - } + }, ) } if (typeParameters.isNotEmpty()) { @@ -623,7 +623,7 @@ private fun KmFunction.toFunSpec( @KotlinPoetMetadataPreview private fun KmValueParameter.toParameterSpec( typeParamResolver: TypeParameterResolver, - annotations: Collection<AnnotationSpec> + annotations: Collection<AnnotationSpec>, ): ParameterSpec { val paramType = varargElementType ?: type ?: throw IllegalStateException("No argument type!") return ParameterSpec.builder(name, paramType.toTypeName(typeParamResolver)) @@ -653,7 +653,7 @@ private fun KmProperty.toPropertySpec( classInspector: ClassInspector? = null, containerData: ContainerData? = null, propertyData: PropertyData? = null, - isInInterface: Boolean = containerData?.isInterface ?: false + isInInterface: Boolean = containerData?.isInterface ?: false, ): PropertySpec { val isOverride = propertyData?.isOverride ?: false val returnTypeName = returnType.toTypeName(typeParamResolver) @@ -679,7 +679,7 @@ private fun KmProperty.toPropertySpec( } getterSignature.jvmNameAnnotation( metadataName = expectedMetadataName, - useSiteTarget = UseSiteTarget.GET + useSiteTarget = UseSiteTarget.GET, )?.let { jvmNameAnnotation -> mutableAnnotations += jvmNameAnnotation } @@ -700,7 +700,7 @@ private fun KmProperty.toPropertySpec( // We skip interface types or open/abstract properties because they can't have @JvmName. setterSignature.jvmNameAnnotation( metadataName = "set${name.safeCapitalize(Locale.US)}", - useSiteTarget = UseSiteTarget.SET + useSiteTarget = UseSiteTarget.SET, )?.let { jvmNameAnnotation -> mutableAnnotations += jvmNameAnnotation } @@ -736,7 +736,7 @@ private fun KmProperty.toPropertySpec( .filterNot { it == FINAL && !isOverride } // Final is the default .filterNot { it == OPEN && isOverride } // Overrides are implicitly open .filterNot { it == OPEN && isInInterface } // Interface properties implicitly open - .filterNot { it == ABSTRACT && isInInterface } // Interface properties implicitly abstract + .filterNot { it == ABSTRACT && isInInterface }, // Interface properties implicitly abstract ) if (isOverride) { addModifiers(KModifier.OVERRIDE) @@ -758,7 +758,7 @@ private fun KmProperty.toPropertySpec( if (returnTypeName.isNullable) { delegate( "%T.observable(null) { _, _, _ -> }", - ClassName("kotlin.properties", "Delegates") + ClassName("kotlin.properties", "Delegates"), ) } else { delegate("%T.notNull()", ClassName("kotlin.properties", "Delegates")) // Placeholder @@ -792,8 +792,10 @@ private fun KmProperty.toPropertySpec( val modifierSet = modifiers.toSet() if (hasGetter && !isDelegated && !flags.isAbstract) { propertyAccessor( - modifierSet, getterFlags, - FunSpec.getterBuilder().addStatement(NOT_IMPLEMENTED), isOverride + modifierSet, + getterFlags, + FunSpec.getterBuilder().addStatement(NOT_IMPLEMENTED), + isOverride, )?.let(::getter) } if (hasSetter && !isDelegated && !flags.isAbstract) { @@ -809,7 +811,7 @@ private fun propertyAccessor( propertyModifiers: Set<KModifier>, flags: Flags, functionBuilder: Builder, - isOverride: Boolean + isOverride: Boolean, ): FunSpec? { val visibility = flags.visibility if (visibility == PUBLIC || visibility !in propertyModifiers) { @@ -864,7 +866,7 @@ private fun KmTypeAlias.toTypeAliasSpec(): TypeAliasSpec { private fun JvmMethodSignature.jvmNameAnnotation( metadataName: String, - useSiteTarget: UseSiteTarget? = null + useSiteTarget: UseSiteTarget? = null, ): AnnotationSpec? { return if (name == metadataName) { null @@ -878,7 +880,7 @@ private fun JvmMethodSignature.jvmNameAnnotation( private val JAVA_ANNOTATION_ANNOTATIONS = setOf( java.lang.annotation.Retention::class.asClassName(), - java.lang.annotation.Target::class.asClassName() + java.lang.annotation.Target::class.asClassName(), ) @KotlinPoetMetadataPreview @@ -928,6 +930,7 @@ private inline fun <E> setOf(body: MutableSet<E>.() -> Unit): Set<E> { } private val METADATA = Metadata::class.asClassName() + @Suppress("DEPRECATION") private val JVM_DEFAULT = JvmDefault::class.asClassName() private val JVM_STATIC = JvmStatic::class.asClassName() diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/MethodData.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/MethodData.kt index 81957a6d..7319e9d8 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/MethodData.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/MethodData.kt @@ -39,7 +39,7 @@ public data class MethodData( val isSynthetic: Boolean, val jvmModifiers: Set<JvmMethodModifier>, val isOverride: Boolean, - val exceptions: List<TypeName> + val exceptions: List<TypeName>, ) { /** @@ -53,10 +53,10 @@ public data class MethodData( */ public fun allAnnotations( useSiteTarget: UseSiteTarget? = null, - containsReifiedTypeParameter: Boolean = false + containsReifiedTypeParameter: Boolean = false, ): Collection<AnnotationSpec> { return ClassInspectorUtil.createAnnotations( - useSiteTarget + useSiteTarget, ) { addAll(annotations) if (isSynthetic && !containsReifiedTypeParameter) { @@ -77,7 +77,7 @@ public data class MethodData( isSynthetic = true, jvmModifiers = emptySet(), isOverride = false, - exceptions = emptyList() + exceptions = emptyList(), ) public val EMPTY: MethodData = MethodData( annotations = emptyList(), @@ -85,7 +85,7 @@ public data class MethodData( isSynthetic = false, jvmModifiers = emptySet(), isOverride = false, - exceptions = emptyList() + exceptions = emptyList(), ) } } diff --git a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/PropertyData.kt b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/PropertyData.kt index 38ec2b74..9fc6d3e4 100644 --- a/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/PropertyData.kt +++ b/interop/kotlinx-metadata/src/main/kotlin/com/squareup/kotlinpoet/metadata/specs/PropertyData.kt @@ -37,7 +37,7 @@ public data class PropertyData( val fieldData: FieldData?, val getterData: MethodData?, val setterData: MethodData?, - val isJvmField: Boolean + val isJvmField: Boolean, ) { /** Indicates if this property overrides another from a supertype. */ val isOverride: Boolean = (getterData?.isOverride ?: false) || (setterData?.isOverride ?: false) @@ -79,7 +79,7 @@ public data class PropertyData( addAll(getterAnnotations.values) addAll( setterData?.allAnnotations(SET).orEmpty() - .filterNot { it.typeName in higherScopedAnnotations } + .filterNot { it.typeName in higherScopedAnnotations }, ) if (isJvmField) { add(ClassInspectorUtil.JVM_FIELD_SPEC) |