@SuppressWarnings("unchecked")
  protected void bindFlags(ExtensionContext context) {
    // Automatically bind all flags in our ExtensionContext to a Named annotation. e.g., binds:
    // settingsExtension.cloud() to a String annotated with @Named("cloud"), so core classes
    // may inject '@Named("cloud") String cloud'.
    for (Method method : context.getClass().getMethods()) {
      boolean isFlagMethod = method.isAnnotationPresent(Flag.class);
      if (!isFlagMethod) {
        continue;
      }

      Class returnType = method.getReturnType();
      Object flagValue;
      try {
        flagValue = method.invoke(context);
      } catch (IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException("Could not get flag value by invoking: " + method.getName(), e);
      }
      Preconditions.checkNotNull(flagValue, "Required flag " + method.getName() + " was null");
      bind(returnType).annotatedWith(Names.named(method.getName())).toInstance(flagValue);
    }
  }
{@link AbstractModule} that binds all @Flag-annotated flags from an {@link ExtensionContext}
as Named annotations to be injected by Guice.
libraries/config/src/main/java/org/datatransferproject/config/FlagBindingModule.java