public final class ElementSource
extends java.lang.Object
element
was
bound.
The declaring source
refers to a location in
source code that defines the Guice element
. For example, if
the element is created from a method annotated by @Provides, the
declaring source of element would be the method itself.
The getStackTrace()
refers to the sequence of calls ends at one of
Binder
bindXXX()
methods and eventually
defines the element. Note that getStackTrace()
lists
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
guice_include_stack_traces
flag value. The value can be either
OFF
, ONLY_FOR_DECLARING_SOURCE
or COMPLETE
. Note that
collecting stack traces for every binding can cause a performance hit when
the injector is created.
The sequence of class names of modules
involved in the element creation can be retrieved by
getModuleClassNames()
. Similar to getStackTrace()
, the
order is reverse chronological. The first module (index 0) is the module that
installs the element
. The last module is the root module.
In order to support the cases where a Guice element
is
created from another Guice element
(original) (e.g., by
Element.applyTo(com.google.inject.Binder)
), it also provides a reference to the original
element source (getOriginalElementSource()
).
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.Object |
declaringSource
Refers to a single location in source code that causes the element creation.
|
(package private) ModuleSource |
moduleSource
The
source of module creates the element. |
(package private) ElementSource |
originalElementSource
The
source of element that this element created from (if there is any),
otherwise null . |
(package private) StackTraceElements.InMemoryStackTraceElement[] |
partialCallStack
The partial call stack that starts at the last module
configure(Binder) call. |
Constructor and Description |
---|
ElementSource(ElementSource originalSource,
java.lang.Object declaringSource,
ModuleSource moduleSource,
java.lang.StackTraceElement[] partialCallStack)
Creates a new from the given parameters.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getDeclaringSource()
Returns a single location in source code that defines the element.
|
java.util.List<java.lang.String> |
getModuleClassNames()
Returns the class names of modules involved in creating this
Element . |
java.util.List<java.lang.Integer> |
getModuleConfigurePositionsInStackTrace()
Returns the position of
configure(Binder) method
call in the stack trace for modules that their classes returned by
getModuleClassNames() . |
ElementSource |
getOriginalElementSource()
Returns the
ElementSource of the element this was created or copied from. |
java.lang.StackTraceElement[] |
getStackTrace()
Returns the sequence of method calls that ends at one of
Binder
bindXXX() methods and eventually defines the element. |
java.lang.String |
toString()
Returns
getDeclaringSource().toString() value. |
final ElementSource originalElementSource
source
of element that this element created from (if there is any),
otherwise null
.final ModuleSource moduleSource
source
of module creates the element.final StackTraceElements.InMemoryStackTraceElement[] partialCallStack
configure(Binder)
call. The value is empty if stack trace collection is off.final java.lang.Object declaringSource
Constructor
, Method
, Field
, StackTraceElement
,
etc. For example, if the element is created from a method annotated by @Provides,
the declaring source of element would be the method itself.ElementSource(ElementSource originalSource, java.lang.Object declaringSource, ModuleSource moduleSource, java.lang.StackTraceElement[] partialCallStack)
originalElementSource
- The source of element that this element created from (if there is
any), otherwise null
.declaringSource
- the source (in)directly declared the element.moduleSource
- the moduleSource when the element is boundpartialCallStack
- the partial call stack from the top module to where the element is
boundpublic ElementSource getOriginalElementSource()
ElementSource
of the element this was created or copied from. If this was
not created or copied from another element, returns null
.public java.lang.Object getDeclaringSource()
Constructor
, Method
,
Field
, StackTraceElement
, etc. For
example, if the element is created from a method annotated by @Provides, the
declaring source of element would be the method itself.public java.util.List<java.lang.String> getModuleClassNames()
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 java.util.List<java.lang.Integer> getModuleConfigurePositionsInStackTrace()
configure(Binder)
method
call in the stack trace
for modules that their classes returned by
getModuleClassNames()
. For example, if the stack trace looks like the following:
0 - Binder.bind(),
1 - ModuleTwo.configure(),
2 - Binder.install(),
3 - ModuleOne.configure(),
4 - theRest().
1 and 3 are returned.
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 java.lang.StackTraceElement[] getStackTrace()
Binder
bindXXX()
methods and eventually defines the element. Note that
getStackTrace()
lists 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 java.lang.String toString()
getDeclaringSource().toString()
value.toString
in class java.lang.Object