diff options
author | Jesse Wilson <jesse@swank.ca> | 2018-01-26 23:28:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-26 23:28:30 -0500 |
commit | c6dd69cb207812493ca7675ea7a9abe64c2f4f98 (patch) | |
tree | f262fde094b55ddcddf5acb32a5504308040581a /src | |
parent | 9e62955dc41e331f14b00e9f7d16dabff45884b0 (diff) | |
download | javapoet-c6dd69cb207812493ca7675ea7a9abe64c2f4f98.tar.gz |
Use $Z in method parameter lists. (#605)
Now we wrap automatically after the method name, if appropriate.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/squareup/javapoet/LineWrapper.java | 8 | ||||
-rw-r--r-- | src/main/java/com/squareup/javapoet/MethodSpec.java | 4 | ||||
-rw-r--r-- | src/test/java/com/squareup/javapoet/MethodSpecTest.java | 8 |
3 files changed, 9 insertions, 11 deletions
diff --git a/src/main/java/com/squareup/javapoet/LineWrapper.java b/src/main/java/com/squareup/javapoet/LineWrapper.java index 3ebaf70..5c9ae74 100644 --- a/src/main/java/com/squareup/javapoet/LineWrapper.java +++ b/src/main/java/com/squareup/javapoet/LineWrapper.java @@ -40,8 +40,8 @@ final class LineWrapper { */ private int indentLevel = -1; - /** {@code null} if we have no buffering; otherwise the type to pass to the next call to {@link - * #flush(FlushType)}. + /** + * Null if we have no buffering; otherwise the type to pass to the next call to {@link #flush}. */ private FlushType nextFlush; @@ -84,7 +84,7 @@ final class LineWrapper { if (closed) throw new IllegalStateException("closed"); if (this.nextFlush != null) flush(nextFlush); - column++; // increment the column even though the space is deferred to next call to flush() + column++; // Increment the column even though the space is deferred to next call to flush(). this.nextFlush = FlushType.SPACE; this.indentLevel = indentLevel; } @@ -93,8 +93,6 @@ final class LineWrapper { void zeroWidthSpace(int indentLevel) throws IOException { if (closed) throw new IllegalStateException("closed"); - // DO NOT SUBMIT: multiple zero-width chars in a row - should that cause a flush? - // What about if the nextFlush is a SPACE? if (this.nextFlush != null) flush(nextFlush); this.nextFlush = FlushType.EMPTY; this.indentLevel = indentLevel; diff --git a/src/main/java/com/squareup/javapoet/MethodSpec.java b/src/main/java/com/squareup/javapoet/MethodSpec.java index bff9341..0073445 100644 --- a/src/main/java/com/squareup/javapoet/MethodSpec.java +++ b/src/main/java/com/squareup/javapoet/MethodSpec.java @@ -91,9 +91,9 @@ public final class MethodSpec { } if (isConstructor()) { - codeWriter.emit("$L(", enclosingName); + codeWriter.emit("$L($Z", enclosingName); } else { - codeWriter.emit("$T $L(", returnType, name); + codeWriter.emit("$T $L($Z", returnType, name); } boolean firstParameter = true; diff --git a/src/test/java/com/squareup/javapoet/MethodSpecTest.java b/src/test/java/com/squareup/javapoet/MethodSpecTest.java index 9a4cde0..1a7205c 100644 --- a/src/test/java/com/squareup/javapoet/MethodSpecTest.java +++ b/src/test/java/com/squareup/javapoet/MethodSpecTest.java @@ -120,7 +120,7 @@ public final class MethodSpecTest { interface ExtendsOthers extends Callable<Integer>, Comparable<ExtendsOthers> { } - + interface ExtendsIterableWithDefaultMethods extends Iterable<Object> { } @@ -131,9 +131,9 @@ public final class MethodSpecTest { assertThat(method.toString()).isEqualTo("" + "@java.lang.Override\n" + "protected <T extends java.lang.Runnable & java.io.Closeable> java.lang.Runnable " - + "everything(java.lang.String arg0,\n" - + " java.util.List<? extends T> arg1) throws java.io.IOException, " - + "java.lang.SecurityException {\n" + + "everything(\n" + + " java.lang.String arg0, java.util.List<? extends T> arg1) throws java.io.IOException,\n" + + " java.lang.SecurityException {\n" + "}\n"); } |