Skip to content
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

Merged
merged 14 commits into from
Mar 7, 2019
Merged

Remove auto value #159

merged 14 commits into from
Mar 7, 2019

Conversation

RicoYao
Copy link
Contributor

@RicoYao RicoYao commented Feb 15, 2019

Removes the use of AutoValue

  • Implement Builder pattern on our own.

Add ability to merge models.

@rahul-malik
Copy link
Collaborator

PR is looking good, mind running “make integration_test” to update the java fixtures in the repo and updating your PR?

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" +
Copy link
Collaborator

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

Copy link
Contributor Author

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.


func renderBuilderMerge() -> JavaIR.Method {
let body = (self.transitiveProperties.map { param, _ in
"if (model.get" + param.snakeCaseToCapitalizedPropertyName() + "IsSet()) {\n" +
Copy link
Collaborator

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?

Copy link
Contributor Author

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();",
Copy link
Collaborator

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 ...”

Copy link
Contributor Author

@RicoYao RicoYao Mar 6, 2019

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.

Copy link
Collaborator

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

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)") {[
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same response as before.

@RicoYao
Copy link
Contributor Author

RicoYao commented Mar 6, 2019

"mind running “make integration_test” to update the java fixtures in the repo and updating your PR?"
-- done

@rahul-malik
Copy link
Collaborator

rahul-malik commented Mar 6, 2019

Will review soon, also I filed this to track actually building the java code during integration tests
#169

return false;
}
Board that = (Board) o;
return Objects.equals(this.identifier, that.identifier) &&
Copy link
Collaborator

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

Copy link
Collaborator

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() {
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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).

Sources/Core/JavaIR.swift Outdated Show resolved Hide resolved
Examples/Java/Sources/Image.java Outdated Show resolved Hide resolved
@rahul-malik
Copy link
Collaborator

@RicoYao - Please take a look at the comments and let me know what you think

@RicoYao
Copy link
Contributor Author

RicoYao commented Mar 7, 2019

@rahul-malik Replied in-line.

@SerializedName("name") private @Nullable String name;
@SerializedName("url") private @Nullable String url;
private int _bits = 0;
private Builder() {
Copy link
Collaborator

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) &&
Copy link
Collaborator

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

@rahul-malik
Copy link
Collaborator

@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 rahul-malik merged commit 7d17623 into pinterest:master Mar 7, 2019
@RicoYao
Copy link
Contributor Author

RicoYao commented Mar 7, 2019

@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.

@rahul-malik
Copy link
Collaborator

@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

@RicoYao
Copy link
Contributor Author

RicoYao commented Mar 8, 2019

@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!

@RicoYao
Copy link
Contributor Author

RicoYao commented Mar 8, 2019

@rahul-malik Also, just FYI, I'd been loading a Plank-generated model into diff D360909 for a compilation check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants