|
23 | 23 | import build.base.commandline.CommandLine; |
24 | 24 | import build.base.configuration.Configuration; |
25 | 25 | import build.base.configuration.ConfigurationBuilder; |
26 | | -import build.base.foundation.Introspection; |
27 | 26 | import build.base.logging.Logger; |
28 | 27 | import build.base.naming.UniqueNameGenerator; |
29 | 28 | import build.base.option.TemporaryDirectory; |
|
34 | 33 | import build.base.table.option.RowComparator; |
35 | 34 | import build.base.table.option.TableName; |
36 | 35 | import build.codemodel.foundation.usage.GenericTypeUsage; |
37 | | -import build.codemodel.foundation.usage.NamedTypeUsage; |
38 | 36 | import build.codemodel.injection.Binding; |
39 | 37 | import build.codemodel.injection.Context; |
40 | 38 | import build.codemodel.injection.Dependency; |
|
52 | 50 | import java.util.HashMap; |
53 | 51 | import java.util.Iterator; |
54 | 52 | import java.util.LinkedHashSet; |
| 53 | +import java.util.List; |
55 | 54 | import java.util.Objects; |
56 | 55 | import java.util.Optional; |
57 | 56 | import java.util.Set; |
@@ -243,68 +242,41 @@ public A launch(final P platform, |
243 | 242 |
|
244 | 243 | // allow the process interfaces to be used for injection |
245 | 244 | launchContext.bind((Class) process.getClass()).to(process); |
246 | | - |
247 | | - Introspection.getAll(process.getClass(), Class::getInterfaces) |
248 | | - .filter(i -> !i.equals(Addressable.class)) |
249 | | - .forEach(i -> launchContext.bind((Class) i).to(process)); |
| 245 | + launchContext.bind(process).asAllInterfaces(i -> !i.equals(Addressable.class)); |
250 | 246 |
|
251 | 247 | // instantiate individual facets |
252 | 248 | final Set<Facet<?>> facets = launchOptions.stream(Facet.class) |
253 | 249 | .map(facet -> (Facet<?>) facet) |
254 | 250 | .map(facet -> { |
255 | 251 | final Object implementation = facet.getFactory().apply(launchContext); |
256 | 252 |
|
257 | | - // allow injection of facets |
| 253 | + // allow injection of facets individually and as Iterable<T> |
258 | 254 | launchContext.bind((Class<Object>) facet.getInterface()).to(implementation); |
| 255 | + launchContext.bindSet((Class<Object>) facet.getInterface()).add(implementation); |
259 | 256 |
|
260 | 257 | // create a synthetic Facet that always resolves to the same implementation |
261 | 258 | return Facet.of(facet.getInterface(), _ -> facet.getInterface().cast(implementation)); |
262 | 259 | }) |
263 | 260 | .collect(Collectors.toSet()); |
264 | 261 |
|
265 | | - // allow Iterable<T> to be resolved for injection where T is implemented by zero or more Facets. |
| 262 | + // fallback: return an empty Iterable<T> for any T not populated via bindSet above |
266 | 263 | launchContext.addResolver(new Resolver<Iterable<Object>>() { |
267 | 264 | @Override |
268 | 265 | public Optional<? extends Binding<Iterable<Object>>> resolve(final Dependency dependency) { |
269 | | - |
270 | 266 | if (dependency.typeUsage() instanceof GenericTypeUsage genericTypeUsage |
271 | 267 | && genericTypeUsage.typeName().canonicalName().equals(Iterable.class.getCanonicalName()) |
272 | 268 | && genericTypeUsage.parameters().count() == 1) { |
273 | | - |
274 | | - final var parameterTypeUsage = genericTypeUsage.parameters() |
275 | | - .findFirst() |
276 | | - .orElseThrow(); |
277 | | - |
278 | | - if (parameterTypeUsage instanceof NamedTypeUsage namedTypeUsage) { |
279 | | - try { |
280 | | - final var parameterClass = this.getClass() |
281 | | - .getClassLoader() |
282 | | - .loadClass(namedTypeUsage.typeName().canonicalName()); |
283 | | - |
284 | | - // find the Facets that implement T |
285 | | - final var list = facets.stream() |
286 | | - .map(facet -> parameterClass.cast(facet.getFactory().apply(launchContext))) |
287 | | - .filter(parameterClass::isInstance) |
288 | | - .toList(); |
289 | | - |
290 | | - return Optional.of(new ValueBinding<Iterable<Object>>() { |
291 | | - @Override |
292 | | - @SuppressWarnings("unchecked") |
293 | | - public Iterable<Object> value() { |
294 | | - return (Iterable<Object>) list; |
295 | | - } |
296 | | - |
297 | | - @Override |
298 | | - public Dependency dependency() { |
299 | | - return dependency; |
300 | | - } |
301 | | - }); |
| 269 | + return Optional.of(new ValueBinding<Iterable<Object>>() { |
| 270 | + @Override |
| 271 | + public Iterable<Object> value() { |
| 272 | + return List.of(); |
302 | 273 | } |
303 | | - catch (final ClassNotFoundException e) { |
304 | | - LOGGER.debug("Could not load class [{0}] for Iterable injection resolution", |
305 | | - namedTypeUsage.typeName().canonicalName(), e); |
| 274 | + |
| 275 | + @Override |
| 276 | + public Dependency dependency() { |
| 277 | + return dependency; |
306 | 278 | } |
307 | | - } |
| 279 | + }); |
308 | 280 | } |
309 | 281 |
|
310 | 282 | return Optional.empty(); |
|
0 commit comments