public Object createProxy(InjectorOptions injectorOptions, Class<?> expectedType) throws InternalProvisionException { if (injectorOptions.disableCircularProxies) { throw InternalProvisionException.circularDependenciesDisabled(expectedType); } if (!expectedType.isInterface()) { throw InternalProvisionException.cannotProxyClass(expectedType); } if (invocationHandlers == null) { invocationHandlers = new ArrayList<>(); } DelegatingInvocationHandler<T> invocationHandler = new DelegatingInvocationHandler<>(); invocationHandlers.add(invocationHandler); // TODO: if I create a proxy which implements all the interfaces of // the implementation type, I'll be able to get away with one proxy // instance (as opposed to one per caller). ClassLoader classLoader = BytecodeGen.getClassLoader(expectedType); return expectedType.cast( Proxy.newProxyInstance( classLoader, new Class[] {expectedType, CircularDependencyProxy.class}, invocationHandler)); }
InjectorOptions getOptions(Stage stage, InjectorOptions parentOptions) { checkNotNull(stage, "stage must be set"); if (parentOptions == null) { return new InjectorOptions( stage, jitDisabled, disableCircularProxies, atInjectRequired, exactBindingAnnotationsRequired); } else { checkState(stage == parentOptions.stage, "child & parent stage don't match"); return new InjectorOptions( stage, jitDisabled || parentOptions.jitDisabled, disableCircularProxies || parentOptions.disableCircularProxies, atInjectRequired || parentOptions.atInjectRequired, exactBindingAnnotationsRequired || parentOptions.exactBindingAnnotationsRequired); } }
InjectorOptions getOptions(Stage stage, InjectorOptions parentOptions) { checkNotNull(stage, "stage must be set"); if(parentOptions == null) { return new InjectorOptions( stage, jitDisabled, disableCircularProxies, atInjectRequired, exactBindingAnnotationsRequired); } else { checkState(stage == parentOptions.stage, "child & parent stage don't match"); return new InjectorOptions( stage, jitDisabled || parentOptions.jitDisabled, disableCircularProxies || parentOptions.disableCircularProxies, atInjectRequired || parentOptions.atInjectRequired, exactBindingAnnotationsRequired || parentOptions.exactBindingAnnotationsRequired); } }
InternalContext(InjectorOptions options, Object[] toClear) { this.options = options; this.toClear = toClear; this.enterCount = 1; }
InjectorOptions getInjectorOptions() { return options; }