Skip to content

Commit fca022e

Browse files
praihanfacebook-github-bot
authored andcommitted
Use whisker for java
Summary: Whisker is a replacement for mustache and is largely backward compatible. It brings several quality of life improvements like... error checking. You can read more about the details [in this post](https://fb.workplace.com/groups/498666380550247/permalink/2051389461944590/). This diff moves `t_mstch_java_generator` to use whisker instead of mstch. This requires some changes to the templates to work around the bugs in mstch that have been previously worked around. #buildall Reviewed By: iahs Differential Revision: D67874968 fbshipit-source-id: 6267cd0ed3c04360241fb3f9b45e6f90b3278142
1 parent 664bf62 commit fca022e

File tree

184 files changed

+9018
-10095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+9018
-10095
lines changed

third-party/thrift/src/thrift/compiler/generate/t_mstch_java_generator.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ class t_mstch_java_generator : public t_mstch_generator {
159159
public:
160160
using t_mstch_generator::t_mstch_generator;
161161

162+
std::optional<whisker_options> use_whisker() const override {
163+
whisker_options opts;
164+
opts.allowed_undefined_variables = {
165+
"type:typedef_type", // in UnionWrite.mustache
166+
"struct:isUnion?", // in WriteResponseType.mustache
167+
"struct:asBean?", // in DefaultValue.mustache
168+
"field:hasAdapter?", // in BoxedType.mustache
169+
};
170+
return opts;
171+
}
172+
162173
std::string template_prefix() const override { return "java"; }
163174

164175
void generate_program() override;

third-party/thrift/src/thrift/compiler/generate/templates/java/ReactiveAsyncWrapper.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{> AutoGenerated}}
1919

2020
package {{service:javaPackage}};
21-
{{#service:disableReactive?}}// Generation of this class is disabled using (java.swift.disable_reactive){{/service:disableReactive?}}{{^service:disableReactive?}}
21+
2222
import java.util.*;
2323

2424
public class {{service:javaCapitalName}}ReactiveAsyncWrapper {{#service:extends}} extends {{service:javaPackage}}.{{service:javaCapitalName}}ReactiveAsyncWrapper{{/service:extends}}
@@ -95,4 +95,3 @@ public class {{service:javaCapitalName}}ReactiveAsyncWrapper {{#service:extends}
9595
{{/last?}}
9696
{{/service:interactions}}
9797
}
98-
{{/service:disableReactive?}}

third-party/thrift/src/thrift/compiler/generate/templates/java/ReactiveBlockingWrapper.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{> AutoGenerated}}
1919

2020
package {{service:javaPackage}};
21-
{{#service:disableReactive?}}// Generation of this class is disabled using (java.swift.disable_reactive){{/service:disableReactive?}}{{^service:disableReactive?}}
21+
2222
import java.util.*;
2323

2424
public class {{service:javaCapitalName}}ReactiveBlockingWrapper {{#service:extends}} extends {{service:javaPackage}}.{{service:javaCapitalName}}ReactiveBlockingWrapper{{/service:extends}}
@@ -94,4 +94,3 @@ public class {{service:javaCapitalName}}ReactiveBlockingWrapper {{#service:exten
9494
{{/last?}}
9595
{{/service:interactions}}
9696
}
97-
{{/service:disableReactive?}}

third-party/thrift/src/thrift/compiler/generate/templates/java/struct/StructBuilder.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class Builder {
2727
{{#field:isSensitive?}}
2828
@org.apache.thrift.annotations.Sensitive
2929
{{/field:isSensitive?}}
30-
{{> ThriftFieldAnnotation}}{{#field:javaAnnotation?}} @{{field:javaAnnotation}}{{/field:javaAnnotation?}}
30+
{{> ThriftFieldAnnotation}}
3131
{{#field:hasWrapper?}}
3232
public Builder {{> SetterName}}({{field:wrapperType}} {{field:javaName}}) {
3333
this.{{field:javaName}} = {{field:javaName}};

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/java/gen-java/test/fixtures/adapter/A.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public A(
2828
}
2929

3030

31-
31+
3232
public static Builder builder() {
3333
return new Builder();
3434
}
@@ -50,7 +50,7 @@ public A build() {
5050
return result;
5151
}
5252
}
53-
53+
5454
public static final Map<String, Integer> NAMES_TO_IDS = new HashMap<>();
5555
public static final Map<String, Integer> THRIFT_NAMES_TO_IDS = new HashMap<>();
5656
public static final Map<Integer, TField> FIELD_METADATA = new HashMap<>();
@@ -65,7 +65,7 @@ public String toString() {
6565
ToStringHelper helper = toStringHelper(this);
6666
return helper.toString();
6767
}
68-
68+
6969
@java.lang.Override
7070
public boolean equals(java.lang.Object o) {
7171
if (this == o) {
@@ -80,13 +80,13 @@ public boolean equals(java.lang.Object o) {
8080
return
8181
true;
8282
}
83-
83+
8484
@java.lang.Override
8585
public int hashCode() {
8686
return Arrays.deepHashCode(new java.lang.Object[] {
8787
});
8888
}
89-
89+
9090

9191
public static com.facebook.thrift.payload.Reader<A> asReader() {
9292
return A::read0;
@@ -109,13 +109,13 @@ public static A read0(TProtocol oprot) throws TException {
109109
oprot.readStructEnd();
110110
return builder.build();
111111
}
112-
112+
113113
public void write0(TProtocol oprot) throws TException {
114114
oprot.writeStructBegin(STRUCT_DESC);
115115
oprot.writeFieldStop();
116116
oprot.writeStructEnd();
117117
}
118-
118+
119119
private static class _ALazy {
120120
private static final A _DEFAULT = new A.Builder().build();
121121
}

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/java/gen-java/test/fixtures/adapter/AdaptTemplatedNestedTestStruct.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public AdaptTemplatedNestedTestStruct(
3333
protected AdaptTemplatedNestedTestStruct() {
3434
this.adaptedStruct = null;
3535
}
36-
36+
3737
public static Builder builder() {
3838
return new Builder();
3939
}
@@ -45,8 +45,7 @@ public static Builder builder(AdaptTemplatedNestedTestStruct other) {
4545
public static class Builder {
4646
private test.fixtures.adapter.AdaptTemplatedTestStruct adaptedStruct = null;
4747

48-
@com.facebook.swift.codec.ThriftField(value=1, name="adaptedStruct", requiredness=Requiredness.NONE)
49-
public Builder setAdaptedStruct(test.fixtures.adapter.AdaptTemplatedTestStruct adaptedStruct) {
48+
@com.facebook.swift.codec.ThriftField(value=1, name="adaptedStruct", requiredness=Requiredness.NONE) public Builder setAdaptedStruct(test.fixtures.adapter.AdaptTemplatedTestStruct adaptedStruct) {
5049
this.adaptedStruct = adaptedStruct;
5150
return this;
5251
}
@@ -66,7 +65,7 @@ public AdaptTemplatedNestedTestStruct build() {
6665
return result;
6766
}
6867
}
69-
68+
7069
public static final Map<String, Integer> NAMES_TO_IDS = new HashMap<>();
7170
public static final Map<String, Integer> THRIFT_NAMES_TO_IDS = new HashMap<>();
7271
public static final Map<Integer, TField> FIELD_METADATA = new HashMap<>();
@@ -86,14 +85,14 @@ public AdaptTemplatedNestedTestStruct build() {
8685
@Nullable
8786
@com.facebook.swift.codec.ThriftField(value=1, name="adaptedStruct", requiredness=Requiredness.NONE)
8887
public test.fixtures.adapter.AdaptTemplatedTestStruct getAdaptedStruct() { return adaptedStruct; }
89-
88+
9089
@java.lang.Override
9190
public String toString() {
9291
ToStringHelper helper = toStringHelper(this);
9392
helper.add("adaptedStruct", adaptedStruct);
9493
return helper.toString();
9594
}
96-
95+
9796
@java.lang.Override
9897
public boolean equals(java.lang.Object o) {
9998
if (this == o) {
@@ -109,14 +108,14 @@ public boolean equals(java.lang.Object o) {
109108
Objects.equals(adaptedStruct, other.adaptedStruct) &&
110109
true;
111110
}
112-
111+
113112
@java.lang.Override
114113
public int hashCode() {
115114
return Arrays.deepHashCode(new java.lang.Object[] {
116115
adaptedStruct
117116
});
118117
}
119-
118+
120119

121120
public static com.facebook.thrift.payload.Reader<AdaptTemplatedNestedTestStruct> asReader() {
122121
return AdaptTemplatedNestedTestStruct::read0;
@@ -147,7 +146,7 @@ public static AdaptTemplatedNestedTestStruct read0(TProtocol oprot) throws TExce
147146
oprot.readStructEnd();
148147
return builder.build();
149148
}
150-
149+
151150
public void write0(TProtocol oprot) throws TException {
152151
oprot.writeStructBegin(STRUCT_DESC);
153152
if (adaptedStruct != null) {
@@ -158,7 +157,7 @@ public void write0(TProtocol oprot) throws TException {
158157
oprot.writeFieldStop();
159158
oprot.writeStructEnd();
160159
}
161-
160+
162161
private static class _AdaptTemplatedNestedTestStructLazy {
163162
private static final AdaptTemplatedNestedTestStruct _DEFAULT = new AdaptTemplatedNestedTestStruct.Builder().build();
164163
}

0 commit comments

Comments
 (0)