fix generic handling of extension processor

This commit is contained in:
Sebastian Sdorra
2014-12-21 00:42:21 +01:00
parent 4644975408
commit 7ead62bb64
4 changed files with 12 additions and 10 deletions

View File

@@ -98,9 +98,10 @@ public final class Priorities
* *
* @return sorted class list * @return sorted class list
*/ */
public static <T> List<Class<T>> sort(Iterable<Class<T>> unordered) public static <T> List<Class<? extends T>> sort(
Iterable<Class<? extends T>> unordered)
{ {
return new PriorityOrdering().sortedCopy(unordered); return new PriorityOrdering<T>().sortedCopy(unordered);
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
@@ -133,7 +134,7 @@ public final class Priorities
* *
* @param <T> type of class * @param <T> type of class
*/ */
public static class PriorityOrdering<T> extends Ordering<Class<T>> public static class PriorityOrdering<T> extends Ordering<Class<? extends T>>
{ {
/** /**
@@ -146,7 +147,7 @@ public final class Priorities
* @return compare value * @return compare value
*/ */
@Override @Override
public int compare(Class<T> left, Class<T> right) public int compare(Class<? extends T> left, Class<? extends T> right)
{ {
return Ints.compare(getPriority(left), getPriority(right)); return Ints.compare(getPriority(left), getPriority(right));
} }

View File

@@ -50,10 +50,11 @@ public interface ExtensionProcessor
* *
* @param <T> type of extension * @param <T> type of extension
* @param extensionPoint extension point * @param extensionPoint extension point
* *
* @return extensions * @return extensions
*/ */
public <T> Iterable<Class<T>> byExtensionPoint(Class<T> extensionPoint); public <T> Iterable<Class<? extends T>> byExtensionPoint(
Class<T> extensionPoint);
/** /**
* Returns single extension by its extension point. * Returns single extension by its extension point.
@@ -61,10 +62,10 @@ public interface ExtensionProcessor
* *
* @param <T> type of extension * @param <T> type of extension
* @param extensionPoint extension point * @param extensionPoint extension point
* *
* @return extension * @return extension
*/ */
public <T> Class<T> oneByExtensionPoint(Class<T> extensionPoint); public <T> Class<? extends T> oneByExtensionPoint(Class<T> extensionPoint);
/** /**
* Process auto bind extensions. * Process auto bind extensions.

View File

@@ -217,7 +217,7 @@ public class ScmContextListener extends GuiceServletContextListener
*/ */
private void appendModules(ExtensionProcessor ep, List<Module> moduleList) private void appendModules(ExtensionProcessor ep, List<Module> moduleList)
{ {
for (Class<Module> module : ep.byExtensionPoint(Module.class)) for (Class<? extends Module> module : ep.byExtensionPoint(Module.class))
{ {
try try
{ {

View File

@@ -102,7 +102,7 @@ public class ScmSecurityModule extends ShiroWebModule
expose(PasswordService.class); expose(PasswordService.class);
// bind realm // bind realm
for (Class<Realm> realm : extensionProcessor.byExtensionPoint(Realm.class)) for (Class<? extends Realm> realm : extensionProcessor.byExtensionPoint(Realm.class))
{ {
logger.info("bind security realm {}", realm); logger.info("bind security realm {}", realm);
bindRealm().to(realm); bindRealm().to(realm);