Skip to content

Commit a196883

Browse files
committed
ShadowMenu: give details on duplicates
In particular, it helps to know which JAR file each entry came from.
1 parent 75146d3 commit a196883

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/main/java/org/scijava/menu/ShadowMenu.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,13 @@ else if (existingChild != null) {
549549
if (childInfo != null && info.getPriority() == childInfo.getPriority())
550550
{
551551
log.warn("ShadowMenu: menu item already exists:\n" + //
552-
"\texisting: " + childInfo + "\n" + //
553-
"\t ignored: " + info);
552+
"\texisting: " + details(childInfo) + "\n" + //
553+
"\t ignored: " + details(info));
554554
}
555555
else {
556556
log.debug("ShadowMenu: higher-priority menu item already exists:\n" +
557-
"\texisting: " + childInfo + "\n" + //
558-
"\t ignored: " + info);
557+
"\texisting: " + details(childInfo) + "\n" + //
558+
"\t ignored: " + details(info));
559559
}
560560
}
561561
}
@@ -566,6 +566,21 @@ private boolean isLeaf(final int depth, final MenuPath path) {
566566
return depth == path.size() - 1;
567567
}
568568

569+
private String details(final ModuleInfo info) {
570+
if (info == null) return "<null>";
571+
String className, classLocation;
572+
try {
573+
final Class<?> c = info.loadDelegateClass();
574+
className = c.getName();
575+
classLocation = ClassUtils.getLocation(c).toString();
576+
}
577+
catch (final ClassNotFoundException exc) {
578+
className = info.getDelegateClassName();
579+
classLocation = "<invalid>";
580+
}
581+
return info.getMenuPath() + " : " + className + " [" + classLocation + "]";
582+
}
583+
569584
private ShadowMenu getMenu(final MenuPath menuPath, final int index) {
570585
final MenuEntry entry = menuPath.get(index);
571586

0 commit comments

Comments
 (0)