New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding configurable indent #198
Conversation
CI was broken. Kicking it. |
This is a very heavyweight API for a relatively lightweight concept. JavaWriter just took a string for the indent. |
This also doesn't allow using tabs which someone might want. |
Yeah, I think we want to just accept a string: By the way: what indent are you using? |
You are right. I missed new JavaPoet(new Indent().space(2));
new JavaPoet(new Indent().tab(1));
// or
new JavaPoet(new Indent().tab()); Would it be acceptable? I didn't implemented something like:
because in first case, you don't know how many spaces are there just by looking at the source code and you don't know that this argument is used for indent before checking documentation. |
Is there a valid use case for non-space-or-tab indents? |
@kenzierocks If I hate my coworkers: @pwittchen Having a dedicated |
I think this is too much API for something so unimportant. What about just this:
|
Only downside is that's the only mutable part of the library. That said,
|
I've updated code. Now, API looks as @swankjesse proposed: JavaPoet javaPoet = new JavaPoet();
javaPoet.setIndent(" "); Drawback of this solution is the fact that |
@@ -49,7 +49,8 @@ | |||
* honors imports, indentation, and deferred variable names. | |||
*/ | |||
final class CodeWriter { | |||
private final String indent = " "; | |||
public static final String DEFAULT_INDENT = " "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this private.
Sorry about being so picky here. The JavaPoet / JavaFile / CodeWriter code is not structured the way we want it to be in order to make manipulating display-stuff in JavaPoet easy. And that means the advice I gave about adding accessors to JavaPoet makes little sense. What I want is accessors on JavaPoet, and then to change |
I've updated code according to your comments. |
@@ -47,13 +47,17 @@ private JavaFile(Builder builder) { | |||
} | |||
|
|||
public void emit(Appendable out) throws IOException { | |||
emit(out, " "); //TODO(pwittchen): this call is made because of toString() and can be improved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just hardcode toString()
to call the emit overload with " "
. That's reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just hardcode toString()
to call the emit overload with " "
. That's reasonable.
Thanks for your patience. Two last nitpicks & I'm eager to merge this. |
Also: please https://rebaseandsqua.sh |
e5799d0
to
18c8153
Compare
I've done the following things:
I hope, now everything is fine :-). |
this.out = checkNotNull(out); | ||
this.indent = checkNotNull(indent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Woohoo! |
Hi,
I have added configurable indent. It solves issue #106 . Indent can be configured in
JavaPoet
class (oldJavaWriter
class). Exemplary usage of the configurable indent is presented in the following code snippet:In addition, I've added appropriate Unit Tests verifying behavior of the library with new functionality.
I wanted to make code clean and as abstract as possible.
I hope it would be useful for you.
Regards,
Piotr