protected Class<?> getDelegateClass() { try { return info.loadDelegateClass(); } catch (final ClassNotFoundException exc) { // TODO: Consider a better error handling mechanism here. throw new IllegalStateException(exc); } }
protected Class<?> getDelegateClass() { try { return info.loadDelegateClass(); } catch (final ClassNotFoundException exc) { // TODO: Consider a better error handling mechanism here. throw new IllegalStateException(exc); } }
private <T> Class<?> delegateClass(final ModuleItem<T> item) { try { return item.getInfo().loadDelegateClass(); } catch (final ClassNotFoundException exc) { throw new IllegalStateException(exc); } }
@Override default String getLocation() { // NB: By default, we use the location of the delegate class. // If the same delegate class is used for more than one module, though, // it may need to override this method to indicate a different location. try { return Types.location(loadDelegateClass()).toExternalForm(); } catch (final ClassNotFoundException exc) { return null; } }
@Override default String getVersion() { // NB: By default, we use the version of the delegate class's JAR archive. // If the same delegate class is used for more than one module, though, // it may need to override this method to indicate a different version. try { return VersionUtils.getVersion(loadDelegateClass()); } catch (final ClassNotFoundException exc) { return null; } } }
private <T> Class<?> delegateClass(final ModuleItem<T> item) { try { return item.getInfo().loadDelegateClass(); } catch (final ClassNotFoundException exc) { throw new IllegalStateException(exc); } }
@Override default String getLocation() { // NB: By default, we use the location of the delegate class. // If the same delegate class is used for more than one module, though, // it may need to override this method to indicate a different location. try { return Types.location(loadDelegateClass()).toExternalForm(); } catch (final ClassNotFoundException exc) { return null; } }
@Override default String getVersion() { // NB: By default, we use the version of the delegate class's JAR archive. // If the same delegate class is used for more than one module, though, // it may need to override this method to indicate a different version. try { return VersionUtils.getVersion(loadDelegateClass()); } catch (final ClassNotFoundException exc) { return null; } } }
private String details(final ModuleInfo info) { if (info == null) return "<null>"; String className, classLocation; try { final Class<?> c = info.loadDelegateClass(); className = c.getName(); classLocation = Types.location(c).toString(); } catch (final ClassNotFoundException exc) { className = info.getDelegateClassName(); classLocation = "<invalid>"; } return info.getMenuPath() + " : " + className + " [" + classLocation + "]"; }
private String details(final ModuleInfo info) { if (info == null) return "<null>"; String className, classLocation; try { final Class<?> c = info.loadDelegateClass(); className = c.getName(); classLocation = Types.location(c).toString(); } catch (final ClassNotFoundException exc) { className = info.getDelegateClassName(); classLocation = "<invalid>"; } return info.getMenuPath() + " : " + className + " [" + classLocation + "]"; }
@Override public T getDefaultValue() { // NB: The default value for a command is the initial field value. // E.g.: // // @Parameter // private int weekdays = 5; // // To obtain this information, we need to instantiate the module, then // extract the value of the associated field. // // Of course, the command might do evil things like: // // @Parameter // private long time = System.currentTimeMillis(); // // In which case the default value will vary by instance. But there is // nothing we can really do about that. This is only a best effort. try { final Object dummy = getInfo().loadDelegateClass().newInstance(); @SuppressWarnings("unchecked") final T value = (T) getField().get(dummy); return value; } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException exc) { throw new IllegalStateException(exc); } }
@Override public T getDefaultValue() { // NB: The default value for a command is the initial field value. // E.g.: // // @Parameter // private int weekdays = 5; // // To obtain this information, we need to instantiate the module, then // extract the value of the associated field. // // Of course, the command might do evil things like: // // @Parameter // private long time = System.currentTimeMillis(); // // In which case the default value will vary by instance. But there is // nothing we can really do about that. This is only a best effort. try { final Object dummy = getInfo().loadDelegateClass().newInstance(); @SuppressWarnings("unchecked") final T value = (T) getField().get(dummy); return value; } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException exc) { throw new IllegalStateException(exc); } }
private void source(final ModuleInfo info) { // HACK: For now, we special case each kind of module. // In the future, we should make it more extensible. // HelpService? ModuleService#help? Some other type of plugin? if (info instanceof ScriptInfo) { // SciJava script. sourceForScript((ScriptInfo) info); return; } final String id = info.getIdentifier(); if (id != null && id.startsWith("legacy:")) { // ImageJ 1.x command. sourceForLegacyCommand(info); return; } try { // Some other kind of module; use the delegate class. sourceForClass(info, info.loadDelegateClass()); } catch (final ClassNotFoundException exc) { log.debug(exc); errorMessage(info); } }
String jarPath; try { final URL location = Types.location(item.info.loadDelegateClass()); jarPath = location == null ? "<unknown>" : location.toString();