Pass `context` directly to `loadConfig` method in AutoConfigManager
This addresses a warning reported by the [Checker Framework](https://checkerframework.org/).
I think having the context as a private member is not necessary here and
we can instead pass it directly to `loadConfig` where it is needed.
private final Set<AutoConfig> loadedConfigs = Sets.newHashSet();
private final TypeHandlerLibrary typeHandlerLibrary;
- private Context context;
-
public AutoConfigManager(TypeHandlerLibrary typeHandlerLibrary) {
this.typeHandlerLibrary = typeHandlerLibrary;
}
@@ -55,8 +53,6 @@ public AutoConfigManager(TypeHandlerLibrary typeHandlerLibrary) {
public void loadConfigsIn(Context context) {
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
- this.context = context;
-
for (Class<? extends AutoConfig> configClass : environment.getSubtypesOf(AutoConfig.class)) {
if (context.get(configClass) != null) {
// We've already initialized this config before
@@ -64,13 +60,11 @@ public void loadConfigsIn(Context context) {
}
SimpleUri configId = ReflectionUtil.getFullyQualifiedSimpleUriFor(configClass, environment);
- loadConfig(configClass, configId);
+ loadConfig(configClass, configId, context);
}
-
- this.context = null;
}
- private <T extends AutoConfig> void loadConfig(Class<T> clazz, SimpleUri id) {
+ private <T extends AutoConfig> void loadConfig(Class<T> clazz, SimpleUri id, Context context) {
Optional<T> optionalConfig = InjectionHelper.safeCreateWithConstructorInjection(clazz, context);
if (!optionalConfig.isPresent()) {
