Skip to content

Commit dab8a2b

Browse files
authored
refactor(codegen): Java builder removal (#534)
1 parent 706e808 commit dab8a2b

File tree

19 files changed

+291
-729
lines changed

19 files changed

+291
-729
lines changed

compile-tests/src/test/kotlin/software/amazon/smithy/kotlin/codegen/WhiteLabelSDKTest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class WhiteLabelSDKTest {
2121

2222
@Test
2323
fun `white label sdk compiles without errors`() {
24-
val model = javaClass.getResource("/kitchen-sink-model.smithy").asSmithy()
24+
val model = javaClass.getResource("/kitchen-sink-model.smithy")!!.asSmithy()
2525

2626
val compileOutputStream = ByteArrayOutputStream()
2727
val compilationResult = compileSdkAndTest(model = model, outputSink = compileOutputStream, emitSourcesToTmp = Debug.emitSourcesToTemp)
@@ -34,7 +34,7 @@ class WhiteLabelSDKTest {
3434
@Test
3535
@Ignore
3636
fun `white label sdk compiles without breaching warning threshold`() {
37-
val model = javaClass.getResource("/kitchen-sink-model.smithy").asSmithy()
37+
val model = javaClass.getResource("/kitchen-sink-model.smithy")!!.asSmithy()
3838

3939
val compileOutputStream = ByteArrayOutputStream()
4040
val compilationResult = compileSdkAndTest(model = model, outputSink = compileOutputStream, emitSourcesToTmp = Debug.emitSourcesToTemp)
@@ -89,7 +89,7 @@ class WhiteLabelSDKTest {
8989
val compilationResult = compileSdkAndTest(model = model, outputSink = compileOutputStream, emitSourcesToTmp = Debug.emitSourcesToTemp)
9090
compileOutputStream.flush()
9191

92-
assertTrue(compilationResult.exitCode == KotlinCompilation.ExitCode.OK, compileOutputStream.toString())
92+
assertEquals(KotlinCompilation.ExitCode.OK, compilationResult.exitCode, compileOutputStream.toString())
9393
}
9494

9595
@Test
@@ -127,7 +127,7 @@ class WhiteLabelSDKTest {
127127
val compilationResult = compileSdkAndTest(model = model, outputSink = compileOutputStream, emitSourcesToTmp = Debug.emitSourcesToTemp)
128128
compileOutputStream.flush()
129129

130-
assertTrue(compilationResult.exitCode == KotlinCompilation.ExitCode.OK, compileOutputStream.toString())
130+
assertEquals(KotlinCompilation.ExitCode.OK, compilationResult.exitCode, compileOutputStream.toString())
131131
}
132132

133133
@Test
@@ -167,7 +167,7 @@ class WhiteLabelSDKTest {
167167
val compilationResult = compileSdkAndTest(model = model, outputSink = compileOutputStream, emitSourcesToTmp = Debug.emitSourcesToTemp)
168168
compileOutputStream.flush()
169169

170-
assertTrue(compilationResult.exitCode == KotlinCompilation.ExitCode.OK, compileOutputStream.toString())
170+
assertEquals(KotlinCompilation.ExitCode.OK, compilationResult.exitCode, compileOutputStream.toString())
171171
}
172172
}
173173

docs/design/binary-streaming.md

Lines changed: 28 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct GetObjectResponse {
8989
```
9090

9191

92-
The following types and service would be generated (note the Java `Builder` implementation has been left off for brevity).
92+
The following types and service would be generated.
9393

9494
### Put Object
9595
See the Appendix for an overview of the `ByteStream` type.
@@ -98,50 +98,32 @@ See the Appendix for an overview of the `ByteStream` type.
9898

9999
import software.aws.clientrt.content.ByteStream
100100

101-
class PutObjectRequest private constructor(builder: BuilderImpl){
101+
class PutObjectRequest private constructor(builder: Builder){
102102
val bucket: String? = builder.bucket
103103
val key: String? = builder.key
104104
val body: ByteStream? = builder.body
105105

106106
companion object {
107-
operator fun invoke(block: DslBuilder.() -> Unit) = BuilderImpl().apply(block).build()
107+
operator fun invoke(block: Builder.() -> Unit) = Builder().apply(block).build()
108108
}
109109

110-
interface Builder {
111-
fun build(): PutObjectRequest
112-
}
113-
114-
interface DslBuilder {
115-
var body: ByteStream?
116-
var bucket: String?
117-
var key: String?
118-
}
119-
120-
private class BuilderImpl : Builder, DslBuilder {
121-
override var body: ByteStream? = null
122-
override var bucket: String? = null
123-
override var key: String? = null
124-
override fun build(): PutObjectRequest = PutObjectRequest(this)
110+
public class Builder {
111+
var body: ByteStream? = null
112+
var bucket: String? = null
113+
var key: String? = null
114+
fun build(): PutObjectRequest = PutObjectRequest(this)
125115
}
126116
}
127117

128118

129-
class PutObjectResponse private constructor(builder: BuilderImpl){
119+
class PutObjectResponse private constructor(builder: Builder){
130120
val versionId: String? = builder.versionId
131121

132122
companion object {
133-
operator fun invoke(block: DslBuilder.() -> Unit) = BuilderImpl().apply(block).build()
134-
}
135-
136-
interface Builder {
137-
fun build(): PutObjectResponse
138-
}
139-
140-
interface DslBuilder {
141-
var versionId: String?
123+
operator fun invoke(block: Builder.() -> Unit) = Builder().apply(block).build()
142124
}
143125

144-
private class BuilderImpl : Builder, DslBuilder {
126+
public class Builder {
145127
override var versionId: String? = null
146128
override fun build(): PutObjectResponse = PutObjectResponse(this)
147129
}
@@ -156,55 +138,37 @@ class PutObjectResponse private constructor(builder: BuilderImpl){
156138
```kt
157139
package com.amazonaws.service.s3.model
158140

159-
class GetObjectRequest private constructor(builder: BuilderImpl){
141+
class GetObjectRequest private constructor(builder: Builder){
160142
val bucket: String? = builder.bucket
161143
val key: String? = builder.key
162144

163145
companion object {
164-
operator fun invoke(block: DslBuilder.() -> Unit) = BuilderImpl().apply(block).build()
165-
}
166-
167-
interface Builder {
168-
fun build(): GetObjectRequest
146+
operator fun invoke(block: Builder.() -> Unit) = Builder().apply(block).build()
169147
}
170-
171-
interface DslBuilder {
172-
var bucket: String?
173-
var key: String?
174-
}
175-
176-
private class BuilderImpl : Builder, DslBuilder {
177-
override var bucket: String? = null
178-
override var key: String? = null
179-
override fun build(): GetObjectRequest = GetObjectRequest(this)
148+
149+
public class Builder {
150+
var bucket: String? = null
151+
var key: String? = null
152+
fun build(): GetObjectRequest = GetObjectRequest(this)
180153
}
181154
}
182155

183156

184157
import software.aws.clientrt.content.ByteStream
185158

186-
class GetObjectResponse private constructor(builder: BuilderImpl){
159+
class GetObjectResponse private constructor(builder: Builder){
187160

188161
val body: ByteStream? = builder.body
189162
val versionId: String? = builder.versionId
190163

191164
companion object {
192-
operator fun invoke(block: DslBuilder.() -> Unit) = BuilderImpl().apply(block).build()
165+
operator fun invoke(block: Builder.() -> Unit) = Builder().apply(block).build()
193166
}
194167

195-
interface Builder {
196-
fun build(): GetObjectResponse
197-
}
198-
199-
interface DslBuilder {
200-
var body: ByteStream?
201-
var versionId: String?
202-
}
203-
204-
private class BuilderImpl : Builder, DslBuilder {
205-
override var body: ByteStream? = null
206-
override var versionId: String? = null
207-
override fun build(): GetObjectResponse = GetObjectResponse(this)
168+
public class Builder {
169+
var body: ByteStream? = null
170+
var versionId: String? = null
171+
fun build(): GetObjectResponse = GetObjectResponse(this)
208172
}
209173
}
210174

@@ -336,7 +300,7 @@ e.g.
336300
```kt
337301
suspend fun getObject(input: GetObjectRequest): GetObjectResponse { ... }
338302

339-
suspend fun getObject(block: GetObjectRequest.DslBuilder.() -> Unit): GetObjectResponse {
303+
suspend fun getObject(block: GetObjectRequest.Builder.() -> Unit): GetObjectResponse {
340304
val input = GetObjectRequest.invoke(block)
341305
return getObject(input)
342306
}
@@ -552,12 +516,12 @@ A simplified example of the request/response would look like:
552516

553517

554518
```kt
555-
class PutObjectRequest private constructor(builder: BuilderImpl) {
519+
class PutObjectRequest private constructor(builder: Builder) {
556520
val body: Flow<ByteArray>? = builder.body
557521
}
558522

559523

560-
class GetObjectResponse private constructor(builder: BuilderImpl) {
524+
class GetObjectResponse private constructor(builder: Builder) {
561525
val body: Flow<ByteArray>? = builder.body
562526
}
563527

@@ -647,5 +611,6 @@ The issue with going that route is two fold:
647611

648612
# Revision history
649613

614+
* 11/15/2021 - Update code snippets from builder refactoring
650615
* 6/03/2021 - Initial upload
651616
* 6/11/2020 - Created

0 commit comments

Comments
 (0)