Skip to content

Commit

Permalink
Add a static TYPE variable to java models
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoYao committed May 15, 2019
1 parent bdd00b0 commit f4bc9ee
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class Board {

public static final String TYPE = "board";

@SerializedName("id") private @Nullable String uid;
@SerializedName("contributors") private @Nullable Set<User> contributors;
@SerializedName("counts") private @Nullable Map<String, Integer> counts;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Everything.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public enum EverythingStringEnum {
@SerializedName("case1") CASE1, @SerializedName("case2") CASE2, @SerializedName("case3") CASE3;
}

public static final String TYPE = "everything";

@SerializedName("array_prop") private @Nullable List<Object> arrayProp;
@SerializedName("boolean_prop") private @Nullable Boolean booleanProp;
@SerializedName("date_prop") private @Nullable Date dateProp;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class Image {

public static final String TYPE = "image";

@SerializedName("height") private @Nullable Integer height;
@SerializedName("url") private @Nullable String url;
@SerializedName("width") private @Nullable Integer width;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class Model {

public static final String TYPE = "model";

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

static final private int ID_SET = 1 << 0;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/Pin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public int getValue() {
}
}

public static final String TYPE = "pin";

@SerializedName("attribution") private @Nullable Map<String, String> attribution;
@SerializedName("attribution_objects") private @Nullable List<PinAttributionObjects> attributionObjects;
@SerializedName("board") private @Nullable Board board;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public enum UserEmailFrequency {
@SerializedName("unset") UNSET, @SerializedName("immediate") IMMEDIATE, @SerializedName("daily") DAILY;
}

public static final String TYPE = "user";

@SerializedName("bio") private @Nullable String bio;
@SerializedName("counts") private @Nullable Map<String, Integer> counts;
@SerializedName("created_at") private @Nullable Date createdAt;
Expand Down
2 changes: 2 additions & 0 deletions Examples/Java/Sources/VariableSubtitution.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

public class VariableSubtitution {

public static final String TYPE = "variable_subtitution";

@SerializedName("alloc_prop") private @Nullable Integer allocProp;
@SerializedName("copy_prop") private @Nullable Integer copyProp;
@SerializedName("mutable_copy_prop") private @Nullable Integer mutableCopyProp;
Expand Down
6 changes: 5 additions & 1 deletion Sources/Core/JavaModelRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public struct JavaModelRenderer: JavaFileRenderer {
}
}

func renderStaticTypeString() -> JavaIR.Property {
return JavaIR.Property(annotations: [], modifiers: [.public, .static, .final], type: "String", name: "TYPE", initialValue: "\"" + rootSchema.typeIdentifier + "\"")
}

func renderModelHashCode() -> JavaIR.Method {
let bodyHashCode = transitiveProperties.map { param, _ in
Languages.java.snakeCaseToPropertyName(param)
Expand Down Expand Up @@ -73,7 +77,7 @@ public struct JavaModelRenderer: JavaFileRenderer {
index += 1
}

return [props, bitmasks, [bits]]
return [[renderStaticTypeString()], props, bitmasks, [bits]]
}

func propertyGetterForParam(param: String, schemaObj: SchemaObjectProperty) -> JavaIR.Method {
Expand Down

0 comments on commit f4bc9ee

Please sign in to comment.