-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve code readability (after review comments)
- Loading branch information
Showing
13 changed files
with
73 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 17 additions & 42 deletions
59
src/main/kotlin/com/virtuslab/pulumikotlin/codegen/step2intermediate/MoreTypes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,46 @@ | ||
package com.virtuslab.pulumikotlin.codegen.step2intermediate | ||
|
||
import com.pulumi.core.Output | ||
import com.pulumi.kotlin.ConvertibleToJava | ||
import com.squareup.kotlinpoet.ClassName | ||
import com.pulumi.kotlin.CustomArgs | ||
import com.pulumi.kotlin.CustomArgsBuilder | ||
import com.pulumi.kotlin.PulumiTagMarker | ||
import com.squareup.kotlinpoet.MemberName | ||
import com.squareup.kotlinpoet.MemberName.Companion.member | ||
import com.squareup.kotlinpoet.ParameterizedTypeName | ||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy | ||
import com.squareup.kotlinpoet.TypeName | ||
import com.squareup.kotlinpoet.asClassName | ||
import com.squareup.kotlinpoet.asTypeName | ||
|
||
object MoreTypes { | ||
|
||
object Kotlin { | ||
object Pulumi { | ||
fun toJavaMethod(): MemberName { | ||
return MemberName("com.pulumi.kotlin", "toJava") | ||
} | ||
fun toJavaExtensionMethod() = MemberName("com.pulumi.kotlin", "toJava") | ||
|
||
fun pulumiDslMarkerAnnotation(): ClassName { | ||
return ClassName("com.pulumi.kotlin", "PulumiTagMarker") | ||
} | ||
fun toKotlinExtensionMethod() = MemberName("com.pulumi.kotlin", "toKotlin") | ||
|
||
fun toKotlinMethod(): MemberName { | ||
return MemberName("com.pulumi.kotlin", "toKotlin") | ||
} | ||
fun applySuspendExtensionMethod() = MemberName("com.pulumi.kotlin", "applySuspend") | ||
|
||
fun applySuspendExtensionMethod(): MemberName { | ||
return MemberName("com.pulumi.kotlin", "applySuspend") | ||
} | ||
fun applyValueExtensionMethod() = MemberName("com.pulumi.kotlin", "applyValue") | ||
|
||
fun applyValueExtensionMethod(): MemberName { | ||
return MemberName("com.pulumi.kotlin", "applyValue") | ||
} | ||
fun pulumiDslMarkerAnnotation() = PulumiTagMarker::class.asClassName() | ||
|
||
fun convertibleToJavaClass(type: TypeName): ParameterizedTypeName = | ||
ConvertibleToJava::class.asClassName().parameterizedBy(type) | ||
fun convertibleToJavaClass() = ConvertibleToJava::class.asClassName() | ||
|
||
fun customArgsClass(): ClassName { | ||
return ClassName("com.pulumi.kotlin", "CustomArgs") | ||
} | ||
fun customArgsClass() = CustomArgs::class.asClassName() | ||
|
||
fun customArgsBuilderClass(): ClassName { | ||
return ClassName("com.pulumi.kotlin", "CustomArgsBuilder") | ||
} | ||
fun customArgsBuilderClass() = CustomArgsBuilder::class.asClassName() | ||
} | ||
|
||
fun coroutinesFutureAwaitExtensionMethod(): MemberName { | ||
return MemberName("kotlinx.coroutines.future", "await") | ||
} | ||
fun coroutinesFutureAwaitExtensionMethod() = MemberName("kotlinx.coroutines.future", "await") | ||
|
||
fun pairClass(leftType: TypeName, rightType: TypeName): ParameterizedTypeName { | ||
return ClassName("kotlin", "Pair").parameterizedBy(leftType, rightType) | ||
} | ||
fun pairClass() = Pair::class.asTypeName() | ||
} | ||
|
||
object Java { | ||
object Pulumi { | ||
fun outputOfMethod(): MemberName = | ||
outputClass().member("of") | ||
|
||
fun outputClass(): ClassName { | ||
return ClassName("com.pulumi.core", "Output") | ||
} | ||
fun outputOfMethod() = outputClass().member("of") | ||
|
||
fun outputClass(type: TypeName): ParameterizedTypeName { | ||
return ClassName("com.pulumi.core", "Output").parameterizedBy(type) | ||
} | ||
fun outputClass() = Output::class.asClassName() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 21 additions & 20 deletions
41
src/main/kotlin/com/virtuslab/pulumikotlin/codegen/step3codegen/KotlinPoetExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
package com.virtuslab.pulumikotlin.codegen.step3codegen | ||
|
||
import com.squareup.kotlinpoet.ClassName | ||
import com.squareup.kotlinpoet.CodeBlock | ||
import com.squareup.kotlinpoet.FileSpec | ||
import com.squareup.kotlinpoet.FunSpec | ||
import com.squareup.kotlinpoet.MemberName | ||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy | ||
import com.squareup.kotlinpoet.PropertySpec | ||
import com.squareup.kotlinpoet.TypeSpec | ||
import com.virtuslab.pulumikotlin.codegen.expressions.Code | ||
import com.virtuslab.pulumikotlin.codegen.step2intermediate.Type | ||
|
||
object KotlinPoetExtensions { | ||
fun FileSpec.Builder.addTypes(vararg typeSpecs: TypeSpec) = | ||
addTypes(typeSpecs.toList()) | ||
fun TypeSpec.Builder.addFunctions(vararg funSpecs: FunSpec) = addFunctions(funSpecs.toList()) | ||
|
||
fun TypeSpec.Builder.addFunctions(vararg funSpecs: FunSpec) = | ||
addFunctions(funSpecs.toList()) | ||
fun TypeSpec.Builder.addProperties(vararg propertySpecs: PropertySpec) = addProperties(propertySpecs.toList()) | ||
|
||
fun TypeSpec.Builder.addProperties(vararg propertySpecs: PropertySpec) = | ||
addProperties(propertySpecs.toList()) | ||
fun FileSpec.Builder.addImport(memberName: MemberName) = addImport(memberName.packageName, memberName.simpleName) | ||
|
||
fun FileSpec.Builder.addImport(memberName: MemberName) = | ||
addImport(memberName.packageName, memberName.simpleName) | ||
fun FileSpec.Builder.addImports(vararg memberNames: MemberName) = | ||
apply { | ||
memberNames.forEach { | ||
addImport(it) | ||
} | ||
} | ||
|
||
fun FileSpec.Builder.addTypes(vararg typeSpecs: TypeSpec) = addTypes(typeSpecs.toList()) | ||
|
||
fun FileSpec.Builder.addImports(vararg memberNames: MemberName): FileSpec.Builder { | ||
memberNames.forEach { | ||
addImport(it) | ||
fun FileSpec.Builder.addTypes(types: Iterable<TypeSpec>) = | ||
apply { | ||
types.forEach { | ||
addType(it) | ||
} | ||
} | ||
return this | ||
} | ||
|
||
fun FileSpec.Builder.addTypes(types: Iterable<TypeSpec>): FileSpec.Builder { | ||
types.forEach { addType(it) } | ||
return this | ||
} | ||
fun ClassName.parameterizedBy(vararg types: Type) = parameterizedBy(types.map { it.toTypeName() }) | ||
|
||
fun CodeBlock.Builder.add(code: Code): CodeBlock.Builder { | ||
return this.add(code.toCodeBlock().toKotlinPoetCodeBlock()) | ||
} | ||
fun CodeBlock.Builder.add(code: Code) = add(code.toCodeBlock().toKotlinPoetCodeBlock()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters