From 7140d184ab4b46a81459236f83ea86b2c64d1472 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 24 Feb 2016 02:23:16 -0800 Subject: [PATCH] Fix IntelliJ query builder type inference issues Relates #15429 --- .../java/org/elasticsearch/search/SearchModule.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 62bfc1de856..05aab255cf9 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -33,6 +33,7 @@ import org.elasticsearch.common.geo.builders.PolygonBuilder; import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.multibindings.Multibinder; +import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.BoolQueryParser; @@ -283,14 +284,15 @@ public class SearchModule extends AbstractModule { /** * Register a new ScoreFunctionParser. */ - public void registerFunctionScoreParser(ScoreFunctionParser parser) { + public void registerFunctionScoreParser(ScoreFunctionParser parser) { for (String name: parser.getNames()) { Object oldValue = functionScoreParsers.putIfAbsent(name, parser); if (oldValue != null) { throw new IllegalArgumentException("Function score parser [" + oldValue + "] already registered for name [" + name + "]"); } } - namedWriteableRegistry.registerPrototype(ScoreFunctionBuilder.class, parser.getBuilderPrototype()); + @SuppressWarnings("unchecked") NamedWriteable sfb = parser.getBuilderPrototype(); + namedWriteableRegistry.registerPrototype(ScoreFunctionBuilder.class, sfb); } public void registerQueryParser(Supplier> parser) { @@ -354,14 +356,15 @@ public class SearchModule extends AbstractModule { public IndicesQueriesRegistry buildQueryParserRegistry() { Map> queryParsersMap = new HashMap<>(); for (Supplier> parserSupplier : queryParsers) { - QueryParser parser = parserSupplier.get(); + QueryParser parser = parserSupplier.get(); for (String name: parser.names()) { Object oldValue = queryParsersMap.putIfAbsent(name, parser); if (oldValue != null) { throw new IllegalArgumentException("Query parser [" + oldValue + "] already registered for name [" + name + "] while trying to register [" + parser + "]"); } } - namedWriteableRegistry.registerPrototype(QueryBuilder.class, parser.getBuilderPrototype()); + @SuppressWarnings("unchecked") NamedWriteable qb = parser.getBuilderPrototype(); + namedWriteableRegistry.registerPrototype(QueryBuilder.class, qb); } return new IndicesQueriesRegistry(settings, queryParsersMap); }