ChangeQueryProcessor: Don't implement PluginAttributesFactory

Return a PluginDefinedAttributesFactory via a named getter on
ChangeQueryProcessor, instead of making ChangeQueryProcessor implement
the interface directly. Without knowing about this interface, a reader
seeing `queryProcessor.create(cd)` might be confused: create what, a
ChangeInfo? (Wrong.)

Change-Id: I07c03169cc13758a7b5649123ccfb945390dd46d
This commit is contained in:
Dave Borowitz
2019-03-15 09:08:45 -07:00
parent 9c6ffc1165
commit dd5a182826
3 changed files with 10 additions and 8 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.query.change;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.query.change.ChangeQueryBuilder.FIELD_LIMIT;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.gerrit.extensions.common.PluginDefinedInfo;
import com.google.gerrit.extensions.registration.DynamicMap;
@@ -45,7 +46,6 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -56,9 +56,7 @@ import java.util.Set;
* holding on to a single instance.
*/
public class ChangeQueryProcessor extends QueryProcessor<ChangeData>
implements DynamicOptions.BeanReceiver,
DynamicOptions.BeanProvider,
PluginDefinedAttributesFactory {
implements DynamicOptions.BeanReceiver, DynamicOptions.BeanProvider {
private final Provider<CurrentUser> userProvider;
private final ChangeNotes.Factory notesFactory;
private final ImmutableListMultimap<String, ChangeAttributeFactory> attributeFactoriesByPlugin;
@@ -131,8 +129,11 @@ public class ChangeQueryProcessor extends QueryProcessor<ChangeData>
return dynamicBeans.get(plugin);
}
@Override
public List<PluginDefinedInfo> create(ChangeData cd) {
public PluginDefinedAttributesFactory getAttributesFactory() {
return this::buildPluginInfo;
}
private ImmutableList<PluginDefinedInfo> buildPluginInfo(ChangeData cd) {
return PluginDefinedAttributesFactories.createAll(
cd,
this,

View File

@@ -324,7 +324,7 @@ public class OutputStreamQuery {
eventFactory.addDependencies(rw, c, d.change(), d.currentPatchSet());
}
c.plugins = queryProcessor.create(d);
c.plugins = queryProcessor.getAttributesFactory().create(d);
return c;
}

View File

@@ -143,7 +143,8 @@ public class QueryChanges implements RestReadView<TopLevelResource>, DynamicOpti
int cnt = queries.size();
List<QueryResult<ChangeData>> results = imp.query(qb.parse(queries));
List<List<ChangeInfo>> res = json.create(options, this.imp).format(results);
List<List<ChangeInfo>> res =
json.create(options, this.imp.getAttributesFactory()).format(results);
for (int n = 0; n < cnt; n++) {
List<ChangeInfo> info = res.get(n);
if (results.get(n).more() && !info.isEmpty()) {