Skip to content

Commit

Permalink
Don't use ObjectiveC-based handling of reserved keywords for Java (#187)
Browse files Browse the repository at this point in the history
- Java has its own set of different reserved keywords.

- Also use a "uid" property name for "id" (ObjC uses "identifier). This is pinterest-specific and we may have to add in a custom override for this instead later.

- Move snakeCaseToPropertyName/CapitalizaedPropertyName/CamelCase into Languages enum

- Remove StringExtension methods that are now in Languages. Fixed a few stragglers. make format/lint.

- Add tests for renaming of "id" fields in java and objC

- Add linux test indexes (`make build_test_index_linux`)
  • Loading branch information
RicoYao authored and rahul-malik committed Mar 20, 2019
1 parent 2dd9ed8 commit 5e5ed22
Show file tree
Hide file tree
Showing 26 changed files with 1,172 additions and 1,370 deletions.
68 changes: 34 additions & 34 deletions Examples/Java/Sources/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

public class Board {

@SerializedName("id") private @Nullable String identifier;
@SerializedName("id") private @Nullable String uid;
@SerializedName("contributors") private @Nullable Set<User> contributors;
@SerializedName("counts") private @Nullable Map<String, Integer> counts;
@SerializedName("created_at") private @Nullable Date createdAt;
@SerializedName("creator") private @Nullable Map<String, String> creator;
@SerializedName("description") private @Nullable String descriptionText;
@SerializedName("description") private @Nullable String description;
@SerializedName("image") private @NonNull Image image;
@SerializedName("name") private @Nullable String name;
@SerializedName("url") private @Nullable String url;
Expand All @@ -53,23 +53,23 @@ public class Board {
private int _bits = 0;

private Board(
@Nullable String identifier,
@Nullable String uid,
@Nullable Set<User> contributors,
@Nullable Map<String, Integer> counts,
@Nullable Date createdAt,
@Nullable Map<String, String> creator,
@Nullable String descriptionText,
@Nullable String description,
@NonNull Image image,
@Nullable String name,
@Nullable String url,
int _bits
) {
this.identifier = identifier;
this.uid = uid;
this.contributors = contributors;
this.counts = counts;
this.createdAt = createdAt;
this.creator = creator;
this.descriptionText = descriptionText;
this.description = description;
this.image = image;
this.name = name;
this.url = url;
Expand Down Expand Up @@ -99,32 +99,32 @@ public boolean equals(Object o) {
return false;
}
Board that = (Board) o;
return Objects.equals(this.identifier, that.identifier) &&
return Objects.equals(this.uid, that.uid) &&
Objects.equals(this.contributors, that.contributors) &&
Objects.equals(this.counts, that.counts) &&
Objects.equals(this.createdAt, that.createdAt) &&
Objects.equals(this.creator, that.creator) &&
Objects.equals(this.descriptionText, that.descriptionText) &&
Objects.equals(this.description, that.description) &&
Objects.equals(this.image, that.image) &&
Objects.equals(this.name, that.name) &&
Objects.equals(this.url, that.url);
}

@Override
public int hashCode() {
return Objects.hash(identifier,
return Objects.hash(uid,
contributors,
counts,
createdAt,
creator,
descriptionText,
description,
image,
name,
url);
}

public @Nullable String getIdentifier() {
return this.identifier;
public @Nullable String getUid() {
return this.uid;
}

public @Nullable Set<User> getContributors() {
Expand All @@ -143,8 +143,8 @@ public int hashCode() {
return this.creator;
}

public @Nullable String getDescriptionText() {
return this.descriptionText;
public @Nullable String getDescription() {
return this.description;
}

public @NonNull Image getImage() {
Expand All @@ -159,7 +159,7 @@ public int hashCode() {
return this.url;
}

public boolean getIdentifierIsSet() {
public boolean getUidIsSet() {
return (this._bits & ID_SET) == ID_SET;
}

Expand All @@ -179,7 +179,7 @@ public boolean getCreatorIsSet() {
return (this._bits & CREATOR_SET) == CREATOR_SET;
}

public boolean getDescriptionTextIsSet() {
public boolean getDescriptionIsSet() {
return (this._bits & DESCRIPTION_SET) == DESCRIPTION_SET;
}

Expand All @@ -197,12 +197,12 @@ public boolean getUrlIsSet() {

public static class Builder {

@SerializedName("id") private @Nullable String identifier;
@SerializedName("id") private @Nullable String uid;
@SerializedName("contributors") private @Nullable Set<User> contributors;
@SerializedName("counts") private @Nullable Map<String, Integer> counts;
@SerializedName("created_at") private @Nullable Date createdAt;
@SerializedName("creator") private @Nullable Map<String, String> creator;
@SerializedName("description") private @Nullable String descriptionText;
@SerializedName("description") private @Nullable String description;
@SerializedName("image") private @NonNull Image image;
@SerializedName("name") private @Nullable String name;
@SerializedName("url") private @Nullable String url;
Expand All @@ -213,20 +213,20 @@ private Builder() {
}

private Builder(@NonNull Board model) {
this.identifier = model.identifier;
this.uid = model.uid;
this.contributors = model.contributors;
this.counts = model.counts;
this.createdAt = model.createdAt;
this.creator = model.creator;
this.descriptionText = model.descriptionText;
this.description = model.description;
this.image = model.image;
this.name = model.name;
this.url = model.url;
this._bits = model._bits;
}

public Builder setIdentifier(@Nullable String value) {
this.identifier = value;
public Builder setUid(@Nullable String value) {
this.uid = value;
this._bits |= ID_SET;
return this;
}
Expand Down Expand Up @@ -255,8 +255,8 @@ public Builder setCreator(@Nullable Map<String, String> value) {
return this;
}

public Builder setDescriptionText(@Nullable String value) {
this.descriptionText = value;
public Builder setDescription(@Nullable String value) {
this.description = value;
this._bits |= DESCRIPTION_SET;
return this;
}
Expand All @@ -279,8 +279,8 @@ public Builder setUrl(@Nullable String value) {
return this;
}

public @Nullable String getIdentifier() {
return this.identifier;
public @Nullable String getUid() {
return this.uid;
}

public @Nullable Set<User> getContributors() {
Expand All @@ -299,8 +299,8 @@ public Builder setUrl(@Nullable String value) {
return this.creator;
}

public @Nullable String getDescriptionText() {
return this.descriptionText;
public @Nullable String getDescription() {
return this.description;
}

public @NonNull Image getImage() {
Expand All @@ -317,12 +317,12 @@ public Builder setUrl(@Nullable String value) {

public Board build() {
return new Board(
this.identifier,
this.uid,
this.contributors,
this.counts,
this.createdAt,
this.creator,
this.descriptionText,
this.description,
this.image,
this.name,
this.url,
Expand All @@ -331,8 +331,8 @@ public Board build() {
}

public void mergeFrom(Board model) {
if (model.getIdentifierIsSet()) {
this.identifier = model.identifier;
if (model.getUidIsSet()) {
this.uid = model.uid;
}
if (model.getContributorsIsSet()) {
this.contributors = model.contributors;
Expand All @@ -346,8 +346,8 @@ public void mergeFrom(Board model) {
if (model.getCreatorIsSet()) {
this.creator = model.creator;
}
if (model.getDescriptionTextIsSet()) {
this.descriptionText = model.descriptionText;
if (model.getDescriptionIsSet()) {
this.description = model.description;
}
if (model.getImageIsSet()) {
this.image = model.image;
Expand Down
34 changes: 17 additions & 17 deletions Examples/Java/Sources/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@

public class Model {

@SerializedName("id") private @Nullable String identifier;
@SerializedName("id") private @Nullable String uid;

static final private int ID_SET = 1 << 0;

private int _bits = 0;

private Model(
@Nullable String identifier,
@Nullable String uid,
int _bits
) {
this.identifier = identifier;
this.uid = uid;
this._bits = _bits;
}

Expand All @@ -67,56 +67,56 @@ public boolean equals(Object o) {
return false;
}
Model that = (Model) o;
return Objects.equals(this.identifier, that.identifier);
return Objects.equals(this.uid, that.uid);
}

@Override
public int hashCode() {
return Objects.hash(identifier);
return Objects.hash(uid);
}

public @Nullable String getIdentifier() {
return this.identifier;
public @Nullable String getUid() {
return this.uid;
}

public boolean getIdentifierIsSet() {
public boolean getUidIsSet() {
return (this._bits & ID_SET) == ID_SET;
}

public static class Builder {

@SerializedName("id") private @Nullable String identifier;
@SerializedName("id") private @Nullable String uid;

private int _bits = 0;

private Builder() {
}

private Builder(@NonNull Model model) {
this.identifier = model.identifier;
this.uid = model.uid;
this._bits = model._bits;
}

public Builder setIdentifier(@Nullable String value) {
this.identifier = value;
public Builder setUid(@Nullable String value) {
this.uid = value;
this._bits |= ID_SET;
return this;
}

public @Nullable String getIdentifier() {
return this.identifier;
public @Nullable String getUid() {
return this.uid;
}

public Model build() {
return new Model(
this.identifier,
this.uid,
this._bits
);
}

public void mergeFrom(Model model) {
if (model.getIdentifierIsSet()) {
this.identifier = model.identifier;
if (model.getUidIsSet()) {
this.uid = model.uid;
}
}
}
Expand Down
Loading

0 comments on commit 5e5ed22

Please sign in to comment.