Class ElementSource
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 sequence of class names of modules involved in the
element creation can be retrieved by getModuleClassNames(). The order of the module
class names 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()).
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ObjectRefers to a single location in source code that causes the element creation.(package private) final ModuleSourceThesourceof module creates the element.(package private) final ElementSourceThesourceof element that this element created from (if there is any), otherwisenull.(package private) final ModuleAnnotatedMethodScannerThe scanner that created this binding (if it was created by a scanner).(package private) final booleanWheather the originalElementSource was set externaly (untrusted) or by Guice internals (trusted). -
Constructor Summary
ConstructorsConstructorDescriptionElementSource(ElementSource originalSource, boolean trustedOriginalSource, Object declaringSource, ModuleSource moduleSource, ModuleAnnotatedMethodScanner scanner) Creates a new from the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionReturns a single location in source code that defines the element.Returns the class names of modules involved in creating thisElement.Returns theElementSourceof the element this was created or copied from.toString()ReturnsgetDeclaringSource().toString()value.
-
Field Details
-
originalElementSource
Thesourceof element that this element created from (if there is any), otherwisenull. -
trustedOriginalElementSource
final boolean trustedOriginalElementSourceWheather the originalElementSource was set externaly (untrusted) or by Guice internals (trusted).External code can set the originalElementSource to an arbitrary ElementSource via Binder.withSource(ElementSource), thereby spoofing the element origin.
-
moduleSource
Thesourceof module creates the element. -
declaringSource
Refers to a single location in source code that causes the element creation. It can be any object such as,invalid reference
Constructor,invalid reference
Method,invalid reference
FieldStackTraceElement, etc. For example, if the element is created from a method annotated by @Provides, the declaring source of element would be the method itself. -
scanner
The scanner that created this binding (if it was created by a scanner).
-
-
Constructor Details
-
ElementSource
ElementSource(@Nullable ElementSource originalSource, boolean trustedOriginalSource, Object declaringSource, ModuleSource moduleSource, ModuleAnnotatedMethodScanner scanner) Creates a new from the given parameters.- Parameters:
originalSource- The source of element that this element was created from (if there is any), otherwisenull.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 bound
-
-
Method Details
-
getOriginalElementSource
Returns theElementSourceof the element this was created or copied from. If this was not created or copied from another element, returnsnull. -
getDeclaringSource
Returns a single location in source code that defines the element. It can be any object such asConstructor,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. -
getModuleClassNames
Returns the class names of modules involved in creating thisElement. 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. -
toString
ReturnsgetDeclaringSource().toString()value.
-