Skip to content

Commit

Permalink
Remove all instances of the deprecated ParseField.match method (#28586
Browse files Browse the repository at this point in the history
)

This removes all the server references to the deprecated `ParseField.match`
method in favor of the method that passes in the deprecation logger.

Relates to #28504
  • Loading branch information
dakrone authored Feb 9, 2018
1 parent 766b9d6 commit 5263b8c
Show file tree
Hide file tree
Showing 47 changed files with 358 additions and 364 deletions.
17 changes: 0 additions & 17 deletions server/src/main/java/org/elasticsearch/common/ParseField.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,6 @@ public ParseField withAllDeprecated(String allReplacedWith) {
return parseField;
}

/**
* Does {@code fieldName} match this field? Uses {@link LoggingDeprecationHandler}
* to prevent us from having to touch every call to {@code match} in the change
* that introduced {@linkplain LoggingDeprecationHandler}. In a followup this will
* be removed.
* @param fieldName
* the field name to match against this {@link ParseField}
* @return true if <code>fieldName</code> matches any of the acceptable
* names for this {@link ParseField}.
* @deprecated Use {@link #match(String, DeprecationHandler)} with
* {@link XContentParser#getDeprecationHandler()} instead.
*/
@Deprecated
public boolean match(String fieldName) {
return match(fieldName, LoggingDeprecationHandler.INSTANCE);
}

/**
* Does {@code fieldName} match this field?
* @param fieldName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static XContentParser createParser(NamedXContentRegistry xContentRegistry
compressedInput = new BufferedInputStream(compressedInput);
}
final XContentType contentType = XContentFactory.xContentType(compressedInput);
return XContentFactory.xContent(contentType).createParser(xContentRegistry, compressedInput);
return XContentFactory.xContent(contentType).createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, compressedInput);
} else {
return XContentFactory.xContent(bytes).createParser(xContentRegistry, bytes.streamInput());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,15 @@ public static BoolQueryBuilder fromXContent(XContentParser parser) throws IOExce
}
}
} else if (token.isValue()) {
if (DISABLE_COORD_FIELD.match(currentFieldName)) {
if (DISABLE_COORD_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
// ignore
} else if (MINIMUM_SHOULD_MATCH.match(currentFieldName)) {
} else if (MINIMUM_SHOULD_MATCH.match(currentFieldName, parser.getDeprecationHandler())) {
minimumShouldMatch = parser.textOrNull();
} else if (BOOST_FIELD.match(currentFieldName)) {
} else if (BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
} else if (ADJUST_PURE_NEGATIVE.match(currentFieldName)) {
} else if (ADJUST_PURE_NEGATIVE.match(currentFieldName, parser.getDeprecationHandler())) {
adjustPureNegative = parser.booleanValue();
} else if (NAME_FIELD.match(currentFieldName)) {
} else if (NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
throw new ParsingException(parser.getTokenLocation(), "[bool] query does not support [" + currentFieldName + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ public static BoostingQueryBuilder fromXContent(XContentParser parser) throws IO
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT) {
if (POSITIVE_FIELD.match(currentFieldName)) {
if (POSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
positiveQuery = parseInnerQueryBuilder(parser);
positiveQueryFound = true;
} else if (NEGATIVE_FIELD.match(currentFieldName)) {
} else if (NEGATIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
negativeQuery = parseInnerQueryBuilder(parser);
negativeQueryFound = true;
} else {
throw new ParsingException(parser.getTokenLocation(), "[boosting] query does not support [" + currentFieldName + "]");
}
} else if (token.isValue()) {
if (NEGATIVE_BOOST_FIELD.match(currentFieldName)) {
if (NEGATIVE_BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
negativeBoost = parser.floatValue();
} else if (NAME_FIELD.match(currentFieldName)) {
} else if (NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else if (BOOST_FIELD.match(currentFieldName)) {
} else if (BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
} else {
throw new ParsingException(parser.getTokenLocation(), "[boosting] query does not support [" + currentFieldName + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ public static CommonTermsQueryBuilder fromXContent(XContentParser parser) throws
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT) {
if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName)) {
if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
String innerFieldName = null;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
innerFieldName = parser.currentName();
} else if (token.isValue()) {
if (LOW_FREQ_FIELD.match(innerFieldName)) {
if (LOW_FREQ_FIELD.match(innerFieldName, parser.getDeprecationHandler())) {
lowFreqMinimumShouldMatch = parser.text();
} else if (HIGH_FREQ_FIELD.match(innerFieldName)) {
} else if (HIGH_FREQ_FIELD.match(innerFieldName, parser.getDeprecationHandler())) {
highFreqMinimumShouldMatch = parser.text();
} else {
throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME +
Expand All @@ -297,23 +297,23 @@ public static CommonTermsQueryBuilder fromXContent(XContentParser parser) throws
"] query does not support [" + currentFieldName + "]");
}
} else if (token.isValue()) {
if (QUERY_FIELD.match(currentFieldName)) {
if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
text = parser.objectText();
} else if (ANALYZER_FIELD.match(currentFieldName)) {
} else if (ANALYZER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
analyzer = parser.text();
} else if (DISABLE_COORD_FIELD.match(currentFieldName)) {
} else if (DISABLE_COORD_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
// ignore
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
} else if (HIGH_FREQ_OPERATOR_FIELD.match(currentFieldName)) {
} else if (HIGH_FREQ_OPERATOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
highFreqOperator = Operator.fromString(parser.text());
} else if (LOW_FREQ_OPERATOR_FIELD.match(currentFieldName)) {
} else if (LOW_FREQ_OPERATOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
lowFreqOperator = Operator.fromString(parser.text());
} else if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName)) {
} else if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
lowFreqMinimumShouldMatch = parser.text();
} else if (CUTOFF_FREQUENCY_FIELD.match(currentFieldName)) {
} else if (CUTOFF_FREQUENCY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
cutoffFrequency = parser.floatValue();
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static ConstantScoreQueryBuilder fromXContent(XContentParser parser) thro
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT) {
if (INNER_QUERY_FIELD.match(currentFieldName)) {
if (INNER_QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
if (queryFound) {
throw new ParsingException(parser.getTokenLocation(), "[" + ConstantScoreQueryBuilder.NAME + "]"
+ " accepts only one 'filter' element.");
Expand All @@ -109,9 +109,9 @@ public static ConstantScoreQueryBuilder fromXContent(XContentParser parser) thro
"[constant_score] query does not support [" + currentFieldName + "]");
}
} else if (token.isValue()) {
if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
} else {
throw new ParsingException(parser.getTokenLocation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ public static DisMaxQueryBuilder fromXContent(XContentParser parser) throws IOEx
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT) {
if (QUERIES_FIELD.match(currentFieldName)) {
if (QUERIES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queriesFound = true;
queries.add(parseInnerQueryBuilder(parser));
} else {
throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (QUERIES_FIELD.match(currentFieldName)) {
if (QUERIES_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queriesFound = true;
while (token != XContentParser.Token.END_ARRAY) {
queries.add(parseInnerQueryBuilder(parser));
Expand All @@ -153,11 +153,11 @@ public static DisMaxQueryBuilder fromXContent(XContentParser parser) throws IOEx
throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
}
} else {
if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
} else if (TIE_BREAKER_FIELD.match(currentFieldName)) {
} else if (TIE_BREAKER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
tieBreaker = parser.floatValue();
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public static ExistsQueryBuilder fromXContent(XContentParser parser) throws IOEx
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token.isValue()) {
if (FIELD_FIELD.match(currentFieldName)) {
if (FIELD_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
fieldPattern = parser.text();
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
} else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
} else {
throw new ParsingException(parser.getTokenLocation(), "[" + ExistsQueryBuilder.NAME +
Expand Down Expand Up @@ -131,7 +131,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
}

public static Query newFilter(QueryShardContext context, String fieldPattern) {

final FieldNamesFieldMapper.FieldNamesFieldType fieldNamesFieldType = (FieldNamesFieldMapper.FieldNamesFieldType) context
.getMapperService().fullName(FieldNamesFieldMapper.NAME);
if (fieldNamesFieldType == null) {
Expand Down Expand Up @@ -165,7 +165,7 @@ public static Query newFilter(QueryShardContext context, String fieldPattern) {
}

private static Query newLegacyExistsQuery(Collection<String> fields) {
// We create TermsQuery directly here rather than using FieldNamesFieldType.termsQuery()
// We create TermsQuery directly here rather than using FieldNamesFieldType.termsQuery()
// so we don't end up with deprecation warnings
if (fields.size() == 1) {
Query filter = new TermQuery(new Term(FieldNamesFieldMapper.NAME, fields.iterator().next()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (token == XContentParser.Token.START_OBJECT) {
if (QUERY_FIELD.match(currentFieldName)) {
if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
QueryBuilder query = parseInnerQueryBuilder(parser);
if (query instanceof SpanQueryBuilder == false) {
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query must be of type span query");
Expand All @@ -124,11 +124,11 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
+ currentFieldName + "]");
}
} else {
if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName)) {
if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
boost = parser.floatValue();
} else if (FIELD_FIELD.match(currentFieldName)) {
} else if (FIELD_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
field = parser.text();
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName)) {
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
throw new ParsingException(parser.getTokenLocation(),
Expand Down
Loading

0 comments on commit 5263b8c

Please sign in to comment.