diff --git a/pico/api/src/main/java/io/helidon/pico/api/Services.java b/pico/api/src/main/java/io/helidon/pico/api/Services.java index 74a1f4553df..c607ab39e85 100644 --- a/pico/api/src/main/java/io/helidon/pico/api/Services.java +++ b/pico/api/src/main/java/io/helidon/pico/api/Services.java @@ -110,13 +110,11 @@ Optional> lookupFirst(Class type, * Retrieves the first match based upon the passed service info criteria. * * @param criteria the criteria to find - * @param the type of the service * @return the best service provider * @throws io.helidon.pico.api.PicoException if resolution fails to resolve a match */ - @SuppressWarnings("unchecked") - default ServiceProvider lookup(ServiceInfoCriteria criteria) { - return (ServiceProvider) lookupFirst(criteria, true).orElseThrow(); + default ServiceProvider lookup(ServiceInfoCriteria criteria) { + return lookupFirst(criteria, true).orElseThrow(); } /** @@ -124,12 +122,11 @@ default ServiceProvider lookup(ServiceInfoCriteria criteria) { * * @param criteria the criteria to find * @param expected indicates whether the provider should throw if a match is not found - * @param the type of the service * @return the best service provider matching the criteria, or {@code empty} if (@code expected = false) and no match found * @throws io.helidon.pico.api.PicoException if expected=true and resolution fails to resolve a match */ - Optional> lookupFirst(ServiceInfoCriteria criteria, - boolean expected); + Optional> lookupFirst(ServiceInfoCriteria criteria, + boolean expected); /** * Retrieves the first match based upon the passed service info criteria. @@ -140,13 +137,11 @@ Optional> lookupFirst(ServiceInfoCriteria criteria, * * * @param criteria the criteria to find - * @param the type of the service * @return the best service provider matching the criteria * @throws io.helidon.pico.api.PicoException if resolution fails to resolve a match */ - @SuppressWarnings("unchecked") - default ServiceProvider lookupFirst(ServiceInfoCriteria criteria) { - return (ServiceProvider) lookupFirst(criteria, true).orElseThrow(); + default ServiceProvider lookupFirst(ServiceInfoCriteria criteria) { + return lookupFirst(criteria, true).orElseThrow(); } /** @@ -179,12 +174,10 @@ default ServiceProvider lookupFirst(Class type) { * Retrieve all services that match the criteria. * * @param criteria the criteria to find - * @param the type of the service * @return the list of service providers matching criteria */ - @SuppressWarnings({"unchecked", "rawtypes"}) - default List> lookupAll(ServiceInfoCriteria criteria) { - return (List) lookupAll(criteria, false); + default List> lookupAll(ServiceInfoCriteria criteria) { + return lookupAll(criteria, false); } /** diff --git a/pico/configdriven/tests/configuredby-application/src/test/java/io/helidon/pico/configdriven/configuredby/test/ApplicationConfiguredByTest.java b/pico/configdriven/tests/configuredby-application/src/test/java/io/helidon/pico/configdriven/configuredby/test/ApplicationConfiguredByTest.java index 47983930b82..48ba0df4da8 100644 --- a/pico/configdriven/tests/configuredby-application/src/test/java/io/helidon/pico/configdriven/configuredby/test/ApplicationConfiguredByTest.java +++ b/pico/configdriven/tests/configuredby-application/src/test/java/io/helidon/pico/configdriven/configuredby/test/ApplicationConfiguredByTest.java @@ -84,7 +84,7 @@ public void startupAndShutdownRunLevelServices() { ServiceInfoCriteria criteria = DefaultServiceInfoCriteria.builder() .runLevel(RunLevel.STARTUP) .build(); - List> startups = services.lookupAll(criteria); + List> startups = services.lookupAll(criteria); List desc = startups.stream().map(ServiceProvider::description).collect(Collectors.toList()); assertThat(desc, contains(ASimpleRunLevelService.class.getSimpleName() + ":INIT")); diff --git a/pico/configdriven/tests/configuredby/src/main/java/io/helidon/pico/configdriven/configuredby/test/AbstractConfiguredByTest.java b/pico/configdriven/tests/configuredby/src/main/java/io/helidon/pico/configdriven/configuredby/test/AbstractConfiguredByTest.java index 596195a1126..e3f667f8cb2 100644 --- a/pico/configdriven/tests/configuredby/src/main/java/io/helidon/pico/configdriven/configuredby/test/AbstractConfiguredByTest.java +++ b/pico/configdriven/tests/configuredby/src/main/java/io/helidon/pico/configdriven/configuredby/test/AbstractConfiguredByTest.java @@ -124,7 +124,7 @@ void testRegistry() { DefaultServiceInfoCriteria criteria = DefaultServiceInfoCriteria.builder() .addQualifier(DefaultQualifierAndValue.create(ConfiguredBy.class)) .build(); - List> list = services.lookupAll(criteria); + List> list = services.lookupAll(criteria); List desc = list.stream().map(ServiceProvider::description).collect(Collectors.toList()); assertThat("root providers are config-driven, auto-started services unless overridden to not be driven", desc, contains("ASingletonService{root}:ACTIVE", @@ -159,7 +159,7 @@ void testRegistry() { assertThat("root providers expected here since no configuration for this service", desc, contains("FakeTlsWSNotDrivenByCB{root}:PENDING")); - ServiceProvider fakeTlsProvider = list.get(0); + ServiceProvider fakeTlsProvider = list.get(0); PicoServiceProviderException e = assertThrows(PicoServiceProviderException.class, fakeTlsProvider::get); assertThat("There is no configuration, so cannot activate this service", e.getMessage(), equalTo("Expected to find a match: service provider: FakeTlsWSNotDrivenByCB{root}:PENDING")); diff --git a/pico/maven-plugin/src/main/java/io/helidon/pico/maven/plugin/AbstractApplicationCreatorMojo.java b/pico/maven-plugin/src/main/java/io/helidon/pico/maven/plugin/AbstractApplicationCreatorMojo.java index cd1e96cbecb..ba3f4523fb0 100644 --- a/pico/maven-plugin/src/main/java/io/helidon/pico/maven/plugin/AbstractApplicationCreatorMojo.java +++ b/pico/maven-plugin/src/main/java/io/helidon/pico/maven/plugin/AbstractApplicationCreatorMojo.java @@ -259,7 +259,7 @@ protected void innerExecute() { // get the application creator only after pico services were initialized (we need to ignore any existing apps) ApplicationCreator creator = applicationCreator(); - List> allModules = services + List> allModules = services .lookupAll(DefaultServiceInfoCriteria.builder().addContractImplemented(Module.class.getName()).build()); getLog().info("processing modules: " + toDescriptions(allModules)); if (allModules.isEmpty()) { diff --git a/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultServices.java b/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultServices.java index 80fd10c27bf..4cdb04614d4 100644 --- a/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultServices.java +++ b/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultServices.java @@ -216,15 +216,17 @@ public boolean reset(boolean deep) { } @Override + @SuppressWarnings({"unchecked", "rawtypes"}) public Optional> lookupFirst(Class type, boolean expected) { DefaultServiceInfoCriteria criteria = DefaultServiceInfoCriteria.builder() .addContractImplemented(type.getName()) .build(); - return lookupFirst(criteria, expected); + return (Optional) lookupFirst(criteria, expected); } @Override + @SuppressWarnings({"unchecked", "rawtypes"}) public Optional> lookupFirst(Class type, String name, boolean expected) { @@ -232,30 +234,30 @@ public Optional> lookupFirst(Class type, .addContractImplemented(type.getName()) .addQualifier(DefaultQualifierAndValue.createNamed(name)) .build(); - return lookupFirst(criteria, expected); + return (Optional) lookupFirst(criteria, expected); } @Override - public Optional> lookupFirst(ServiceInfoCriteria criteria, - boolean expected) { - List> result = lookup(criteria, expected, 1); + public Optional> lookupFirst(ServiceInfoCriteria criteria, + boolean expected) { + List> result = lookup(criteria, expected, 1); assert (!expected || !result.isEmpty()); return (result.isEmpty()) ? Optional.empty() : Optional.of(result.get(0)); } @Override + @SuppressWarnings({"unchecked", "rawtypes"}) public List> lookupAll(Class type) { DefaultServiceInfoCriteria serviceInfo = DefaultServiceInfoCriteria.builder() .addContractImplemented(type.getName()) .build(); - return lookup(serviceInfo, false, Integer.MAX_VALUE); + return (List) lookup(serviceInfo, false, Integer.MAX_VALUE); } @Override - @SuppressWarnings({"rawtypes", "unchecked"}) public List> lookupAll(ServiceInfoCriteria criteria, boolean expected) { - List> result = (List) lookup(criteria, expected, Integer.MAX_VALUE); + List> result = lookup(criteria, expected, Integer.MAX_VALUE); assert (!expected || !result.isEmpty()); return result; } @@ -346,10 +348,10 @@ Metrics metrics() { .build(); } - @SuppressWarnings({"unchecked", "rawtypes"}) - List> lookup(ServiceInfoCriteria criteria, - boolean expected, - int limit) { + @SuppressWarnings({"rawtypes"}) + List> lookup(ServiceInfoCriteria criteria, + boolean expected, + int limit) { List> result; lookupCount.incrementAndGet(); @@ -389,7 +391,7 @@ List> lookup(ServiceInfoCriteria criteria, cacheLookupCount.incrementAndGet(); if (result != null) { cacheHitCount.incrementAndGet(); - return (List) result; + return result; } } @@ -411,7 +413,7 @@ List> lookup(ServiceInfoCriteria criteria, cache.put(criteria, List.copyOf(result)); } - return (List) result; + return result; } ServiceProvider serviceProviderFor(String serviceTypeName) { diff --git a/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/interceptor/InterceptorRuntimeTest.java b/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/interceptor/InterceptorRuntimeTest.java index 2e5beb89fd5..e8be8d21b9d 100644 --- a/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/interceptor/InterceptorRuntimeTest.java +++ b/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/interceptor/InterceptorRuntimeTest.java @@ -115,7 +115,7 @@ void runtimeWithNoInterception() throws Exception { .addContractImplemented(Closeable.class.getName()) .includeIntercepted(true) .build(); - List> closeableProviders = services.lookupAll(criteria); + List> closeableProviders = services.lookupAll(criteria); assertThat("the interceptors should always be weighted higher than the non-interceptors", toDescriptions(closeableProviders), contains("XImpl$$Pico$$Interceptor:INIT", "YImpl$$Pico$$Interceptor:INIT", @@ -160,7 +160,7 @@ void runtimeWithNoInterception() throws Exception { equalTo("forced")); // we cannot look up by service type here - we need to instead lookup by one of the interfaces - ServiceProvider yimplProvider = services + ServiceProvider yimplProvider = services .lookupFirst( DefaultServiceInfoCriteria.builder() .addContractImplemented(Closeable.class.getName()) @@ -242,7 +242,7 @@ void runtimeWithInterception() throws Exception { equalTo(1)); // we cannot look up by service type here - we need to instead lookup by one of the interfaces - ServiceProvider yimplProvider = services + ServiceProvider yimplProvider = services .lookupFirst( DefaultServiceInfoCriteria.builder() .addContractImplemented(Closeable.class.getName()) diff --git a/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/tbox/ToolBoxTest.java b/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/tbox/ToolBoxTest.java index a5bc9cc6679..93125f6f4c7 100644 --- a/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/tbox/ToolBoxTest.java +++ b/pico/tests/resources-pico/src/test/java/io/helidon/pico/tests/pico/tbox/ToolBoxTest.java @@ -328,7 +328,7 @@ void startupAndShutdownCallsPostConstructAndPreDestroy() { @Test void knownProviders() { - List> providers = services.lookupAll( + List> providers = services.lookupAll( DefaultServiceInfoCriteria.builder().addContractImplemented(Provider.class.getName()).build()); List desc = providers.stream().map(ServiceProvider::description).collect(Collectors.toList()); // note that order matters here diff --git a/pico/tools/src/test/java/io/helidon/pico/tools/DefaultApplicationCreatorTest.java b/pico/tools/src/test/java/io/helidon/pico/tools/DefaultApplicationCreatorTest.java index 2449554db4e..abe7a68d7c7 100644 --- a/pico/tools/src/test/java/io/helidon/pico/tools/DefaultApplicationCreatorTest.java +++ b/pico/tools/src/test/java/io/helidon/pico/tools/DefaultApplicationCreatorTest.java @@ -58,7 +58,7 @@ void codegenHelloWorldApplication() { PicoServices picoServices = PicoServices.picoServices().orElseThrow(); Services services = picoServices.services(); - List> serviceProviders = services.lookupAll(allServices); + List> serviceProviders = services.lookupAll(allServices); List serviceTypeNames = serviceProviders.stream() .map(sp -> DefaultTypeName.createFromTypeName(sp.serviceInfo().serviceTypeName()))