@DisplayName("test_getLoader_NotSpiAnnotation") @Test void testGetLoaderNotSpiAnnotation() { try { SpiLoader.getLoader(Output.class); fail(); } catch (IllegalArgumentException e) { assertEquals("Spi type io.github.ukuz.piccolo.api.spi.Output must annotated with @Spi", e.getMessage()); } }
@SuppressWarnings("unchecked") public static <T> SpiLoader<T> getLoader(Class<T> type) { if (type == null) { throw new IllegalArgumentException("Spi type must not be null"); } if (!type.isInterface()) { throw new IllegalArgumentException("Spi type " + type.getName() + " must an interface"); } if (!type.isAnnotationPresent(Spi.class)) { throw new IllegalArgumentException("Spi type " + type.getName() + " must annotated with @Spi"); } return LOADERS.computeIfAbsent(type, t -> new SpiLoader(t)); }
SpiLoader { @SuppressWarnings("unchecked") public static <T> SpiLoader<T> getLoader(Class<T> type) { if (type == null) { throw new IllegalArgumentException("Spi type must not be null"); } if (!type.isInterface()) { throw new IllegalArgumentException("Spi type " + type.getName() + " must an interface"); } if (!type.isAnnotationPresent(Spi.class)) { throw new IllegalArgumentException("Spi type " + type.getName() + " must annotated with @Spi"); } return LOADERS.computeIfAbsent(type, t -> new SpiLoader(t)); } }
SpiLoader { @SuppressWarnings("unchecked") public static <T> SpiLoader<T> getLoader(Class<T> type) { if (type == null) { throw new IllegalArgumentException("Spi type must not be null"); } if (!type.isInterface()) { throw new IllegalArgumentException("Spi type " + type.getName() + " must an interface"); } if (!type.isAnnotationPresent(Spi.class)) { throw new IllegalArgumentException("Spi type " + type.getName() + " must annotated with @Spi"); } return LOADERS.computeIfAbsent(type, t -> new SpiLoader(t)); } private  SpiLoader(Class<T> type); }
SpiLoader { @SuppressWarnings("unchecked") public static <T> SpiLoader<T> getLoader(Class<T> type) { if (type == null) { throw new IllegalArgumentException("Spi type must not be null"); } if (!type.isInterface()) { throw new IllegalArgumentException("Spi type " + type.getName() + " must an interface"); } if (!type.isAnnotationPresent(Spi.class)) { throw new IllegalArgumentException("Spi type " + type.getName() + " must annotated with @Spi"); } return LOADERS.computeIfAbsent(type, t -> new SpiLoader(t)); } private  SpiLoader(Class<T> type); @SuppressWarnings("unchecked") static SpiLoader<T> getLoader(Class<T> type); T getExtension(); T getExtension(String key); }
SpiLoader { @SuppressWarnings("unchecked") public static <T> SpiLoader<T> getLoader(Class<T> type) { if (type == null) { throw new IllegalArgumentException("Spi type must not be null"); } if (!type.isInterface()) { throw new IllegalArgumentException("Spi type " + type.getName() + " must an interface"); } if (!type.isAnnotationPresent(Spi.class)) { throw new IllegalArgumentException("Spi type " + type.getName() + " must annotated with @Spi"); } return LOADERS.computeIfAbsent(type, t -> new SpiLoader(t)); } private  SpiLoader(Class<T> type); @SuppressWarnings("unchecked") static SpiLoader<T> getLoader(Class<T> type); T getExtension(); T getExtension(String key);  }