diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2019-05-02 14:11:30 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2019-05-02 14:11:30 +0300 |
commit | 1d36fcff75cfe38639fc1a8a28eefc79e8e7286f (patch) | |
tree | 8eb09080a052f54537632dd25ecb2b3b5b985698 /pf4j/src/main/java/org | |
parent | a6ce0a6ace6c03a7369236350b5f8e4a61e4c381 (diff) | |
download | pf4j-1d36fcff75cfe38639fc1a8a28eefc79e8e7286f.tar.gz pf4j-1d36fcff75cfe38639fc1a8a28eefc79e8e7286f.zip |
Resolve #296
Diffstat (limited to 'pf4j/src/main/java/org')
-rw-r--r-- | pf4j/src/main/java/org/pf4j/AbstractPluginManager.java | 73 | ||||
-rw-r--r-- | pf4j/src/main/java/org/pf4j/PluginManager.java | 4 |
2 files changed, 33 insertions, 44 deletions
diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index a7333ca..478149d 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -525,60 +525,25 @@ public abstract class AbstractPluginManager implements PluginManager { return extensionClasses; } - @SuppressWarnings("unchecked") - @Override - public <T> List<Class<T>> getExtensionClasses(Class<T> type) { - List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type); - List<Class<T>> extensionClasses = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { - Class<T> c = (Class<T>) extensionWrapper.getDescriptor().extensionClass; - extensionClasses.add(c); - } - return extensionClasses; + @Override + public <T> List<Class<? extends T>> getExtensionClasses(Class<T> type) { + return getExtensionClasses(extensionFinder.find(type)); } - @SuppressWarnings("unchecked") @Override - public <T> List<Class<T>> getExtensionClasses(Class<T> type, String pluginId) { - List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type, pluginId); - List<Class<T>> extensionClasses = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { - Class<T> c = (Class<T>) extensionWrapper.getDescriptor().extensionClass; - extensionClasses.add(c); - } - - return extensionClasses; + public <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId) { + return getExtensionClasses(extensionFinder.find(type, pluginId)); } @Override public <T> List<T> getExtensions(Class<T> type) { - List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type); - List<T> extensions = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { - try { - extensions.add(extensionWrapper.getExtension()); - } catch (PluginException e) { - log.error("Cannot retrieve extension", e); - } - } - - return extensions; + return getExtensions(extensionFinder.find(type)); } @Override public <T> List<T> getExtensions(Class<T> type, String pluginId) { - List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type, pluginId); - List<T> extensions = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { - try { - extensions.add(extensionWrapper.getExtension()); - } catch (PluginException e) { - log.error("Cannot retrieve extension", e); - } - } - - return extensions; + return getExtensions(extensionFinder.find(type, pluginId)); } @Override @@ -943,4 +908,28 @@ public abstract class AbstractPluginManager implements PluginManager { return pluginDescriptor.getPluginId() + "@" + pluginDescriptor.getVersion(); } + @SuppressWarnings("unchecked") + private <T> List<Class<? extends T>> getExtensionClasses(List<ExtensionWrapper<T>> extensionsWrapper) { + List<Class<? extends T>> extensionClasses = new ArrayList<>(extensionsWrapper.size()); + for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { + Class<T> c = (Class<T>) extensionWrapper.getDescriptor().extensionClass; + extensionClasses.add(c); + } + + return extensionClasses; + } + + private <T> List<T> getExtensions(List<ExtensionWrapper<T>> extensionsWrapper) { + List<T> extensions = new ArrayList<>(extensionsWrapper.size()); + for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { + try { + extensions.add(extensionWrapper.getExtension()); + } catch (PluginException e) { + log.error("Cannot retrieve extension", e); + } + } + + return extensions; + } + } diff --git a/pf4j/src/main/java/org/pf4j/PluginManager.java b/pf4j/src/main/java/org/pf4j/PluginManager.java index a283738..badba28 100644 --- a/pf4j/src/main/java/org/pf4j/PluginManager.java +++ b/pf4j/src/main/java/org/pf4j/PluginManager.java @@ -135,9 +135,9 @@ public interface PluginManager { List<Class<?>> getExtensionClasses(String pluginId); - <T> List<Class<T>> getExtensionClasses(Class<T> type); + <T> List<Class<? extends T>> getExtensionClasses(Class<T> type); - <T> List<Class<T>> getExtensionClasses(Class<T> type, String pluginId); + <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId); <T> List<T> getExtensions(Class<T> type); |