forked from square/wire
-
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.
Emit compiler flags around Codable, Equatable, Hashable, and Redactable
This allows you to turn off features for a module which are not needed to save binary size.
- Loading branch information
1 parent
72c5e30
commit 2964424
Showing
33 changed files
with
539 additions
and
60 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
72 changes: 72 additions & 0 deletions
72
wire-library/wire-swift-generator/src/main/swiftpoet/io/outfoxx/swiftpoet/FileMemberSpec.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,72 @@ | ||
package io.outfoxx.swiftpoet | ||
|
||
class FileMemberSpec internal constructor(builder: Builder) { | ||
val kdoc = builder.kdoc.build() | ||
val member = builder.member | ||
val guardTest = builder.guardTest.build() | ||
|
||
internal fun emit(out: CodeWriter): CodeWriter { | ||
|
||
out.emitKdoc(kdoc) | ||
|
||
if (guardTest.isNotEmpty()) { | ||
out.emit("#if ") | ||
out.emitCode(guardTest) | ||
out.emit("\n") | ||
} | ||
|
||
when (member) { | ||
is TypeSpec -> member.emit(out) | ||
is FunctionSpec -> member.emit(out, null, setOf(Modifier.PUBLIC)) | ||
is PropertySpec -> member.emit(out, setOf(Modifier.PUBLIC)) | ||
is TypeAliasSpec -> member.emit(out) | ||
is ExtensionSpec -> member.emit(out) | ||
else -> throw AssertionError() | ||
} | ||
|
||
if (guardTest.isNotEmpty()) { | ||
out.emit("#endif") | ||
out.emit("\n") | ||
} | ||
|
||
return out | ||
} | ||
|
||
class Builder internal constructor(internal val member: Any) { | ||
internal val kdoc = CodeBlock.builder() | ||
internal val guardTest = CodeBlock.builder() | ||
|
||
fun addKdoc(format: String, vararg args: Any) = apply { | ||
kdoc.add(format, *args) | ||
} | ||
|
||
fun addKdoc(block: CodeBlock) = apply { | ||
kdoc.add(block) | ||
} | ||
|
||
fun addGuard(test: CodeBlock) = apply { | ||
guardTest.add(test) | ||
} | ||
|
||
fun addGuard(format: String, vararg args: Any) = apply { | ||
addGuard(CodeBlock.of(format, args)) | ||
} | ||
|
||
fun build(): FileMemberSpec { | ||
return FileMemberSpec(this) | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic fun builder(member: TypeSpec) = Builder(member) | ||
|
||
@JvmStatic fun builder(member: FunctionSpec) = Builder(member) | ||
|
||
@JvmStatic fun builder(member: PropertySpec) = Builder(member) | ||
|
||
@JvmStatic fun builder(member: TypeAliasSpec) = Builder(member) | ||
|
||
@JvmStatic fun builder(member: ExtensionSpec) = Builder(member) | ||
} | ||
|
||
} |
Oops, something went wrong.