diff options
author | Florian Enner <florian@hebirobotics.com> | 2020-01-04 18:10:32 +0100 |
---|---|---|
committer | Egor Andreevich <egor@squareup.com> | 2020-01-04 12:10:32 -0500 |
commit | 25d19845b866c04a2fb3e11ce3d43ccb2e7b98cd (patch) | |
tree | 2c753f13b9d5b62b2c99c58f426e722c25dabe4b /src/main/java/com | |
parent | 3d65852a482185e464c4986b862394691ac197da (diff) | |
download | javapoet-25d19845b866c04a2fb3e11ce3d43ccb2e7b98cd.tar.gz |
added convenience overloads for code blocks in control flow (#752)
* added convenience overloads for code blocks in control flow
* added javadoc and test
* added test for do while block
* fixed continuation space count
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/squareup/javapoet/MethodSpec.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/com/squareup/javapoet/MethodSpec.java b/src/main/java/com/squareup/javapoet/MethodSpec.java index 2f9be0e..67722c7 100644 --- a/src/main/java/com/squareup/javapoet/MethodSpec.java +++ b/src/main/java/com/squareup/javapoet/MethodSpec.java @@ -475,6 +475,14 @@ public final class MethodSpec { } /** + * @param codeBlock the control flow construct and its code, such as "if (foo == 5)". + * Shouldn't contain braces or newline characters. + */ + public Builder beginControlFlow(CodeBlock codeBlock) { + return beginControlFlow("$L", codeBlock); + } + + /** * @param controlFlow the control flow construct and its code, such as "else if (foo == 10)". * Shouldn't contain braces or newline characters. */ @@ -483,6 +491,14 @@ public final class MethodSpec { return this; } + /** + * @param codeBlock the control flow construct and its code, such as "else if (foo == 10)". + * Shouldn't contain braces or newline characters. + */ + public Builder nextControlFlow(CodeBlock codeBlock) { + return nextControlFlow("$L", codeBlock); + } + public Builder endControlFlow() { code.endControlFlow(); return this; @@ -497,6 +513,14 @@ public final class MethodSpec { return this; } + /** + * @param codeBlock the optional control flow construct and its code, such as + * "while(foo == 20)". Only used for "do/while" control flows. + */ + public Builder endControlFlow(CodeBlock codeBlock) { + return endControlFlow("$L", codeBlock); + } + public Builder addStatement(String format, Object... args) { code.addStatement(format, args); return this; |