private ModuleSource getModuleSource(Object module) { StackTraceElement[] partialCallStack; if (getIncludeStackTraceOption() == IncludeStackTraceOption.COMPLETE) { partialCallStack = getPartialCallStack(new Throwable().getStackTrace()); } else { partialCallStack = new StackTraceElement[0]; } if (moduleSource == null) { return new ModuleSource(module, partialCallStack); } return moduleSource.createChild(module, partialCallStack); }
|| !moduleSource.getModuleClassName().equals(delegate.getClass().getName())) { moduleSource = getModuleSource(delegate); unwrapModuleSource = true; moduleSource = moduleSource.getParent();
/** * Returns the class names of modules involved in creating this {@link Element}. The first element * (index 0) is the class name of module that defined the element, and the last element is the * class name of root module. */ public List<String> getModuleClassNames() { return moduleSource.getModuleClassNames(); }
int size = moduleSource.size(); Integer[] positions = new Integer[size]; int chunkSize = partialCallStack.length; ModuleSource current = moduleSource; for (int cursor = 1; cursor < size; cursor++) { chunkSize = current.getPartialCallStackSize(); positions[cursor] = positions[cursor - 1] + chunkSize; current = current.getParent();
/** * Returns the sequence of method calls that ends at one of {@link com.google.inject.Binder} * {@code bindXXX()} methods and eventually defines the element. Note that {@link #getStackTrace} * lists {@link StackTraceElement StackTraceElements} in reverse chronological order. The first * element (index zero) is the last method call and the last element is the first method * invocation. In the cases where stack trace is not available (i.e.,the stack trace was not * collected), it returns an empty array. */ public StackTraceElement[] getStackTrace() { int modulesCallStackSize = moduleSource.getStackTraceSize(); int chunkSize = partialCallStack.length; int size = moduleSource.getStackTraceSize() + chunkSize; StackTraceElement[] callStack = new StackTraceElement[size]; System.arraycopy( StackTraceElements.convertToStackTraceElement(partialCallStack), 0, callStack, 0, chunkSize); System.arraycopy(moduleSource.getStackTrace(), 0, callStack, chunkSize, modulesCallStackSize); return callStack; }
/** * Returns the size of call stack that ends just before the module {@link Module#configure(Binder) * configure(Binder)} method invocation (see {@link #getStackTrace()}). */ int getStackTraceSize() { if (parent == null) { return partialCallStack.length; } return parent.getStackTraceSize() + partialCallStack.length; }
/** * Creates and returns a child {@link ModuleSource} corresponding to the {@link Module module}. * * @param module the corresponding module * @param partialCallStack the chunk of call stack that starts from the parent module {@link * Module#configure(Binder) configure(Binder)} call and ends just before the module {@link * Module#configure(Binder) configure(Binder)} method invocation */ ModuleSource createChild(Object module, StackTraceElement[] partialCallStack) { return new ModuleSource(this, module, partialCallStack); }
/** * Returns the size of {@link ModuleSource ModuleSources} chain (all parents) that ends at this * object. */ int size() { if (parent == null) { return 1; } return parent.size() + 1; }
int size = moduleSource.size(); Integer[] positions = new Integer[size]; int chunkSize = partialCallStack.length; ModuleSource current = moduleSource; for (int cursor = 1; cursor < size; cursor++) { chunkSize = current.getPartialCallStackSize(); positions[cursor] = positions[cursor - 1] + chunkSize; current = current.getParent();
/** * Returns the sequence of method calls that ends at one of {@link com.google.inject.Binder} * {@code bindXXX()} methods and eventually defines the element. Note that * this method lists {@link StackTraceElement StackTraceElements} in reverse * chronological order. The first element (index zero) is the last method call and the last * element is the first method invocation. In the cases where stack trace is not available * (i.e.,the stack trace was not collected), it returns an empty array. */ public StackTraceElement[] getStackTrace() { int modulesCallStackSize = moduleSource.getStackTraceSize(); int chunkSize = partialCallStack.length; int size = moduleSource.getStackTraceSize() + chunkSize; StackTraceElement[] callStack = new StackTraceElement[size]; System.arraycopy( StackTraceElements.convertToStackTraceElement(partialCallStack), 0, callStack, 0, chunkSize); System.arraycopy(moduleSource.getStackTrace(), 0, callStack, chunkSize, modulesCallStackSize); return callStack; }
/** * Removes the {@link #moduleSource} call stack from the beginning of current call stack. It * also removes the last two elements in order to make {@link #install(Module)} the last call in * the call stack. */ private StackTraceElement[] getPartialCallStack(StackTraceElement[] callStack) { int toSkip = 0; if (moduleSource != null) { toSkip = moduleSource.getStackTraceSize(); } // -1 for skipping 'getModuleSource' and 'getElementSource' calls int chunkSize = callStack.length - toSkip - 1; StackTraceElement[] partialCallStack = new StackTraceElement[chunkSize]; System.arraycopy(callStack, 1, partialCallStack, 0, chunkSize); return partialCallStack; }
/** * Creates and returns a child {@link ModuleSource} corresponding to the {@link Module module}. * * @param module the corresponding module * @param partialCallStack the chunk of call stack that starts from the parent module {@link * Module#configure(Binder) configure(Binder)} call and ends just before the module {@link * Module#configure(Binder) configure(Binder)} method invocation */ ModuleSource createChild(Object module, StackTraceElement[] partialCallStack) { return new ModuleSource(this, module, partialCallStack); }
/** * Returns the size of {@link ModuleSource ModuleSources} chain (all parents) that ends at this * object. */ int size() { if (parent == null) { return 1; } return parent.size() + 1; }
int size = moduleSource.size(); Integer[] positions = new Integer[size]; int chunkSize = partialCallStack.length; ModuleSource current = moduleSource; for (int cursor = 1; cursor < size; cursor++) { chunkSize = current.getPartialCallStackSize(); positions[cursor] = positions[cursor - 1] + chunkSize; current = current.getParent();
private ModuleSource getModuleSource(Object module) { StackTraceElement[] partialCallStack; if (getIncludeStackTraceOption() == IncludeStackTraceOption.COMPLETE) { partialCallStack = getPartialCallStack(new Throwable().getStackTrace()); } else { partialCallStack = new StackTraceElement[0]; } if (moduleSource == null) { return new ModuleSource(module, partialCallStack); } return moduleSource.createChild(module, partialCallStack); }
/** * Returns the sequence of method calls that ends at one of {@link com.google.inject.Binder} * {@code bindXXX()} methods and eventually defines the element. Note that {@link #getStackTrace} * lists {@link StackTraceElement StackTraceElements} in reverse chronological order. The first * element (index zero) is the last method call and the last element is the first method * invocation. In the cases where stack trace is not available (i.e.,the stack trace was not * collected), it returns an empty array. */ public StackTraceElement[] getStackTrace() { int modulesCallStackSize = moduleSource.getStackTraceSize(); int chunkSize = partialCallStack.length; int size = moduleSource.getStackTraceSize() + chunkSize; StackTraceElement[] callStack = new StackTraceElement[size]; System.arraycopy( StackTraceElements.convertToStackTraceElement(partialCallStack), 0, callStack, 0, chunkSize); System.arraycopy(moduleSource.getStackTrace(), 0, callStack, chunkSize, modulesCallStackSize); return callStack; }
|| !moduleSource.getModuleClassName().equals(delegate.getClass().getName())) { moduleSource = getModuleSource(delegate); unwrapModuleSource = true; moduleSource = moduleSource.getParent();
/** * Returns the full call stack that ends just before the module {@link Module#configure(Binder) * configure(Binder)} method invocation. The return array is non-empty if stack trace collection * on. */ StackTraceElement[] getStackTrace() { int stackTraceSize = getStackTraceSize(); StackTraceElement[] callStack = new StackTraceElement[stackTraceSize]; int cursor = 0; ModuleSource current = this; while (current != null) { StackTraceElement[] chunk = StackTraceElements.convertToStackTraceElement(current.partialCallStack); int chunkSize = chunk.length; System.arraycopy(chunk, 0, callStack, cursor, chunkSize); current = current.parent; cursor = cursor + chunkSize; } return callStack; } }
} else { // or if (stackTraceOption == IncludeStackTraceOptions.OFF) declaringSource = sourceProvider.getFromClassNames(moduleSource.getModuleClassNames());
/** * Creates and returns a child {@link ModuleSource} corresponding to the {@link Module module}. * * @param module the corresponding module * @param partialCallStack the chunk of call stack that starts from the parent module {@link * Module#configure(Binder) configure(Binder)} call and ends just before the module {@link * Module#configure(Binder) configure(Binder)} method invocation */ ModuleSource createChild(Object module, StackTraceElement[] partialCallStack) { return new ModuleSource(this, module, partialCallStack); }