Skip to content

Commit

Permalink
Opt-out wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor Andreevici committed Dec 15, 2017
1 parent eb2ca1c commit a5e5eb0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/squareup/kotlinpoet/FunSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class FunSpec private constructor(builder: Builder) {
codeWriter.emitCode("%L", escapeIfKeyword(name))
}

parameters.emit(codeWriter, wrappable = true) { param ->
parameters.emit(codeWriter) { param ->
param.emit(codeWriter, includeType = name != SETTER)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/squareup/kotlinpoet/LambdaTypeName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class LambdaTypeName internal constructor(
out.emitCode("%T.", it)
}

parameters.emit(out)
parameters.emit(out, wrap = false)
out.emitCode(" -> %T", returnType)

if (nullable) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/squareup/kotlinpoet/ParameterSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ class ParameterSpec private constructor(builder: ParameterSpec.Builder) {

internal fun List<ParameterSpec>.emit(
codeWriter: CodeWriter,
wrappable: Boolean = false,
wrap: Boolean = true,
emitBlock: (ParameterSpec) -> Unit = { it.emit(codeWriter) }
) = with(codeWriter) {
emit("(")
if (wrappable) codeWriter.openWrappingGroup()
if (wrap) codeWriter.openWrappingGroup()
forEachIndexed { index, parameter ->
if (index > 0) if (wrappable) emitCode(",%W") else emit(", ")
if (index > 0) if (wrap) emitCode(",%W") else emit(", ")
emitBlock(parameter)
}
if (wrappable) codeWriter.closeWrappingGroup()
if (wrap) codeWriter.closeWrappingGroup()
emit(")")
}
2 changes: 1 addition & 1 deletion src/main/java/com/squareup/kotlinpoet/TypeSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class TypeSpec private constructor(builder: TypeSpec.Builder) {
codeWriter.emit("constructor")
}

it.parameters.emit(codeWriter, wrappable = true) { param ->
it.parameters.emit(codeWriter) { param ->
val property = constructorProperties[param.name]
if (property != null) {
property.emit(codeWriter, setOf(PUBLIC), withInitializer = false, inline = true)
Expand Down

0 comments on commit a5e5eb0

Please sign in to comment.