Skip to content

Commit c68bf45

Browse files
committed
Do not inject delegate command classes
Instead, let the ServicePreprocessor handle them. It turns out it is very tricky to inject the context into the Command instance at the proper time. The best time would be precisely when the CommandModule instance has its context injected, but unfortunately, there is no hook to trigger behavior in response to context injection. It is not guaranteed that Contextual#setContext(Context) be called. Injecting the context into the Command instance during ContextModule#initialize() appeared to work on the surface, but actually deferred population of Service parameters until the InitPreprocessor was called; such behavior was unintuitive and dare I say bogus. Furthermore, by suppressing Service and Context parameters from the list of Command inputs, we made commands behave differently than scripts: the latter report Service and Context parameters as input parameters, whereas the former did not. With this change, that discrepancy is fixed.
1 parent 85122f6 commit c68bf45

File tree

2 files changed

+0
-15
lines changed

2 files changed

+0
-15
lines changed

src/main/java/org/scijava/command/CommandInfo.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.Map;
4242

4343
import org.scijava.Cancelable;
44-
import org.scijava.Context;
4544
import org.scijava.InstantiableException;
4645
import org.scijava.ItemIO;
4746
import org.scijava.ItemVisibility;
@@ -55,7 +54,6 @@
5554
import org.scijava.plugin.Parameter;
5655
import org.scijava.plugin.Plugin;
5756
import org.scijava.plugin.PluginInfo;
58-
import org.scijava.service.Service;
5957
import org.scijava.util.ClassUtils;
6058
import org.scijava.util.StringMaker;
6159

@@ -451,11 +449,6 @@ private void checkFields(final Class<?> type) {
451449
for (final Field f : fields) {
452450
f.setAccessible(true); // expose private fields
453451

454-
// NB: Skip types handled by the application framework itself.
455-
// I.e., these parameters get injected by Context#inject(Object).
456-
if (Service.class.isAssignableFrom(f.getType())) continue;
457-
if (Context.class.isAssignableFrom(f.getType())) continue;
458-
459452
final Parameter param = f.getAnnotation(Parameter.class);
460453

461454
boolean valid = true;

src/main/java/org/scijava/command/CommandModule.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.scijava.InstantiableException;
4040
import org.scijava.NullContextException;
4141
import org.scijava.module.AbstractModule;
42-
import org.scijava.module.MethodCallException;
4342
import org.scijava.module.Module;
4443
import org.scijava.module.ModuleException;
4544
import org.scijava.module.ModuleInfo;
@@ -144,13 +143,6 @@ public void cancel() {
144143
previewPlugin.cancel();
145144
}
146145

147-
@Override
148-
public void initialize() throws MethodCallException {
149-
// NB: Inject the context into the command before initializing.
150-
getContext().inject(command);
151-
super.initialize();
152-
}
153-
154146
@Override
155147
public CommandInfo getInfo() {
156148
return info;

0 commit comments

Comments
 (0)