Skip to content

Commit c09937e

Browse files
committed
Context: recursively inject the context
For each non-Service, non-Context, non-primitive @parameter, check whether it is already assigned a value, and if so, inject the context into that value. This makes it much easier to compose a class whose member fields also need to know the context at the same time as the containing class. See next commit for an example.
1 parent 3d158e5 commit c09937e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/java/org/scijava/Context.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ else if (Context.class.isAssignableFrom(type) && type.isInstance(this)) {
471471
// populate Context parameter
472472
ClassUtils.setValue(f, o, this);
473473
}
474+
else if (!type.isPrimitive()) {
475+
// the parameter is some other object; if it is non-null, we recurse
476+
final Object value = ClassUtils.getValue(f, o);
477+
if (value != null) inject(value);
478+
}
474479
}
475480
catch (final Throwable t) {
476481
handleSafely(t);

0 commit comments

Comments
 (0)