Skip to content

Commit 952a4c8

Browse files
committed
Make DynamicCommand work when not in plugin index
This enables some new use cases: e.g. it becomes possible to make a DynamicCommand anonymous subclass as a local variable in a method, for the purpose of using it once, without registering it in the context.
1 parent 9de270c commit 952a4c8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public abstract class DynamicCommand extends DefaultMutableModule implements
7979
public DynamicCommandInfo getInfo() {
8080
if (info == null) {
8181
// NB: Create dynamic metadata lazily.
82-
final CommandInfo commandInfo = commandService.getCommand(getClass());
82+
CommandInfo commandInfo = commandService.getCommand(getClass());
83+
if (commandInfo == null) commandInfo = new CommandInfo(getClass());
8384
info = new DynamicCommandInfo(commandInfo, getClass());
8485
}
8586
return info;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
* Helper class for maintaining a {@link DynamicCommand}'s associated
5252
* {@link ModuleInfo}.
5353
* <p>
54-
* The {@link CommandService} has a plain {@link CommandInfo} object in its
55-
* index, populated from the {@link DynamicCommand}'s @{@link Plugin}
56-
* annotation. So this class adapts that object, delegating to it for the
54+
* This class wraps a plain {@link CommandInfo} object (e.g. from the
55+
* {@link CommandService}'s index, present due to an @{@link Plugin} annotation
56+
* on the {@link DynamicCommand} class), delegating to it for the
5757
* {@link UIDetails} methods. The plain {@link CommandInfo} cannot be used
5858
* as-is, however, because we need to override the {@link ModuleInfo} methods as
5959
* well as provide metadata manipulation functionality such as

0 commit comments

Comments
 (0)