-
Notifications
You must be signed in to change notification settings - Fork 43
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
Remove auto value #159
Remove auto value #159
Conversation
PR is looking good, mind running “make integration_test” to update the java fixtures in the repo and updating your PR? |
Sources/Core/JavaModelRenderer.swift
Outdated
func renderBuilderMerge() -> JavaIR.Method { | ||
let body = (self.transitiveProperties.map { param, _ in | ||
"if (model.get" + param.snakeCaseToCapitalizedPropertyName() + "IsSet()) {\n" + | ||
" this." + param.snakeCaseToPropertyName() + " = model." + param.snakeCaseToPropertyName() + ";\n" + |
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.
We generally don’t indent generated code like this throughout the repository. Ok general we rely on the “—>” operator to indent a scoped region.
The reason is because we insert tabs and then post process them out to whatever the correct tabwidth is per language
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.
Done (I used --> in the ifBLock method that you asked me to add in your other comment). I also switched over the other if-statements in this PR to use it.
Sources/Core/JavaModelRenderer.swift
Outdated
|
||
func renderBuilderMerge() -> JavaIR.Method { | ||
let body = (self.transitiveProperties.map { param, _ in | ||
"if (model.get" + param.snakeCaseToCapitalizedPropertyName() + "IsSet()) {\n" + |
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.
Can we add a JavaIR.if method and use it here?
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.
Done. I had to call it ifBlock because just "if" wasn't allowed.
"return new AutoValue_\(className).GsonTypeAdapter(gson);" | ||
func renderModelMergeWith() -> JavaIR.Method { | ||
return JavaIR.method([.public], self.className + " mergeWith(" + self.className + " model)") {[ | ||
self.className + ".Builder builder = this.toBuilder();", |
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.
FYI you can use string interpolation in swift to inline simple strings line this
“(self.className).Builder ...”
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.
I can switch the whole thing over if you feel strongly, but I really found it hard to read/code particularly because of the need to include a "\". I spoke to some in-house iOS folks who seemed to feel that concatenation through + was fine.
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.
I think as long as we're not executing functions inside \()
, for simple strings this is a bit easier to read but that's just my opinion. I'd prefer that they were using string interpolation for simple strings
Sources/Core/JavaModelRenderer.swift
Outdated
return JavaIR.method([.public, .static], "TypeAdapter<\(className)> jsonAdapter(Gson gson)") {[ | ||
"return new AutoValue_\(className).GsonTypeAdapter(gson);" | ||
func renderModelMergeWith() -> JavaIR.Method { | ||
return JavaIR.method([.public], self.className + " mergeWith(" + self.className + " model)") {[ |
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.
String interpolation for the method name as well
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.
Same response as before.
"mind running “make integration_test” to update the java fixtures in the repo and updating your PR?" |
- Remove autovalue annotations/imports - Add builder class
Use --> instead of custom indentation Create JavaIR.ifBlock
b793e4e
to
9d8f956
Compare
Will review soon, also I filed this to track actually building the java code during integration tests |
return false; | ||
} | ||
Board that = (Board) o; | ||
return Objects.equals(this.identifier, that.identifier) && |
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.
For later, in ObjC we sorted the equality comparisons to compare primitive properties first since that was a bit faster
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.
I'll file a ticket for this as well
@SerializedName("name") private @Nullable String name; | ||
@SerializedName("url") private @Nullable String url; | ||
private int _bits = 0; | ||
private Builder() { |
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.
Do we need an empty builder init here?
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.
It's not a hard requirement right now (creating a Model from scratch), but I'm about to introduce a custom GSON TypeAdapter that goes through the Builder (so that we properly set _bits), and it will use this.
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.
Is there anything proprietary about this adapter? If it’s pretty general it would be useful to include here for others to utilize.
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.
@RicoYao - We can resolve this in a follow-up. I'll file an issue
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.
@rahul-malik Sorry I should have been more clear, the plan is to submit the TypeAdapter into the master branch (working on the pull request).
@RicoYao - Please take a look at the comments and let me know what you think |
@rahul-malik Replied in-line. |
@SerializedName("name") private @Nullable String name; | ||
@SerializedName("url") private @Nullable String url; | ||
private int _bits = 0; | ||
private Builder() { |
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.
@RicoYao - We can resolve this in a follow-up. I'll file an issue
return false; | ||
} | ||
Board that = (Board) o; | ||
return Objects.equals(this.identifier, that.identifier) && |
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.
I'll file a ticket for this as well
@RicoYao - I'll merge this now, can you get yourself added to the Pinterest Github Organization so I can assign you tasks? The #opensource room should be able to help :) |
@rahul-malik Thanks, I didn't realize you would actually merge it, but it's helpful so I can work on smaller follow-up pull requests. Please check in before producing a release though, as I'd want to run some extra tests. |
@RicoYao Yeah I think it was far enough along where it should be merged, I wanted to merge it so I could look into actually building the code. We'll work together before drafting a release candidate which will involve actually having these models building as part of CI That said, I did notice an issue when I tried to compile some of the code in the private initializers #174 |
@rahul-malik I think I broke it in my very last commit when I was trying to fix the tabbing. I normally test it in my Java IDE, but forgot on the last one. Will fix. Thanks! |
@rahul-malik Also, just FYI, I'd been loading a Plank-generated model into diff D360909 for a compilation check. |
Removes the use of AutoValue
Add ability to merge models.