mirror of
https://github.com/google/guice.git
synced 2024-04-21 12:32:36 +00:00
Remove COMPLETE option for flag guice_include_stack_traces.
This option does not provide much benefits and doesn't even work correctly in some cases. PiperOrigin-RevId: 407408634
This commit is contained in:
@@ -50,8 +50,6 @@ public final class InternalFlags {
|
||||
OFF,
|
||||
/** Minimum stack trace collection (Default) */
|
||||
ONLY_FOR_DECLARING_SOURCE,
|
||||
/** Full stack trace for everything */
|
||||
COMPLETE
|
||||
}
|
||||
|
||||
/** The options for Guice custom class loading. */
|
||||
@@ -176,15 +174,14 @@ public final class InternalFlags {
|
||||
|
||||
/**
|
||||
* Gets the system option indicated by the specified key; runs as a privileged action.
|
||||
*
|
||||
*
|
||||
* @param name of the system option
|
||||
* @param defaultValue if the option is not set
|
||||
* @param secureValue if the security manager disallows access to the option
|
||||
*
|
||||
* @return value of the option, defaultValue if not set, secureValue if no access
|
||||
*/
|
||||
private static <T extends Enum<T>> T getSystemOption(final String name, T defaultValue,
|
||||
T secureValue) {
|
||||
private static <T extends Enum<T>> T getSystemOption(
|
||||
final String name, T defaultValue, T secureValue) {
|
||||
Class<T> enumType = defaultValue.getDeclaringClass();
|
||||
String value = null;
|
||||
try {
|
||||
|
||||
@@ -17,9 +17,6 @@
|
||||
package com.google.inject.spi;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.internal.util.StackTraceElements;
|
||||
import com.google.inject.internal.util.StackTraceElements.InMemoryStackTraceElement;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -30,20 +27,10 @@ import javax.annotation.Nullable;
|
||||
* defines the Guice {@link Element element}. For example, if the element is created from a method
|
||||
* annotated by {@literal @Provides}, the declaring source of element would be the method itself.
|
||||
*
|
||||
* <p>The {@link #getStackTrace()} refers to the sequence of calls 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. By default, the stack trace is not collected. The default
|
||||
* behavior can be changed by setting the {@code guice_include_stack_traces} flag value. The value
|
||||
* can be either {@code OFF}, {@code ONLY_FOR_DECLARING_SOURCE} or {@code COMPLETE}. Note that
|
||||
* collecting stack traces for every binding can cause a performance hit when the injector is
|
||||
* created.
|
||||
*
|
||||
* <p>The sequence of class names of {@link com.google.inject.Module modules} involved in the
|
||||
* element creation can be retrieved by {@link #getModuleClassNames()}. Similar to {@link
|
||||
* #getStackTrace()}, the order is reverse chronological. The first module (index 0) is the module
|
||||
* that installs the {@link Element element}. The last module is the root module.
|
||||
* element creation can be retrieved by {@link #getModuleClassNames()}. The order of the module
|
||||
* class names is reverse chronological. The first module (index 0) is the module that installs the
|
||||
* {@link Element element}. The last module is the root module.
|
||||
*
|
||||
* <p>In order to support the cases where a Guice {@link Element element} is created from another
|
||||
* Guice {@link Element element} (original) (e.g., by {@link Element#applyTo}), it also provides a
|
||||
@@ -71,12 +58,6 @@ public final class ElementSource {
|
||||
/** The {@link ModuleSource source} of module creates the element. */
|
||||
final ModuleSource moduleSource;
|
||||
|
||||
/**
|
||||
* The partial call stack that starts at the last module {@link Module#Configure(Binder)
|
||||
* configure(Binder)} call. The value is empty if stack trace collection is off.
|
||||
*/
|
||||
final InMemoryStackTraceElement[] partialCallStack;
|
||||
|
||||
/**
|
||||
* Refers to a single location in source code that causes the element creation. It can be any
|
||||
* object such as {@link Constructor}, {@link Method}, {@link Field}, {@link StackTraceElement},
|
||||
@@ -103,16 +84,13 @@ public final class ElementSource {
|
||||
boolean trustedOriginalSource,
|
||||
Object declaringSource,
|
||||
ModuleSource moduleSource,
|
||||
StackTraceElement[] partialCallStack,
|
||||
ModuleAnnotatedMethodScanner scanner) {
|
||||
Preconditions.checkNotNull(declaringSource, "declaringSource cannot be null.");
|
||||
Preconditions.checkNotNull(moduleSource, "moduleSource cannot be null.");
|
||||
Preconditions.checkNotNull(partialCallStack, "partialCallStack cannot be null.");
|
||||
this.originalElementSource = originalSource;
|
||||
this.trustedOriginalElementSource = trustedOriginalSource;
|
||||
this.declaringSource = declaringSource;
|
||||
this.moduleSource = moduleSource;
|
||||
this.partialCallStack = StackTraceElements.convertToInMemoryStackTraceElement(partialCallStack);
|
||||
this.scanner = scanner;
|
||||
}
|
||||
|
||||
@@ -144,61 +122,6 @@ public final class ElementSource {
|
||||
return moduleSource.getModuleClassNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position of {@link com.google.inject.Module#configure configure(Binder)} method
|
||||
* call in the {@link #getStackTrace stack trace} for modules that their classes returned by
|
||||
* {@link #getModuleClassNames}. For example, if the stack trace looks like the following:
|
||||
*
|
||||
* <ol>
|
||||
* <li>{@code Binder.bind()}
|
||||
* <li>{@code ModuleTwo.configure()}
|
||||
* <li>{@code Binder.install()}
|
||||
* <li>{@code ModuleOne.configure()}
|
||||
* <li>{@code theRest().
|
||||
* </ol>
|
||||
*
|
||||
* <p>1 and 3 are returned.
|
||||
*
|
||||
* <p>In the cases where stack trace is not available (i.e., the stack trace was not collected),
|
||||
* it returns -1 for all module positions.
|
||||
*/
|
||||
public List<Integer> getModuleConfigurePositionsInStackTrace() {
|
||||
int size = moduleSource.size();
|
||||
Integer[] positions = new Integer[size];
|
||||
int chunkSize = partialCallStack.length;
|
||||
positions[0] = chunkSize - 1;
|
||||
ModuleSource current = moduleSource;
|
||||
for (int cursor = 1; cursor < size; cursor++) {
|
||||
chunkSize = current.getPartialCallStackSize();
|
||||
positions[cursor] = positions[cursor - 1] + chunkSize;
|
||||
current = current.getParent();
|
||||
}
|
||||
return ImmutableList.<Integer>copyOf(positions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {@code getDeclaringSource().toString()} value. */
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -632,23 +632,13 @@ public final class Elements {
|
||||
}
|
||||
|
||||
private ModuleSource getModuleSource(Class<?> 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, permitMapConstruction.getPermitMap());
|
||||
return new ModuleSource(module, permitMapConstruction.getPermitMap());
|
||||
}
|
||||
return moduleSource.createChild(module, partialCallStack);
|
||||
return moduleSource.createChild(module);
|
||||
}
|
||||
|
||||
private ElementSource getElementSource() {
|
||||
// Full call stack
|
||||
StackTraceElement[] callStack = null;
|
||||
// The call stack starts from current top module configure and ends at this method caller
|
||||
StackTraceElement[] partialCallStack = new StackTraceElement[0];
|
||||
// The element original source
|
||||
ElementSource originalSource = null;
|
||||
// The element declaring source
|
||||
@@ -657,21 +647,10 @@ public final class Elements {
|
||||
originalSource = (ElementSource) declaringSource;
|
||||
declaringSource = originalSource.getDeclaringSource();
|
||||
}
|
||||
IncludeStackTraceOption stackTraceOption = getIncludeStackTraceOption();
|
||||
if (stackTraceOption == IncludeStackTraceOption.COMPLETE
|
||||
|| (stackTraceOption == IncludeStackTraceOption.ONLY_FOR_DECLARING_SOURCE
|
||||
&& declaringSource == null)) {
|
||||
callStack = new Throwable().getStackTrace();
|
||||
}
|
||||
if (stackTraceOption == IncludeStackTraceOption.COMPLETE) {
|
||||
partialCallStack = getPartialCallStack(callStack);
|
||||
}
|
||||
if (declaringSource == null) {
|
||||
// So 'source' and 'originalSource' are null otherwise declaringSource has some value
|
||||
if (stackTraceOption == IncludeStackTraceOption.COMPLETE
|
||||
|| stackTraceOption == IncludeStackTraceOption.ONLY_FOR_DECLARING_SOURCE) {
|
||||
// With the above conditions and assignments 'callStack' is non-null
|
||||
StackTraceElement callingSource = sourceProvider.get(callStack);
|
||||
IncludeStackTraceOption stackTraceOption = getIncludeStackTraceOption();
|
||||
if (stackTraceOption == IncludeStackTraceOption.ONLY_FOR_DECLARING_SOURCE) {
|
||||
StackTraceElement callingSource = sourceProvider.get(new Throwable().getStackTrace());
|
||||
// If we've traversed past all reasonable sources and into our internal code, then we
|
||||
// don't know the source.
|
||||
if (callingSource
|
||||
@@ -682,37 +661,14 @@ public final class Elements {
|
||||
} else {
|
||||
declaringSource = callingSource;
|
||||
}
|
||||
} else { // or if (stackTraceOption == IncludeStackTraceOptions.OFF)
|
||||
} else {
|
||||
// As neither 'declaring source' nor 'call stack' is available use 'module source'
|
||||
declaringSource = sourceProvider.getFromClassNames(moduleSource.getModuleClassNames());
|
||||
}
|
||||
}
|
||||
// Build the binding call stack
|
||||
return new ElementSource(
|
||||
originalSource,
|
||||
trustedSource,
|
||||
declaringSource,
|
||||
moduleSource,
|
||||
partialCallStack,
|
||||
scannerSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
originalSource, trustedSource, declaringSource, moduleSource, scannerSource);
|
||||
}
|
||||
|
||||
/** Returns if the binder is in the module scanning phase. */
|
||||
|
||||
@@ -19,8 +19,6 @@ package com.google.inject.spi;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.internal.util.StackTraceElements;
|
||||
import com.google.inject.internal.util.StackTraceElements.InMemoryStackTraceElement;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -46,27 +44,13 @@ final class ModuleSource {
|
||||
*/
|
||||
private final BindingSourceRestriction.PermitMap permitMap;
|
||||
|
||||
/**
|
||||
* 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. For a module without a parent module the chunk starts
|
||||
* from the bottom of call stack. The array is non-empty if stack trace collection is on.
|
||||
*/
|
||||
private final InMemoryStackTraceElement[] partialCallStack;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ModuleSource} with a {@literal null} parent.
|
||||
*
|
||||
* @param moduleClass 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(
|
||||
Class<?> moduleClass,
|
||||
StackTraceElement[] partialCallStack,
|
||||
BindingSourceRestriction.PermitMap permitMap) {
|
||||
this(null, moduleClass, partialCallStack, permitMap);
|
||||
ModuleSource(Class<?> moduleClass, BindingSourceRestriction.PermitMap permitMap) {
|
||||
this(null, moduleClass, permitMap);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,13 +65,10 @@ final class ModuleSource {
|
||||
private ModuleSource(
|
||||
@Nullable ModuleSource parent,
|
||||
Class<?> moduleClass,
|
||||
StackTraceElement[] partialCallStack,
|
||||
BindingSourceRestriction.PermitMap permitMap) {
|
||||
Preconditions.checkNotNull(moduleClass, "module cannot be null.");
|
||||
Preconditions.checkNotNull(partialCallStack, "partialCallStack cannot be null.");
|
||||
this.parent = parent;
|
||||
this.moduleClassName = moduleClass.getName();
|
||||
this.partialCallStack = StackTraceElements.convertToInMemoryStackTraceElement(partialCallStack);
|
||||
this.permitMap = permitMap;
|
||||
}
|
||||
|
||||
@@ -100,31 +81,13 @@ final class ModuleSource {
|
||||
return moduleClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 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. The return array is non-empty
|
||||
* only if stack trace collection is on.
|
||||
*/
|
||||
StackTraceElement[] getPartialCallStack() {
|
||||
return StackTraceElements.convertToStackTraceElement(partialCallStack);
|
||||
}
|
||||
|
||||
/** Returns the size of partial call stack if stack trace collection is on otherwise zero. */
|
||||
int getPartialCallStackSize() {
|
||||
return partialCallStack.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a child {@link ModuleSource} corresponding to the {@link Module module}.
|
||||
*
|
||||
* @param moduleClass 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(Class<?> moduleClass, StackTraceElement[] partialCallStack) {
|
||||
return new ModuleSource(this, moduleClass, partialCallStack, permitMap);
|
||||
ModuleSource createChild(Class<?> moduleClass) {
|
||||
return new ModuleSource(this, moduleClass, permitMap);
|
||||
}
|
||||
|
||||
/** Returns the parent module {@link ModuleSource source}. */
|
||||
@@ -159,38 +122,6 @@ final class ModuleSource {
|
||||
return parent.size() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/** Returns the permit map created by the binder that installed this module. */
|
||||
BindingSourceRestriction.PermitMap getPermitMap() {
|
||||
return permitMap;
|
||||
|
||||
@@ -81,14 +81,6 @@ public class Asserts {
|
||||
return getIncludeStackTraceOption() == IncludeStackTraceOption.OFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if {@link #getIncludeStackTraceOption()} returns {@link
|
||||
* IncludeStackTraceOption#COMPLETE}.
|
||||
*/
|
||||
public static boolean isIncludeStackTraceComplete() {
|
||||
return getIncludeStackTraceOption() == IncludeStackTraceOption.COMPLETE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails unless {@code expected.equals(actual)}, {@code actual.equals(expected)} and their hash
|
||||
* codes are equal. This is useful for testing the equals method itself.
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.google.inject.spi;
|
||||
|
||||
import static com.google.inject.internal.InternalFlags.getIncludeStackTraceOption;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
@@ -25,29 +24,6 @@ public class ElementSourceTest extends TestCase {
|
||||
"Unknown Source",
|
||||
234 /* line number*/);
|
||||
|
||||
public void testCallStackSize() {
|
||||
ModuleSource moduleSource = createModuleSource();
|
||||
StackTraceElement[] bindingCallStack = new StackTraceElement[3];
|
||||
bindingCallStack[0] =
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.Elements$RecordingBinder", "bind", "Unknown Source", 200);
|
||||
bindingCallStack[1] =
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.Elements$RecordingBinder", "bind", "Unknown Source", 100);
|
||||
bindingCallStack[2] =
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$C", "configure", "Unknown Source", 100);
|
||||
ElementSource elementSource =
|
||||
new ElementSource(
|
||||
/* originalSource = */ null,
|
||||
/* trustedOriginalSource = */ false,
|
||||
/* declaringSource = */ "",
|
||||
moduleSource,
|
||||
bindingCallStack,
|
||||
/* scanner = */ null);
|
||||
assertEquals(10 /* call stack size */, elementSource.getStackTrace().length);
|
||||
}
|
||||
|
||||
public void testGetCallStack_IntegrationTest() throws Exception {
|
||||
List<Element> elements = Elements.getElements(new A());
|
||||
for (Element element : elements) {
|
||||
@@ -64,62 +40,7 @@ public class ElementSourceTest extends TestCase {
|
||||
assertEquals("com.google.inject.spi.ElementSourceTest$B", moduleClassNames.get(1));
|
||||
// Module A
|
||||
assertEquals("com.google.inject.spi.ElementSourceTest$A", moduleClassNames.get(2));
|
||||
StackTraceElement[] callStack = elementSource.getStackTrace();
|
||||
switch (getIncludeStackTraceOption()) {
|
||||
case OFF:
|
||||
// Check declaring source
|
||||
StackTraceElement stackTraceElement =
|
||||
(StackTraceElement) elementSource.getDeclaringSource();
|
||||
assertEquals(
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.ElementSourceTest$C", "configure", null, -1),
|
||||
stackTraceElement);
|
||||
// Check call stack
|
||||
assertEquals(0, callStack.length);
|
||||
return;
|
||||
case ONLY_FOR_DECLARING_SOURCE:
|
||||
// Check call stack
|
||||
assertEquals(0, callStack.length);
|
||||
return;
|
||||
case COMPLETE:
|
||||
// Check call stack
|
||||
int skippedCallStackSize = new Throwable().getStackTrace().length - 1;
|
||||
assertEquals(skippedCallStackSize + 15, elementSource.getStackTrace().length);
|
||||
assertEquals(
|
||||
"com.google.inject.spi.Elements$RecordingBinder", callStack[0].getClassName());
|
||||
assertEquals(
|
||||
"com.google.inject.spi.Elements$RecordingBinder", callStack[1].getClassName());
|
||||
assertEquals("com.google.inject.AbstractModule", callStack[2].getClassName());
|
||||
// Module C
|
||||
assertEquals(
|
||||
"com.google.inject.spi.ElementSourceTest$C", callStack[3].getClassName());
|
||||
assertEquals("configure", callStack[3].getMethodName());
|
||||
assertEquals("Unknown Source", callStack[3].getFileName());
|
||||
assertEquals("com.google.inject.AbstractModule", callStack[4].getClassName());
|
||||
assertEquals(
|
||||
"com.google.inject.spi.Elements$RecordingBinder", callStack[5].getClassName());
|
||||
// Module B
|
||||
assertEquals(
|
||||
"com.google.inject.spi.ElementSourceTest$B", callStack[6].getClassName());
|
||||
assertEquals(
|
||||
"com.google.inject.spi.Elements$RecordingBinder", callStack[7].getClassName());
|
||||
// Module A
|
||||
assertEquals("com.google.inject.AbstractModule", callStack[8].getClassName());
|
||||
assertEquals(
|
||||
"com.google.inject.spi.ElementSourceTest$A", callStack[9].getClassName());
|
||||
assertEquals("com.google.inject.AbstractModule", callStack[10].getClassName());
|
||||
assertEquals(
|
||||
"com.google.inject.spi.Elements$RecordingBinder", callStack[11].getClassName());
|
||||
assertEquals("com.google.inject.spi.Elements", callStack[12].getClassName());
|
||||
assertEquals("com.google.inject.spi.Elements", callStack[13].getClassName());
|
||||
assertEquals("com.google.inject.spi.ElementSourceTest", callStack[14].getClassName());
|
||||
// Check modules index
|
||||
List<Integer> indexes = elementSource.getModuleConfigurePositionsInStackTrace();
|
||||
assertEquals(4, (int) indexes.get(0));
|
||||
assertEquals(6, (int) indexes.get(1));
|
||||
assertEquals(10, (int) indexes.get(2));
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,25 +49,11 @@ public class ElementSourceTest extends TestCase {
|
||||
|
||||
private ModuleSource createModuleSource() {
|
||||
// First module
|
||||
StackTraceElement[] partialCallStack = new StackTraceElement[1];
|
||||
partialCallStack[0] = BINDER_INSTALL;
|
||||
ModuleSource moduleSource = new ModuleSource(A.class, partialCallStack, /* permitMap = */ null);
|
||||
ModuleSource moduleSource = new ModuleSource(A.class, /* permitMap = */ null);
|
||||
// Second module
|
||||
partialCallStack = new StackTraceElement[2];
|
||||
partialCallStack[0] = BINDER_INSTALL;
|
||||
partialCallStack[1] =
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "Unknown Source", 100);
|
||||
moduleSource = moduleSource.createChild(B.class, partialCallStack);
|
||||
moduleSource = moduleSource.createChild(B.class);
|
||||
// Third module
|
||||
partialCallStack = new StackTraceElement[4];
|
||||
partialCallStack[0] = BINDER_INSTALL;
|
||||
partialCallStack[1] = new StackTraceElement("class1", "method1", "Class1.java", 1);
|
||||
partialCallStack[2] = new StackTraceElement("class2", "method2", "Class2.java", 2);
|
||||
partialCallStack[3] =
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$B", "configure", "Unknown Source", 200);
|
||||
return moduleSource.createChild(C.class, partialCallStack);
|
||||
return moduleSource.createChild(C.class);
|
||||
}
|
||||
|
||||
private static class A extends AbstractModule {
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.google.inject.spi;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.inject.Asserts.assertContains;
|
||||
import static com.google.inject.Asserts.getDeclaringSourcePart;
|
||||
import static com.google.inject.Asserts.isIncludeStackTraceComplete;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
@@ -1364,11 +1363,6 @@ public class ElementsTest extends TestCase {
|
||||
if (!(element instanceof Message)) {
|
||||
ElementSource source = (ElementSource) element.getSource();
|
||||
assertFalse(source.getModuleClassNames().isEmpty());
|
||||
if (isIncludeStackTraceComplete()) {
|
||||
assertTrue(source.getStackTrace().length > 0);
|
||||
} else {
|
||||
assertEquals(0, source.getStackTrace().length);
|
||||
}
|
||||
}
|
||||
if (!(visitor instanceof ExternalFailureVisitor)) {
|
||||
assertContains(element.getSource().toString(), getDeclaringSourcePart(ElementsTest.class));
|
||||
|
||||
@@ -38,72 +38,28 @@ public class ModuleSourceTest extends TestCase {
|
||||
|
||||
private void checkSizeOne(ModuleSource moduleSource) {
|
||||
assertEquals(1, moduleSource.size());
|
||||
assertEquals(1, moduleSource.getStackTraceSize());
|
||||
// Check call stack
|
||||
StackTraceElement[] callStack = moduleSource.getStackTrace();
|
||||
assertEquals(BINDER_INSTALL, callStack[0]);
|
||||
}
|
||||
|
||||
private void checkSizeTwo(ModuleSource moduleSource) {
|
||||
assertEquals(2, moduleSource.size());
|
||||
assertEquals(3, moduleSource.getStackTraceSize());
|
||||
// Check call stack
|
||||
StackTraceElement[] callStack = moduleSource.getStackTrace();
|
||||
assertEquals(BINDER_INSTALL, callStack[0]);
|
||||
assertEquals(
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "Unknown Source", 100),
|
||||
callStack[1]);
|
||||
assertEquals(BINDER_INSTALL, callStack[2]);
|
||||
}
|
||||
|
||||
private void checkSizeThree(ModuleSource moduleSource) {
|
||||
assertEquals(3, moduleSource.size());
|
||||
assertEquals(7, moduleSource.getStackTraceSize());
|
||||
// Check call stack
|
||||
StackTraceElement[] callStack = moduleSource.getStackTrace();
|
||||
assertEquals(BINDER_INSTALL, callStack[0]);
|
||||
assertEquals(new StackTraceElement("class1", "method1", "Unknown Source", 1), callStack[1]);
|
||||
assertEquals(new StackTraceElement("class2", "method2", "Unknown Source", 2), callStack[2]);
|
||||
assertEquals(
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$B", "configure", "Unknown Source", 200),
|
||||
callStack[3]);
|
||||
assertEquals(BINDER_INSTALL, callStack[4]);
|
||||
|
||||
assertEquals(
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "Unknown Source", 100),
|
||||
callStack[5]);
|
||||
assertEquals(BINDER_INSTALL, callStack[6]);
|
||||
}
|
||||
|
||||
private ModuleSource createWithSizeOne() {
|
||||
StackTraceElement[] partialCallStack = new StackTraceElement[1];
|
||||
partialCallStack[0] = BINDER_INSTALL;
|
||||
return new ModuleSource(A.class, partialCallStack, /* permitMap = */ null);
|
||||
return new ModuleSource(A.class, /* permitMap = */ null);
|
||||
}
|
||||
|
||||
private ModuleSource createWithSizeTwo() {
|
||||
ModuleSource moduleSource = createWithSizeOne();
|
||||
StackTraceElement[] partialCallStack = new StackTraceElement[2];
|
||||
partialCallStack[0] = BINDER_INSTALL;
|
||||
partialCallStack[1] =
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "moduleSourceTest.java", 100);
|
||||
return moduleSource.createChild(B.class, partialCallStack);
|
||||
return moduleSource.createChild(B.class);
|
||||
}
|
||||
|
||||
private ModuleSource createWithSizeThree() {
|
||||
ModuleSource moduleSource = createWithSizeTwo();
|
||||
StackTraceElement[] partialCallStack = new StackTraceElement[4];
|
||||
partialCallStack[0] = BINDER_INSTALL;
|
||||
partialCallStack[1] = new StackTraceElement("class1", "method1", "Class1.java", 1);
|
||||
partialCallStack[2] = new StackTraceElement("class2", "method2", "Class2.java", 2);
|
||||
partialCallStack[3] =
|
||||
new StackTraceElement(
|
||||
"com.google.inject.spi.moduleSourceTest$B", "configure", "moduleSourceTest.java", 200);
|
||||
return moduleSource.createChild(C.class, partialCallStack);
|
||||
return moduleSource.createChild(C.class);
|
||||
}
|
||||
|
||||
private static class A extends AbstractModule {
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.google.inject.spi;
|
||||
|
||||
import static com.google.inject.Asserts.assertContains;
|
||||
import static com.google.inject.Asserts.getDeclaringSourcePart;
|
||||
import static com.google.inject.Asserts.isIncludeStackTraceComplete;
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -456,11 +455,6 @@ public class SpiBindingsTest extends TestCase {
|
||||
assertContains(binding.getSource().toString(), getDeclaringSourcePart(getClass()));
|
||||
ElementSource source = (ElementSource) binding.getSource();
|
||||
assertFalse(source.getModuleClassNames().isEmpty());
|
||||
if (isIncludeStackTraceComplete()) {
|
||||
assertTrue(source.getStackTrace().length > 0);
|
||||
} else {
|
||||
assertEquals(0, source.getStackTrace().length);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkInjector(Module module, ElementVisitor<?>... visitors) {
|
||||
|
||||
@@ -315,14 +315,6 @@ See the Apache License Version 2.0 for the specific language governing permissio
|
||||
<argLine>-Dguice_include_stack_traces=OFF</argLine>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stack-traces-complete</id>
|
||||
<phase>test</phase>
|
||||
<goals><goal>test</goal></goals>
|
||||
<configuration>
|
||||
<argLine>-Dguice_include_stack_traces=COMPLETE</argLine>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-test</id>
|
||||
<phase>test</phase>
|
||||
|
||||
Reference in New Issue
Block a user