From 00efbf6fd819ca944d6325e02ae3bae77fc0030e Mon Sep 17 00:00:00 2001 From: Egor Andreevich Date: Tue, 15 Oct 2024 13:01:07 +0200 Subject: [PATCH] Introduce Modifiable interface to standardized modifiers API --- kotlinpoet/api/kotlinpoet.api | 64 ++++++++++--------- .../kotlin/com/squareup/kotlinpoet/FunSpec.kt | 18 ++---- .../com/squareup/kotlinpoet/Modifiable.kt | 49 ++++++++++++++ .../com/squareup/kotlinpoet/ParameterSpec.kt | 19 ++---- .../com/squareup/kotlinpoet/PropertySpec.kt | 18 ++---- .../com/squareup/kotlinpoet/TypeAliasSpec.kt | 23 ++----- .../com/squareup/kotlinpoet/TypeSpec.kt | 14 ++-- 7 files changed, 117 insertions(+), 88 deletions(-) create mode 100644 kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/Modifiable.kt diff --git a/kotlinpoet/api/kotlinpoet.api b/kotlinpoet/api/kotlinpoet.api index eef2b6132b..f811616d14 100644 --- a/kotlinpoet/api/kotlinpoet.api +++ b/kotlinpoet/api/kotlinpoet.api @@ -293,7 +293,7 @@ public final class com/squareup/kotlinpoet/FileSpec$Companion { public static synthetic fun scriptBuilder$default (Lcom/squareup/kotlinpoet/FileSpec$Companion;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/kotlinpoet/FileSpec$Builder; } -public final class com/squareup/kotlinpoet/FunSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/ContextReceivable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/OriginatingElementsHolder, com/squareup/kotlinpoet/Taggable { +public final class com/squareup/kotlinpoet/FunSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/ContextReceivable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/Modifiable, com/squareup/kotlinpoet/OriginatingElementsHolder, com/squareup/kotlinpoet/Taggable { public static final field Companion Lcom/squareup/kotlinpoet/FunSpec$Companion; public static final fun builder (Lcom/squareup/kotlinpoet/MemberName;)Lcom/squareup/kotlinpoet/FunSpec$Builder; public static final fun builder (Ljava/lang/String;)Lcom/squareup/kotlinpoet/FunSpec$Builder; @@ -305,7 +305,7 @@ public final class com/squareup/kotlinpoet/FunSpec : com/squareup/kotlinpoet/Ann public final fun getDelegateConstructor ()Ljava/lang/String; public final fun getDelegateConstructorArguments ()Ljava/util/List; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock; - public final fun getModifiers ()Ljava/util/Set; + public fun getModifiers ()Ljava/util/Set; public final fun getName ()Ljava/lang/String; public fun getOriginatingElements ()Ljava/util/List; public final fun getParameters ()Ljava/util/List; @@ -330,7 +330,7 @@ public final class com/squareup/kotlinpoet/FunSpec : com/squareup/kotlinpoet/Ann public fun toString ()Ljava/lang/String; } -public final class com/squareup/kotlinpoet/FunSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/ContextReceivable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/OriginatingElementsHolder$Builder, com/squareup/kotlinpoet/Taggable$Builder { +public final class com/squareup/kotlinpoet/FunSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/ContextReceivable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/Modifiable$Builder, com/squareup/kotlinpoet/OriginatingElementsHolder$Builder, com/squareup/kotlinpoet/Taggable$Builder { public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/Annotatable$Builder; public fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/FunSpec$Builder; public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/ClassName;)Lcom/squareup/kotlinpoet/Annotatable$Builder; @@ -348,8 +348,6 @@ public final class com/squareup/kotlinpoet/FunSpec$Builder : com/squareup/kotlin public fun addKdoc (Lcom/squareup/kotlinpoet/CodeBlock;)Lcom/squareup/kotlinpoet/FunSpec$Builder; public synthetic fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/Documentable$Builder; public fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/FunSpec$Builder; - public final fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/FunSpec$Builder; - public final fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/FunSpec$Builder; public final fun addNamedCode (Ljava/lang/String;Ljava/util/Map;)Lcom/squareup/kotlinpoet/FunSpec$Builder; public final fun addParameter (Lcom/squareup/kotlinpoet/ParameterSpec;)Lcom/squareup/kotlinpoet/FunSpec$Builder; public final fun addParameter (Ljava/lang/String;Lcom/squareup/kotlinpoet/TypeName;Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/FunSpec$Builder; @@ -379,7 +377,7 @@ public final class com/squareup/kotlinpoet/FunSpec$Builder : com/squareup/kotlin public final fun endControlFlow ()Lcom/squareup/kotlinpoet/FunSpec$Builder; public fun getAnnotations ()Ljava/util/List; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock$Builder; - public final fun getModifiers ()Ljava/util/List; + public fun getModifiers ()Ljava/util/Set; public fun getOriginatingElements ()Ljava/util/List; public final fun getParameters ()Ljava/util/List; public fun getTags ()Ljava/util/Map; @@ -583,6 +581,16 @@ public abstract interface class com/squareup/kotlinpoet/MemberSpecHolder$Builder public fun addProperty (Ljava/lang/String;Lkotlin/reflect/KClass;[Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/MemberSpecHolder$Builder; } +public abstract interface class com/squareup/kotlinpoet/Modifiable { + public abstract fun getModifiers ()Ljava/util/Set; +} + +public abstract interface class com/squareup/kotlinpoet/Modifiable$Builder { + public fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/Modifiable$Builder; + public fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/Modifiable$Builder; + public abstract fun getModifiers ()Ljava/util/Set; +} + public final class com/squareup/kotlinpoet/NameAllocator { public fun ()V public fun (Z)V @@ -606,7 +614,7 @@ public final class com/squareup/kotlinpoet/OriginatingElementsHolder$Builder$Def public static fun addOriginatingElement (Lcom/squareup/kotlinpoet/OriginatingElementsHolder$Builder;Ljavax/lang/model/element/Element;)Lcom/squareup/kotlinpoet/OriginatingElementsHolder$Builder; } -public final class com/squareup/kotlinpoet/ParameterSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/Taggable { +public final class com/squareup/kotlinpoet/ParameterSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/Modifiable, com/squareup/kotlinpoet/Taggable { public static final field Companion Lcom/squareup/kotlinpoet/ParameterSpec$Companion; public fun (Ljava/lang/String;Lcom/squareup/kotlinpoet/TypeName;Ljava/lang/Iterable;)V public fun (Ljava/lang/String;Lcom/squareup/kotlinpoet/TypeName;[Lcom/squareup/kotlinpoet/KModifier;)V @@ -621,7 +629,7 @@ public final class com/squareup/kotlinpoet/ParameterSpec : com/squareup/kotlinpo public fun getAnnotations ()Ljava/util/List; public final fun getDefaultValue ()Lcom/squareup/kotlinpoet/CodeBlock; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock; - public final fun getModifiers ()Ljava/util/Set; + public fun getModifiers ()Ljava/util/Set; public final fun getName ()Ljava/lang/String; public fun getTags ()Ljava/util/Map; public final fun getType ()Lcom/squareup/kotlinpoet/TypeName; @@ -637,7 +645,7 @@ public final class com/squareup/kotlinpoet/ParameterSpec : com/squareup/kotlinpo public static final fun unnamed (Lkotlin/reflect/KClass;)Lcom/squareup/kotlinpoet/ParameterSpec; } -public final class com/squareup/kotlinpoet/ParameterSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/Taggable$Builder { +public final class com/squareup/kotlinpoet/ParameterSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/Modifiable$Builder, com/squareup/kotlinpoet/Taggable$Builder { public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/Annotatable$Builder; public fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/ClassName;)Lcom/squareup/kotlinpoet/Annotatable$Builder; @@ -652,14 +660,12 @@ public final class com/squareup/kotlinpoet/ParameterSpec$Builder : com/squareup/ public fun addKdoc (Lcom/squareup/kotlinpoet/CodeBlock;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; public synthetic fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/Documentable$Builder; public fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; - public final fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; - public final fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; public final fun build ()Lcom/squareup/kotlinpoet/ParameterSpec; public final fun defaultValue (Lcom/squareup/kotlinpoet/CodeBlock;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; public final fun defaultValue (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; public fun getAnnotations ()Ljava/util/List; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock$Builder; - public final fun getModifiers ()Ljava/util/List; + public fun getModifiers ()Ljava/util/Set; public fun getTags ()Ljava/util/Map; public final fun jvmModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/ParameterSpec$Builder; } @@ -720,7 +726,7 @@ public final class com/squareup/kotlinpoet/ParameterizedTypeNames { public static final fun get (Ljava/lang/reflect/ParameterizedType;)Lcom/squareup/kotlinpoet/ParameterizedTypeName; } -public final class com/squareup/kotlinpoet/PropertySpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/ContextReceivable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/OriginatingElementsHolder, com/squareup/kotlinpoet/Taggable { +public final class com/squareup/kotlinpoet/PropertySpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/ContextReceivable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/Modifiable, com/squareup/kotlinpoet/OriginatingElementsHolder, com/squareup/kotlinpoet/Taggable { public static final field Companion Lcom/squareup/kotlinpoet/PropertySpec$Companion; public static final fun builder (Ljava/lang/String;Lcom/squareup/kotlinpoet/TypeName;Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; public static final fun builder (Ljava/lang/String;Lcom/squareup/kotlinpoet/TypeName;[Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; @@ -735,7 +741,7 @@ public final class com/squareup/kotlinpoet/PropertySpec : com/squareup/kotlinpoe public final fun getGetter ()Lcom/squareup/kotlinpoet/FunSpec; public final fun getInitializer ()Lcom/squareup/kotlinpoet/CodeBlock; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock; - public final fun getModifiers ()Ljava/util/Set; + public fun getModifiers ()Ljava/util/Set; public final fun getMutable ()Z public final fun getName ()Ljava/lang/String; public fun getOriginatingElements ()Ljava/util/List; @@ -754,7 +760,7 @@ public final class com/squareup/kotlinpoet/PropertySpec : com/squareup/kotlinpoe public fun toString ()Ljava/lang/String; } -public final class com/squareup/kotlinpoet/PropertySpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/ContextReceivable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/OriginatingElementsHolder$Builder, com/squareup/kotlinpoet/Taggable$Builder { +public final class com/squareup/kotlinpoet/PropertySpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/ContextReceivable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/Modifiable$Builder, com/squareup/kotlinpoet/OriginatingElementsHolder$Builder, com/squareup/kotlinpoet/Taggable$Builder { public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/Annotatable$Builder; public fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/ClassName;)Lcom/squareup/kotlinpoet/Annotatable$Builder; @@ -769,8 +775,6 @@ public final class com/squareup/kotlinpoet/PropertySpec$Builder : com/squareup/k public fun addKdoc (Lcom/squareup/kotlinpoet/CodeBlock;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; public synthetic fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/Documentable$Builder; public fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; - public final fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; - public final fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; public final fun addTypeVariable (Lcom/squareup/kotlinpoet/TypeVariableName;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; public final fun addTypeVariables (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; public final fun build ()Lcom/squareup/kotlinpoet/PropertySpec; @@ -778,7 +782,7 @@ public final class com/squareup/kotlinpoet/PropertySpec$Builder : com/squareup/k public final fun delegate (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/PropertySpec$Builder; public fun getAnnotations ()Ljava/util/List; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock$Builder; - public final fun getModifiers ()Ljava/util/List; + public fun getModifiers ()Ljava/util/Set; public fun getOriginatingElements ()Ljava/util/List; public fun getTags ()Ljava/util/Map; public final fun getTypeVariables ()Ljava/util/List; @@ -825,7 +829,7 @@ public final class com/squareup/kotlinpoet/Taggable$DefaultImpls { public static fun tag (Lcom/squareup/kotlinpoet/Taggable;Lkotlin/reflect/KClass;)Ljava/lang/Object; } -public final class com/squareup/kotlinpoet/TypeAliasSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/Taggable { +public final class com/squareup/kotlinpoet/TypeAliasSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/Modifiable, com/squareup/kotlinpoet/Taggable { public static final field Companion Lcom/squareup/kotlinpoet/TypeAliasSpec$Companion; public static final fun builder (Ljava/lang/String;Lcom/squareup/kotlinpoet/TypeName;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; public static final fun builder (Ljava/lang/String;Ljava/lang/reflect/Type;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; @@ -833,7 +837,7 @@ public final class com/squareup/kotlinpoet/TypeAliasSpec : com/squareup/kotlinpo public fun equals (Ljava/lang/Object;)Z public fun getAnnotations ()Ljava/util/List; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock; - public final fun getModifiers ()Ljava/util/Set; + public fun getModifiers ()Ljava/util/Set; public final fun getName ()Ljava/lang/String; public fun getTags ()Ljava/util/Map; public final fun getType ()Lcom/squareup/kotlinpoet/TypeName; @@ -848,7 +852,7 @@ public final class com/squareup/kotlinpoet/TypeAliasSpec : com/squareup/kotlinpo public fun toString ()Ljava/lang/String; } -public final class com/squareup/kotlinpoet/TypeAliasSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/Taggable$Builder { +public final class com/squareup/kotlinpoet/TypeAliasSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/Modifiable$Builder, com/squareup/kotlinpoet/Taggable$Builder { public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/Annotatable$Builder; public fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/ClassName;)Lcom/squareup/kotlinpoet/Annotatable$Builder; @@ -863,14 +867,12 @@ public final class com/squareup/kotlinpoet/TypeAliasSpec$Builder : com/squareup/ public fun addKdoc (Lcom/squareup/kotlinpoet/CodeBlock;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; public synthetic fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/Documentable$Builder; public fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; - public final fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; - public final fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; public final fun addTypeVariable (Lcom/squareup/kotlinpoet/TypeVariableName;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; public final fun addTypeVariables (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/TypeAliasSpec$Builder; public final fun build ()Lcom/squareup/kotlinpoet/TypeAliasSpec; public fun getAnnotations ()Ljava/util/List; public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock$Builder; - public final fun getModifiers ()Ljava/util/Set; + public fun getModifiers ()Ljava/util/Set; public fun getTags ()Ljava/util/Map; public final fun getTypeVariables ()Ljava/util/Set; } @@ -957,7 +959,7 @@ public final class com/squareup/kotlinpoet/TypeNames { public static final fun get (Lkotlin/reflect/KClass;)Lcom/squareup/kotlinpoet/ClassName; } -public final class com/squareup/kotlinpoet/TypeSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/ContextReceivable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/MemberSpecHolder, com/squareup/kotlinpoet/OriginatingElementsHolder, com/squareup/kotlinpoet/Taggable, com/squareup/kotlinpoet/TypeSpecHolder { +public final class com/squareup/kotlinpoet/TypeSpec : com/squareup/kotlinpoet/Annotatable, com/squareup/kotlinpoet/ContextReceivable, com/squareup/kotlinpoet/Documentable, com/squareup/kotlinpoet/MemberSpecHolder, com/squareup/kotlinpoet/Modifiable, com/squareup/kotlinpoet/OriginatingElementsHolder, com/squareup/kotlinpoet/Taggable, com/squareup/kotlinpoet/TypeSpecHolder { public static final field Companion Lcom/squareup/kotlinpoet/TypeSpec$Companion; public static final fun annotationBuilder (Lcom/squareup/kotlinpoet/ClassName;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; public static final fun annotationBuilder (Ljava/lang/String;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; @@ -982,7 +984,7 @@ public final class com/squareup/kotlinpoet/TypeSpec : com/squareup/kotlinpoet/An public final fun getInitializerIndex ()I public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock; public final fun getKind ()Lcom/squareup/kotlinpoet/TypeSpec$Kind; - public final fun getModifiers ()Ljava/util/Set; + public fun getModifiers ()Ljava/util/Set; public final fun getName ()Ljava/lang/String; public fun getOriginatingElements ()Ljava/util/List; public final fun getPrimaryConstructor ()Lcom/squareup/kotlinpoet/FunSpec; @@ -1013,7 +1015,7 @@ public final class com/squareup/kotlinpoet/TypeSpec : com/squareup/kotlinpoet/An public static final fun valueClassBuilder (Ljava/lang/String;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; } -public final class com/squareup/kotlinpoet/TypeSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/ContextReceivable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/MemberSpecHolder$Builder, com/squareup/kotlinpoet/OriginatingElementsHolder$Builder, com/squareup/kotlinpoet/Taggable$Builder, com/squareup/kotlinpoet/TypeSpecHolder$Builder { +public final class com/squareup/kotlinpoet/TypeSpec$Builder : com/squareup/kotlinpoet/Annotatable$Builder, com/squareup/kotlinpoet/ContextReceivable$Builder, com/squareup/kotlinpoet/Documentable$Builder, com/squareup/kotlinpoet/MemberSpecHolder$Builder, com/squareup/kotlinpoet/Modifiable$Builder, com/squareup/kotlinpoet/OriginatingElementsHolder$Builder, com/squareup/kotlinpoet/Taggable$Builder, com/squareup/kotlinpoet/TypeSpecHolder$Builder { public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/Annotatable$Builder; public fun addAnnotation (Lcom/squareup/kotlinpoet/AnnotationSpec;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; public synthetic fun addAnnotation (Lcom/squareup/kotlinpoet/ClassName;)Lcom/squareup/kotlinpoet/Annotatable$Builder; @@ -1036,8 +1038,10 @@ public final class com/squareup/kotlinpoet/TypeSpec$Builder : com/squareup/kotli public fun addKdoc (Lcom/squareup/kotlinpoet/CodeBlock;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; public synthetic fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/Documentable$Builder; public fun addKdoc (Ljava/lang/String;[Ljava/lang/Object;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; - public final fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; - public final fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; + public synthetic fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/Modifiable$Builder; + public fun addModifiers (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; + public synthetic fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/Modifiable$Builder; + public fun addModifiers ([Lcom/squareup/kotlinpoet/KModifier;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; public synthetic fun addProperties (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/MemberSpecHolder$Builder; public fun addProperties (Ljava/lang/Iterable;)Lcom/squareup/kotlinpoet/TypeSpec$Builder; public synthetic fun addProperty (Lcom/squareup/kotlinpoet/PropertySpec;)Lcom/squareup/kotlinpoet/MemberSpecHolder$Builder; @@ -1079,7 +1083,7 @@ public final class com/squareup/kotlinpoet/TypeSpec$Builder : com/squareup/kotli public final fun getFunSpecs ()Ljava/util/List; public final fun getInitializerIndex ()I public fun getKdoc ()Lcom/squareup/kotlinpoet/CodeBlock$Builder; - public final fun getModifiers ()Ljava/util/Set; + public fun getModifiers ()Ljava/util/Set; public fun getOriginatingElements ()Ljava/util/List; public final fun getPropertySpecs ()Ljava/util/List; public final fun getSuperclassConstructorParameters ()Ljava/util/List; diff --git a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/FunSpec.kt b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/FunSpec.kt index 06059c96e8..010ecc88ef 100644 --- a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/FunSpec.kt +++ b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/FunSpec.kt @@ -42,13 +42,14 @@ public class FunSpec private constructor( OriginatingElementsHolder by delegateOriginatingElementsHolder, ContextReceivable by contextReceivers, Annotatable, - Documentable { + Documentable, + Modifiable { public val name: String = builder.name override val kdoc: CodeBlock = builder.kdoc.build() public val returnKdoc: CodeBlock = builder.returnKdoc public val receiverKdoc: CodeBlock = builder.receiverKdoc override val annotations: List = builder.annotations.toImmutableList() - public val modifiers: Set = builder.modifiers.toImmutableSet() + override val modifiers: Set = builder.modifiers.toImmutableSet() public val typeVariables: List = builder.typeVariables.toImmutableList() public val receiverType: TypeName? = builder.receiverType @@ -307,7 +308,8 @@ public class FunSpec private constructor( OriginatingElementsHolder.Builder, ContextReceivable.Builder, Annotatable.Builder, - Documentable.Builder { + Documentable.Builder, + Modifiable.Builder { internal var returnKdoc = CodeBlock.EMPTY internal var receiverKdoc = CodeBlock.EMPTY internal var receiverType: TypeName? = null @@ -317,7 +319,7 @@ public class FunSpec private constructor( internal val body = CodeBlock.builder() override val kdoc: CodeBlock.Builder = CodeBlock.builder() override val annotations: MutableList = mutableListOf() - public val modifiers: MutableList = mutableListOf() + override val modifiers: MutableSet = mutableSetOf() public val typeVariables: MutableList = mutableListOf() public val parameters: MutableList = mutableListOf() override val tags: MutableMap, Any> = mutableMapOf() @@ -326,14 +328,6 @@ public class FunSpec private constructor( @ExperimentalKotlinPoetApi override val contextReceiverTypes: MutableList = mutableListOf() - public fun addModifiers(vararg modifiers: KModifier): Builder = apply { - this.modifiers += modifiers - } - - public fun addModifiers(modifiers: Iterable): Builder = apply { - this.modifiers += modifiers - } - public fun jvmModifiers(modifiers: Iterable) { var visibility = KModifier.INTERNAL for (modifier in modifiers) { diff --git a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/Modifiable.kt b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/Modifiable.kt new file mode 100644 index 0000000000..ea30924d3c --- /dev/null +++ b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/Modifiable.kt @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2024 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.squareup.kotlinpoet + +/** A spec that has a set of [KModifier]s attached to it. */ +public interface Modifiable { + public val modifiers: Set + + public interface Builder> { + public val modifiers: MutableSet + + /** + * Add one or multiple modifiers to this spec. + * + * Note that not all [KModifier]s can be applied to a specific spec, and specs may or may not + * validate modifiers at runtime. Consult Kotlin documentation on which modifiers are allowed on + * specific Kotlin constructs. + */ + @Suppress("UNCHECKED_CAST") + public fun addModifiers(vararg modifiers: KModifier): T = apply { + this.modifiers += modifiers + } as T + + /** + * Add a collection of modifiers to this spec. + * + * Note that not all [KModifier]s can be applied to a specific spec, and specs may or may not + * validate modifiers at runtime. Consult Kotlin documentation on which modifiers are allowed on + * specific Kotlin constructs. + */ + @Suppress("UNCHECKED_CAST") + public fun addModifiers(modifiers: Iterable): T = apply { + this.modifiers += modifiers + } as T + } +} diff --git a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt index 00c7374141..08951af511 100644 --- a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt +++ b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/ParameterSpec.kt @@ -29,11 +29,11 @@ import kotlin.reflect.KClass public class ParameterSpec private constructor( builder: Builder, private val tagMap: TagMap = builder.buildTagMap(), -) : Taggable by tagMap, Annotatable, Documentable { +) : Taggable by tagMap, Annotatable, Documentable, Modifiable { public val name: String = builder.name override val kdoc: CodeBlock = builder.kdoc.build() override val annotations: List = builder.annotations.toImmutableList() - public val modifiers: Set = builder.modifiers + override val modifiers: Set = builder.modifiers .also { LinkedHashSet(it).apply { removeAll(ALLOWED_PARAMETER_MODIFIERS) @@ -94,22 +94,17 @@ public class ParameterSpec private constructor( public class Builder internal constructor( internal val name: String, internal val type: TypeName, - ) : Taggable.Builder, Annotatable.Builder, Documentable.Builder { + ) : Taggable.Builder, + Annotatable.Builder, + Documentable.Builder, + Modifiable.Builder { internal var defaultValue: CodeBlock? = null - public val modifiers: MutableList = mutableListOf() + override val modifiers: MutableSet = mutableSetOf() override val kdoc: CodeBlock.Builder = CodeBlock.builder() override val tags: MutableMap, Any> = mutableMapOf() override val annotations: MutableList = mutableListOf() - public fun addModifiers(vararg modifiers: KModifier): Builder = apply { - this.modifiers += modifiers - } - - public fun addModifiers(modifiers: Iterable): Builder = apply { - this.modifiers += modifiers - } - @Deprecated( "There are no jvm modifiers applicable to parameters in Kotlin", ReplaceWith(""), diff --git a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/PropertySpec.kt b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/PropertySpec.kt index 2b153dbcb0..584baf2116 100644 --- a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/PropertySpec.kt +++ b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/PropertySpec.kt @@ -34,13 +34,14 @@ public class PropertySpec private constructor( OriginatingElementsHolder by delegateOriginatingElementsHolder, ContextReceivable by contextReceivers, Annotatable, - Documentable { + Documentable, + Modifiable { public val mutable: Boolean = builder.mutable public val name: String = builder.name public val type: TypeName = builder.type override val kdoc: CodeBlock = builder.kdoc.build() override val annotations: List = builder.annotations.toImmutableList() - public val modifiers: Set = builder.modifiers.toImmutableSet() + override val modifiers: Set = builder.modifiers.toImmutableSet() public val typeVariables: List = builder.typeVariables.toImmutableList() public val initializer: CodeBlock? = builder.initializer public val delegated: Boolean = builder.delegated @@ -176,7 +177,8 @@ public class PropertySpec private constructor( OriginatingElementsHolder.Builder, ContextReceivable.Builder, Annotatable.Builder, - Documentable.Builder { + Documentable.Builder, + Modifiable.Builder { internal var isPrimaryConstructorParameter = false internal var mutable = false internal var initializer: CodeBlock? = null @@ -185,7 +187,7 @@ public class PropertySpec private constructor( internal var setter: FunSpec? = null internal var receiverType: TypeName? = null - public val modifiers: MutableList = mutableListOf() + override val modifiers: MutableSet = mutableSetOf() public val typeVariables: MutableList = mutableListOf() override val tags: MutableMap, Any> = mutableMapOf() override val kdoc: CodeBlock.Builder = CodeBlock.builder() @@ -200,14 +202,6 @@ public class PropertySpec private constructor( this.mutable = mutable } - public fun addModifiers(vararg modifiers: KModifier): Builder = apply { - this.modifiers += modifiers - } - - public fun addModifiers(modifiers: Iterable): Builder = apply { - this.modifiers += modifiers - } - public fun addTypeVariables(typeVariables: Iterable): Builder = apply { this.typeVariables += typeVariables } diff --git a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeAliasSpec.kt b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeAliasSpec.kt index f9a607fba8..0d339aabc2 100644 --- a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeAliasSpec.kt +++ b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeAliasSpec.kt @@ -26,10 +26,10 @@ import kotlin.reflect.KClass public class TypeAliasSpec private constructor( builder: Builder, private val tagMap: TagMap = builder.buildTagMap(), -) : Taggable by tagMap, Annotatable, Documentable { +) : Taggable by tagMap, Annotatable, Documentable, Modifiable { public val name: String = builder.name public val type: TypeName = builder.type - public val modifiers: Set = builder.modifiers.toImmutableSet() + override val modifiers: Set = builder.modifiers.toImmutableSet() public val typeVariables: List = builder.typeVariables.toImmutableList() override val kdoc: CodeBlock = builder.kdoc.build() override val annotations: List = builder.annotations.toImmutableList() @@ -69,25 +69,16 @@ public class TypeAliasSpec private constructor( public class Builder internal constructor( internal val name: String, internal val type: TypeName, - ) : Taggable.Builder, Annotatable.Builder, Documentable.Builder { - public val modifiers: MutableSet = mutableSetOf() + ) : Taggable.Builder, + Annotatable.Builder, + Documentable.Builder, + Modifiable.Builder { + override val modifiers: MutableSet = mutableSetOf() public val typeVariables: MutableSet = mutableSetOf() override val tags: MutableMap, Any> = mutableMapOf() override val kdoc: CodeBlock.Builder = CodeBlock.builder() override val annotations: MutableList = mutableListOf() - public fun addModifiers(vararg modifiers: KModifier): Builder = apply { - modifiers.forEach(this::addModifier) - } - - public fun addModifiers(modifiers: Iterable): Builder = apply { - modifiers.forEach(this::addModifier) - } - - private fun addModifier(modifier: KModifier) { - this.modifiers.add(modifier) - } - public fun addTypeVariables(typeVariables: Iterable): Builder = apply { this.typeVariables += typeVariables } diff --git a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt index 7bca35bc0a..c8f8fbb1b1 100644 --- a/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt +++ b/kotlinpoet/src/jvmMain/kotlin/com/squareup/kotlinpoet/TypeSpec.kt @@ -48,13 +48,14 @@ public class TypeSpec private constructor( ContextReceivable by contextReceivers, Annotatable, Documentable, + Modifiable, TypeSpecHolder, MemberSpecHolder { public val kind: Kind = builder.kind public val name: String? = builder.name override val kdoc: CodeBlock = builder.kdoc.build() override val annotations: List = builder.annotations.toImmutableList() - public val modifiers: Set = builder.modifiers.toImmutableSet() + override val modifiers: Set = builder.modifiers.toImmutableSet() public val typeVariables: List = builder.typeVariables.toImmutableList() public val primaryConstructor: FunSpec? = builder.primaryConstructor public val superclass: TypeName = builder.superclass @@ -476,6 +477,7 @@ public class TypeSpec private constructor( ContextReceivable.Builder, Annotatable.Builder, Documentable.Builder, + Modifiable.Builder, TypeSpecHolder.Builder, MemberSpecHolder.Builder { internal var primaryConstructor: FunSpec? = null @@ -499,7 +501,7 @@ public class TypeSpec private constructor( @ExperimentalKotlinPoetApi override val contextReceiverTypes: MutableList = mutableListOf() - public val modifiers: MutableSet = mutableSetOf(*modifiers) + override val modifiers: MutableSet = mutableSetOf(*modifiers) public val superinterfaces: MutableMap = mutableMapOf() public val enumConstants: MutableMap = mutableMapOf() public val typeVariables: MutableList = mutableListOf() @@ -511,14 +513,14 @@ public class TypeSpec private constructor( @Deprecated("Use annotations property", ReplaceWith("annotations"), ERROR) public val annotationSpecs: MutableList get() = annotations - public fun addModifiers(vararg modifiers: KModifier): Builder = apply { + override fun addModifiers(vararg modifiers: KModifier): Builder { check(!isAnonymousClass) { "forbidden on anonymous types." } - this.modifiers += modifiers + return super.addModifiers(*modifiers) } - public fun addModifiers(modifiers: Iterable): Builder = apply { + override fun addModifiers(modifiers: Iterable): Builder { check(!isAnonymousClass) { "forbidden on anonymous types." } - this.modifiers += modifiers + return super.addModifiers(modifiers) } public fun addTypeVariables(typeVariables: Iterable): Builder = apply {