From dbfa84f0edc51d82bc3c871ca956037f43714bb7 Mon Sep 17 00:00:00 2001 From: Christian Edward Gruber Date: Thu, 13 Jun 2013 15:13:01 -0700 Subject: [PATCH] Various fixes from review, including style fixes for square's codebase, typos, clean up some extra logging, etc. --- .../codegen/InjectAdapterProcessor.java | 5 +-- core/src/main/java/dagger/ObjectGraph.java | 3 +- .../java/dagger/internal/FailoverLoader.java | 42 +++++-------------- .../loaders/ReflectiveModuleAdapter.java | 2 +- 4 files changed, 14 insertions(+), 38 deletions(-) diff --git a/compiler/src/main/java/dagger/internal/codegen/InjectAdapterProcessor.java b/compiler/src/main/java/dagger/internal/codegen/InjectAdapterProcessor.java index 30b2b68b23e..de890dc0be5 100644 --- a/compiler/src/main/java/dagger/internal/codegen/InjectAdapterProcessor.java +++ b/compiler/src/main/java/dagger/internal/codegen/InjectAdapterProcessor.java @@ -15,9 +15,6 @@ */ package dagger.internal.codegen; -import static dagger.internal.loaders.GeneratedAdapters.INJECT_ADAPTER_SUFFIX; -import static dagger.internal.loaders.GeneratedAdapters.STATIC_INJECTION_SUFFIX; - import com.squareup.java.JavaWriter; import dagger.MembersInjector; import dagger.internal.Binding; @@ -57,6 +54,8 @@ import static dagger.internal.codegen.TypeUtils.isCallableConstructor; import static dagger.internal.codegen.TypeUtils.rawTypeToString; import static dagger.internal.codegen.TypeUtils.typeToString; +import static dagger.internal.loaders.GeneratedAdapters.INJECT_ADAPTER_SUFFIX; +import static dagger.internal.loaders.GeneratedAdapters.STATIC_INJECTION_SUFFIX; import static java.lang.reflect.Modifier.FINAL; import static java.lang.reflect.Modifier.PRIVATE; import static java.lang.reflect.Modifier.PUBLIC; diff --git a/core/src/main/java/dagger/ObjectGraph.java b/core/src/main/java/dagger/ObjectGraph.java index 3e56f2e774a..9c6214080e1 100644 --- a/core/src/main/java/dagger/ObjectGraph.java +++ b/core/src/main/java/dagger/ObjectGraph.java @@ -16,9 +16,8 @@ */ package dagger; -import dagger.internal.FailoverLoader; - import dagger.internal.Binding; +import dagger.internal.FailoverLoader; import dagger.internal.Keys; import dagger.internal.Linker; import dagger.internal.Loader; diff --git a/core/src/main/java/dagger/internal/FailoverLoader.java b/core/src/main/java/dagger/internal/FailoverLoader.java index c8c16a55569..674b2595350 100644 --- a/core/src/main/java/dagger/internal/FailoverLoader.java +++ b/core/src/main/java/dagger/internal/FailoverLoader.java @@ -21,32 +21,24 @@ import dagger.internal.loaders.ReflectiveAtInjectBinding; import dagger.internal.loaders.ReflectiveModuleAdapter; import dagger.internal.loaders.ReflectiveStaticInjection; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Handles loading/finding of modules, injection bindings, and static injections by use of a - * strategy of "load the appropriate generaged code" or, if no such code is found, create a + * strategy of "load the appropriate generated code" or, if no such code is found, create a * reflective equivalent. */ public final class FailoverLoader implements Loader { - private static final Logger logger = Logger.getLogger(Loader.class.getName()); /** * Obtains a module adapter for {@code module} from the first responding resolver. */ @Override public ModuleAdapter getModuleAdapter(Class type, T instance) { - try { - ModuleAdapter result = GeneratedAdapters.initModuleAdapter(type); - if (result == null) { - result = ReflectiveModuleAdapter.createAdaptor(type); - } - result.module = (instance == null) ? result.newModule() : instance; - return result; - } catch (RuntimeException e) { - logNotFound("Module adapter", type.getName(), e); - throw e; + ModuleAdapter result = GeneratedAdapters.initModuleAdapter(type); + if (result == null) { + result = ReflectiveModuleAdapter.create(type); } + result.module = (instance != null) ? instance : result.newModule(); + return result; } @Override public Binding getAtInjectBinding(String key, String className, @@ -64,28 +56,14 @@ public final class FailoverLoader implements Loader { return result; } catch (ClassNotFoundException e) { throw new RuntimeException("Could not find " + className + " needed for binding " + key, e); - } catch (RuntimeException e) { - logNotFound("Binding", className, e); - throw e; } } @Override public StaticInjection getStaticInjection(Class injectedClass) { - try { - StaticInjection result = GeneratedAdapters.initStaticInjection(injectedClass); - if (result == null) { - result = ReflectiveStaticInjection.create(injectedClass); - } - return result; - } catch (RuntimeException e) { - logNotFound("Static injection", injectedClass.getName(), e); - throw e; - } - } - - private void logNotFound(String type, String name, RuntimeException e) { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, String.format("Could not initialize a %s for %s.", type, name), e); + StaticInjection result = GeneratedAdapters.initStaticInjection(injectedClass); + if (result == null) { + result = ReflectiveStaticInjection.create(injectedClass); } + return result; } } diff --git a/core/src/main/java/dagger/internal/loaders/ReflectiveModuleAdapter.java b/core/src/main/java/dagger/internal/loaders/ReflectiveModuleAdapter.java index 1ed3ee9f284..1bb36f7838b 100644 --- a/core/src/main/java/dagger/internal/loaders/ReflectiveModuleAdapter.java +++ b/core/src/main/java/dagger/internal/loaders/ReflectiveModuleAdapter.java @@ -133,7 +133,7 @@ private void handleSetBindings(Map> bindings, Method meth * Creates a ReflectiveModuleAdapter or throws an {@code IllegalArgumentException}. */ @SuppressWarnings("unchecked") // Runtime checks validate that the result type matches 'T'. - public static ModuleAdapter createAdaptor(Class moduleClass) { + public static ModuleAdapter create(Class moduleClass) { Module annotation = moduleClass.getAnnotation(Module.class); if (annotation == null) { throw new IllegalArgumentException("No @Module on " + moduleClass.getName());