-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c2593f
commit a98043a
Showing
4,197 changed files
with
28,420 additions
and
44,266 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...d-logic/src/main/kotlin/cloudshift/awscdkdsl/build/dsl/model/type/CdkWrappersGenerator.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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package cloudshift.awscdkdsl.build.dsl.model.type | ||
|
||
import cloudshift.awscdkdsl.build.dsl.isBuilderClass | ||
import cloudshift.awscdkdsl.build.dsl.isCdkClass | ||
import cloudshift.awscdkdsl.build.dsl.mappedClassName | ||
import cloudshift.awscdkdsl.build.dsl.model.CdkModel | ||
import com.squareup.kotlinpoet.ANY | ||
import com.squareup.kotlinpoet.ClassName | ||
import com.squareup.kotlinpoet.CodeBlock | ||
import com.squareup.kotlinpoet.FileSpec | ||
import com.squareup.kotlinpoet.FunSpec | ||
import com.squareup.kotlinpoet.KModifier | ||
import com.squareup.kotlinpoet.LambdaTypeName | ||
import com.squareup.kotlinpoet.MAP | ||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy | ||
import com.squareup.kotlinpoet.PropertySpec | ||
import com.squareup.kotlinpoet.STRING | ||
import com.squareup.kotlinpoet.TypeSpec | ||
import kotlin.reflect.KClass | ||
|
||
internal object CdkWrappersGenerator { | ||
internal fun generateCdkWrappersObject(model: CdkModel): FileSpec { | ||
val builder = TypeSpec.objectBuilder(ClassName) | ||
.addModifiers(KModifier.INTERNAL) | ||
|
||
val resolveWrapperFunction = FunSpec.builder("resolveWrapperFunction") | ||
.addParameter("klass", KClass::class) | ||
.returns(KClass::class) | ||
.addStatement( | ||
"val qualifiedName = klass::class.qualifiedName ?: error(%P)", | ||
"No qualified name for \${klass::class}", | ||
) | ||
.addStatement("return typeMap[qualifiedName] ?: klass.superclasses.filterNot { it.java.isInterface || it.isAbstract || it == Any::class }.firstOrNull()?.let { resolveWrapperFunction(it) }") | ||
.build() | ||
|
||
val wrapFunction = FunSpec.builder("wrap") | ||
.addModifiers(KModifier.INTERNAL) | ||
.addParameter("cdkObject", ANY) | ||
.returns(ANY) | ||
.addCode("%L", resolveWrapperFunction) | ||
.addStatement( | ||
"return resolveWrapperFunction(cdkObject::class)?.invoke(cdkObject) ?: error(%P)", | ||
"No wrapper found for type \${cdkObject::class}", | ||
) | ||
|
||
builder.addFunction(wrapFunction.build()) | ||
|
||
val mapBuilder = CodeBlock.builder() | ||
.addStatement("mapOf(") | ||
model.classes.filter { | ||
it.className.isCdkClass && !(it.isEnum || it.isInterface || it.isAbstract || it.className.isBuilderClass) | ||
}.map { | ||
mapBuilder.addStatement( | ||
"\"%L\" to { %T.wrap(it as %T) },", | ||
it.className, | ||
it.className.mappedClassName(), | ||
it.className, | ||
) | ||
} | ||
mapBuilder.addStatement(")") | ||
|
||
val lambdaTypeName = LambdaTypeName.get( | ||
receiver = ANY, | ||
returnType = ANY, | ||
) | ||
val typeMap = PropertySpec.builder("typeMap", MAP.parameterizedBy(STRING, lambdaTypeName)) | ||
.addModifiers(KModifier.PRIVATE) | ||
.initializer(mapBuilder.build()) | ||
.build() | ||
|
||
builder.addProperty(typeMap) | ||
|
||
return FileSpec.builder(ClassName) | ||
.addType(builder.build()) | ||
.build() | ||
} | ||
|
||
val ClassName = ClassName("io.cloudshiftdev.awscdk.common", "CdkObjectWrappers") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
group = io.cloudshiftdev.kotlin-cdk-wrapper | ||
version = 0.7.4 | ||
version = 0.7.5 | ||
|
||
kotlin.code.style=official | ||
|
||
|
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
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
Oops, something went wrong.