Skip to content

Commit 50cdf29

Browse files
committed
Make ToXContent return a builder
1 parent 89314f2 commit 50cdf29

File tree

73 files changed

+155
-82
lines changed

Some content is hidden

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

73 files changed

+155
-82
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/analyze/AnalyzeResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public List<AnalyzeToken> getTokens() {
145145
return tokens.iterator();
146146
}
147147

148-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
148+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
149149
String format = params.param("format", "detailed");
150150
if ("detailed".equals(format)) {
151151
builder.startArray("tokens");
@@ -177,6 +177,7 @@ public List<AnalyzeToken> getTokens() {
177177
}
178178
builder.field("tokens", sb);
179179
}
180+
return builder;
180181
}
181182

182183
@Override public void readFrom(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/get/GetResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static final class Fields {
241241
static final XContentBuilderString FIELDS = new XContentBuilderString("fields");
242242
}
243243

244-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
244+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
245245
if (!exists()) {
246246
builder.startObject();
247247
builder.field(Fields._INDEX, index);
@@ -283,6 +283,7 @@ static final class Fields {
283283

284284
builder.endObject();
285285
}
286+
return builder;
286287
}
287288

288289
@Override public void readFrom(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/action/search/SearchResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static final class Fields {
222222
static final XContentBuilderString TIMED_OUT = new XContentBuilderString("timed_out");
223223
}
224224

225-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
225+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
226226
if (scrollId != null) {
227227
builder.field(Fields._SCROLL_ID, scrollId);
228228
}
@@ -249,6 +249,7 @@ static final class Fields {
249249

250250
builder.endObject();
251251
internalResponse.toXContent(builder, params);
252+
return builder;
252253
}
253254

254255
public static SearchResponse readSearchResponse(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public boolean retryable() {
7676
return this.retryable;
7777
}
7878

79-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
79+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
8080
builder.startObject(Integer.toString(id));
8181
builder.field("description", description);
8282
builder.field("retryable", retryable);
@@ -86,6 +86,7 @@ public boolean retryable() {
8686
}
8787
builder.endArray();
8888
builder.endObject();
89+
return builder;
8990
}
9091

9192
public static ClusterBlock readClusterBlock(StreamInput in) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/ToXContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ public MapParams(Map<String, String> params) {
9292
}
9393
}
9494

95-
void toXContent(XContentBuilder builder, Params params) throws IOException;
95+
XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException;
9696
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/AbstractFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,11 @@ protected AbstractFieldMapper(Names names, Field.Index index, Field.Store store,
388388
return FieldDataType.DefaultTypes.STRING;
389389
}
390390

391-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
391+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
392392
builder.startObject(names.name());
393393
doXContentBody(builder);
394394
builder.endObject();
395+
return builder;
395396
}
396397

397398
protected void doXContentBody(XContentBuilder builder) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/AllFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ private Analyzer findAnalyzer(ParseContext context) {
152152
return CONTENT_TYPE;
153153
}
154154

155-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
155+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
156156
// if all are defaults, no need to write it at all
157157
if (enabled == Defaults.ENABLED && store == Defaults.STORE && termVector == Defaults.TERM_VECTOR && indexAnalyzer == null && searchAnalyzer == null) {
158-
return;
158+
return builder;
159159
}
160160
builder.startObject(CONTENT_TYPE);
161161
if (enabled != Defaults.ENABLED) {
@@ -179,6 +179,7 @@ private Analyzer findAnalyzer(ParseContext context) {
179179
}
180180
}
181181
builder.endObject();
182+
return builder;
182183
}
183184

184185
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/AnalyzerMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ public AnalyzerMapper(String path) {
110110
@Override public void traverse(FieldMapperListener fieldMapperListener) {
111111
}
112112

113-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
113+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
114114
if (path.equals(Defaults.PATH)) {
115-
return;
115+
return builder;
116116
}
117117
builder.startObject(CONTENT_TYPE);
118118
if (!path.equals(Defaults.PATH)) {
119119
builder.field("path", path);
120120
}
121121
builder.endObject();
122+
return builder;
122123
}
123124
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/BinaryFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ protected BinaryFieldMapper(Names names) {
9999
return CONTENT_TYPE;
100100
}
101101

102-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
102+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
103103
builder.startObject(names.name());
104104
builder.field("type", contentType());
105105
if (!names.name().equals(names.indexNameClean())) {
106106
builder.field("index_name", names.indexNameClean());
107107
}
108108
builder.endObject();
109+
return builder;
109110
}
110111
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/BoostFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ private float parseFloatValue(ParseContext context) throws IOException {
175175
return CONTENT_TYPE;
176176
}
177177

178-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
178+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
179179
// all are defaults, don't write it at all
180180
if (name().equals(Defaults.NAME) && nullValue == null) {
181-
return;
181+
return builder;
182182
}
183183
builder.startObject(contentType());
184184
if (!name().equals(Defaults.NAME)) {
@@ -188,6 +188,7 @@ private float parseFloatValue(ParseContext context) throws IOException {
188188
builder.field("null_value", nullValue);
189189
}
190190
builder.endObject();
191+
return builder;
191192
}
192193

193194
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IdFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,17 @@ protected IdFieldMapper(String name, String indexName, Field.Store store, Field.
120120
return CONTENT_TYPE;
121121
}
122122

123-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
123+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
124124
// if all are defaults, no sense to write it at all
125125
if (store == Defaults.STORE) {
126-
return;
126+
return builder;
127127
}
128128
builder.startObject(CONTENT_TYPE);
129129
if (store != Defaults.STORE) {
130130
builder.field("store", store.name().toLowerCase());
131131
}
132132
builder.endObject();
133+
return builder;
133134
}
134135

135136
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IndexFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ public IndexFieldMapper(String name, String indexName, Field.Store store, Field.
127127
return CONTENT_TYPE;
128128
}
129129

130-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
130+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
131131
// if all defaults, no need to write it at all
132132
if (store == Defaults.STORE && enabled == Defaults.ENABLED) {
133-
return;
133+
return builder;
134134
}
135135
builder.startObject(CONTENT_TYPE);
136136
if (store != Defaults.STORE) {
@@ -140,6 +140,7 @@ public IndexFieldMapper(String name, String indexName, Field.Store store, Field.
140140
builder.field("enabled", enabled);
141141
}
142142
builder.endObject();
143+
return builder;
143144
}
144145

145146
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/MultiFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public ImmutableMap<String, XContentMapper> mappers() {
263263
}
264264
}
265265

266-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
266+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
267267
builder.startObject(name);
268268
builder.field("type", CONTENT_TYPE);
269269
if (pathType != Defaults.PATH_TYPE) {
@@ -280,5 +280,6 @@ public ImmutableMap<String, XContentMapper> mappers() {
280280
builder.endObject();
281281

282282
builder.endObject();
283+
return builder;
283284
}
284285
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ObjectMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,9 @@ protected void doMerge(ObjectMapper mergeWith, MergeContext mergeContext) {
548548

549549
}
550550

551-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
551+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
552552
toXContent(builder, params, null, XContentMapper.EMPTY_ARRAY);
553+
return builder;
553554
}
554555

555556
public void toXContent(XContentBuilder builder, Params params, ToXContent custom, XContentMapper... additionalMappers) throws IOException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/ParentFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ protected ParentFieldMapper(String name, String indexName, String type) {
135135
return CONTENT_TYPE;
136136
}
137137

138-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
138+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
139139
builder.startObject(CONTENT_TYPE);
140140
builder.field("type", type);
141141
builder.endObject();
142+
return builder;
142143
}
143144

144145
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/RoutingFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ public void validate(ParseContext context, String routing) throws MapperParsingE
153153
return CONTENT_TYPE;
154154
}
155155

156-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
156+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
157157
// if all are defaults, no sense to write it at all
158158
if (index == Defaults.INDEX && store == Defaults.STORE && required == Defaults.REQUIRED && path == Defaults.PATH) {
159-
return;
159+
return builder;
160160
}
161161
builder.startObject(CONTENT_TYPE);
162162
if (index != Defaults.INDEX) {
@@ -172,6 +172,7 @@ public void validate(ParseContext context, String routing) throws MapperParsingE
172172
builder.field("path", path);
173173
}
174174
builder.endObject();
175+
return builder;
175176
}
176177

177178
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/SourceFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ private SourceFieldSelector(String name) {
181181
return CONTENT_TYPE;
182182
}
183183

184-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
184+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
185185
// all are defaults, no need to write it at all
186186
if (enabled == Defaults.ENABLED && compress == null && compressThreshold == -1) {
187-
return;
187+
return builder;
188188
}
189189
builder.startObject(contentType());
190190
if (enabled != Defaults.ENABLED) {
@@ -197,6 +197,7 @@ private SourceFieldSelector(String name) {
197197
builder.field("compress_threshold", new ByteSizeValue(compressThreshold).toString());
198198
}
199199
builder.endObject();
200+
return builder;
200201
}
201202

202203
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/TypeFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ public TypeFieldMapper(String name, String indexName, Field.Store store, Field.T
109109
return CONTENT_TYPE;
110110
}
111111

112-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
112+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
113113
// if all are defaults, no sense to write it at all
114114
if (store == Defaults.STORE) {
115-
return;
115+
return builder;
116116
}
117117
builder.startObject(CONTENT_TYPE);
118118
if (store != Defaults.STORE) {
119119
builder.field("store", store.name().toLowerCase());
120120
}
121121
builder.endObject();
122+
return builder;
122123
}
123124

124125
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/UidFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ protected UidFieldMapper(String name, String indexName) {
108108
return CONTENT_TYPE;
109109
}
110110

111-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
111+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
112112
// for now, don't output it at all
113+
return builder;
113114
}
114115

115116
@Override public void merge(XContentMapper mergeWith, MergeContext mergeContext) throws MergeMappingException {

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ void addFieldMapper(FieldMapper fieldMapper) {
525525
}
526526
}
527527

528-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
528+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
529529
rootObjectMapper.toXContent(builder, params, new ToXContent() {
530-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
530+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
531531
if (indexAnalyzer != null && searchAnalyzer != null && indexAnalyzer.name().equals(searchAnalyzer.name()) && !indexAnalyzer.name().startsWith("_")) {
532532
if (!indexAnalyzer.name().equals("default")) {
533533
// same analyzers, output it once
@@ -549,9 +549,11 @@ void addFieldMapper(FieldMapper fieldMapper) {
549549
if (meta != null && !meta.isEmpty()) {
550550
builder.field("_meta", meta());
551551
}
552+
return builder;
552553
}
553554
// no need to pass here id and boost, since they are added to the root object mapper
554555
// in the constructor
555556
}, indexFieldMapper, typeFieldMapper, allFieldMapper, analyzerMapper, sourceFieldMapper);
557+
return builder;
556558
}
557559
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/geo/GeoPointFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private void parseGeohash(ParseContext context, String geohash) throws IOExcepti
354354
}
355355
}
356356

357-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
357+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
358358
builder.startObject(name);
359359
builder.field("type", CONTENT_TYPE);
360360
if (pathType != Defaults.PATH_TYPE) {
@@ -377,6 +377,7 @@ private void parseGeohash(ParseContext context, String geohash) throws IOExcepti
377377
}
378378

379379
builder.endObject();
380+
return builder;
380381
}
381382

382383
public static class GeoStringFieldMapper extends StringFieldMapper {

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BaseFilterBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
*/
2929
public abstract class BaseFilterBuilder implements XContentFilterBuilder {
3030

31-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
31+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
3232
builder.startObject();
3333
doXContent(builder, params);
3434
builder.endObject();
35+
return builder;
3536
}
3637

3738
protected abstract void doXContent(XContentBuilder builder, Params params) throws IOException;

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/BaseQueryBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ public abstract class BaseQueryBuilder implements XContentQueryBuilder {
6060
}
6161
}
6262

63-
@Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
63+
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
6464
builder.startObject();
6565
doXContent(builder, params);
6666
builder.endObject();
67+
return builder;
6768
}
6869

6970
protected abstract void doXContent(XContentBuilder builder, Params params) throws IOException;

0 commit comments

Comments
 (0)