Skip to content

Commit

Permalink
Default prefixed builder types renamed to be suffixed (#6796)
Browse files Browse the repository at this point in the history
  • Loading branch information
trentjeff authored May 11, 2023
1 parent 505b999 commit 1c74f7c
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* The default implementation of {@link TypeAndBody}.
*/
public class DefaultTypeAndBody implements TypeAndBody {
public class TypeAndBodyDefault implements TypeAndBody {
private final TypeName typeName;
private final String body;

Expand All @@ -31,7 +31,7 @@ public class DefaultTypeAndBody implements TypeAndBody {
* @param b the builder
* @see #builder()
*/
protected DefaultTypeAndBody(Builder b) {
protected TypeAndBodyDefault(Builder b) {
this.typeName = b.typeName;
this.body = b.body;
}
Expand Down Expand Up @@ -114,8 +114,8 @@ public Builder body(String val) {
*
* @return the built instance
*/
public DefaultTypeAndBody build() {
return new DefaultTypeAndBody(this);
public TypeAndBodyDefault build() {
return new TypeAndBodyDefault(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import io.helidon.builder.RequiredAttributeVisitor;
import io.helidon.builder.Singular;
import io.helidon.builder.processor.spi.BuilderCreatorProvider;
import io.helidon.builder.processor.spi.DefaultTypeAndBody;
import io.helidon.builder.processor.spi.TypeAndBody;
import io.helidon.builder.processor.spi.TypeAndBodyDefault;
import io.helidon.common.Weight;
import io.helidon.common.Weighted;
import io.helidon.common.types.AnnotationAndValue;
Expand Down Expand Up @@ -95,11 +95,11 @@ public List<TypeAndBody> create(TypeInfo typeInfo,
preValidate(implTypeName, typeInfo, builderAnnotation);

List<TypeAndBody> builds = new ArrayList<>();
builds.add(DefaultTypeAndBody.builder()
builds.add(TypeAndBodyDefault.builder()
.typeName(abstractImplTypeName)
.body(toBody(createBodyContext(false, abstractImplTypeName, typeInfo, builderAnnotation)))
.build());
builds.add(DefaultTypeAndBody.builder()
builds.add(TypeAndBodyDefault.builder()
.typeName(implTypeName)
.body(toBody(createBodyContext(true, implTypeName, typeInfo, builderAnnotation)))
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@ void buildAndCompare() {
is(0));
}

@Test
public void buildAndCompareClassNamed() {
QualifierAndValueDefault qav1 = QualifierAndValueDefault.createNamed(new FakeNamed());
QualifierAndValueDefault qav2 = QualifierAndValueDefault.createNamed(new FakeClassNamed());

assertThat(qav1.compareTo(qav2),
is(0));
assertThat(qav2.compareTo(qav1),
is(0));
}

@Named("io.helidon.pico.api.DefaultQualifierAndValueTest")
@ClassNamed(QualifierAndValueDefaultTest.class)
@Test
Expand All @@ -69,6 +58,18 @@ public void createClassNamed() throws Exception {
assertThat("runtime retention expected for " + ClassNamed.class,
getClass().getMethod("createClassNamed").getAnnotation(ClassNamed.class),
notNullValue());

}

@Test
public void buildAndCompareClassNamed() {
QualifierAndValueDefault qav1 = QualifierAndValueDefault.createNamed(new FakeNamed());
QualifierAndValueDefault qav2 = QualifierAndValueDefault.createNamed(new FakeClassNamed());

assertThat(qav1.compareTo(qav2),
is(0));
assertThat(qav2.compareTo(qav1),
is(0));
}

class FakeNamed implements Named {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import io.helidon.pico.api.ServiceProvider;
import io.helidon.pico.api.ServiceProviderProvider;
import io.helidon.pico.api.Services;
import io.helidon.pico.runtime.DefaultServiceBinder;
import io.helidon.pico.runtime.ServiceBinderDefault;
import io.helidon.pico.tools.AbstractFilerMessager;
import io.helidon.pico.tools.ActivatorCreatorCodeGen;
import io.helidon.pico.tools.ApplicationCreatorCodeGen;
Expand Down Expand Up @@ -373,7 +373,7 @@ List<TypeName> toTypeNames(List<String> permittedProviderQualifierTypeNames) {
Set<TypeName> toNames(List<ServiceProvider<?>> services) {
Map<TypeName, ServiceProvider<?>> result = new LinkedHashMap<>();
services.forEach(sp -> {
sp = DefaultServiceBinder.toRootProvider(sp);
sp = ServiceBinderDefault.toRootProvider(sp);
String serviceType = sp.serviceInfo().serviceTypeName();
TypeName name = TypeNameDefault.createFromTypeName(serviceType);
ServiceProvider<?> prev = result.put(name, sp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DefaultInjectionPlanBinder implements ServiceInjectionPlanBinder, ServiceI
public Binder bindTo(ServiceProvider<?> untrustedSp) {
// don't trust what we get, but instead lookup the service provider that we carry in our services registry
ServiceProvider<?> serviceProvider = services.serviceProviderFor(untrustedSp.serviceInfo().serviceTypeName());
Optional<ServiceProviderBindable<?>> bindable = DefaultServiceBinder.toBindableProvider(serviceProvider);
Optional<ServiceProviderBindable<?>> bindable = ServiceBinderDefault.toBindableProvider(serviceProvider);
Optional<Binder> binder = (bindable.isPresent()) ? bindable.get().injectionPlanBinder() : Optional.empty();
if (binder.isEmpty()) {
// basically this means this service will not support compile-time injection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static Object resolve(ServiceProvider<?> self,
// "standard" case
ServiceProvider<?> serviceProvider = serviceProviders.get(0);
Optional<ServiceProviderBindable<?>> serviceProviderBindable =
DefaultServiceBinder.toBindableProvider(DefaultServiceBinder.toRootProvider(serviceProvider));
ServiceBinderDefault.toBindableProvider(ServiceBinderDefault.toRootProvider(serviceProvider));
if (serviceProviderBindable.isPresent()
&& serviceProviderBindable.get() != serviceProvider
&& serviceProviderBindable.get() instanceof ServiceProviderProvider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ ServiceBinder createServiceBinder(PicoServices picoServices,
String moduleName,
boolean trusted) {
assert (picoServices.services() == services);
return DefaultServiceBinder.create(picoServices, moduleName, trusted);
return ServiceBinderDefault.create(picoServices, moduleName, trusted);
}

void bind(PicoServices picoServices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
/**
* The default implementation for {@link ServiceBinder}.
*/
public class DefaultServiceBinder implements ServiceBinder {
public class ServiceBinderDefault implements ServiceBinder {
private final PicoServices picoServices;
private final ServiceBinder serviceRegistry;
private final String moduleName;
private final boolean trusted;

private DefaultServiceBinder(PicoServices picoServices,
private ServiceBinderDefault(PicoServices picoServices,
String moduleName,
boolean trusted) {
this.picoServices = picoServices;
Expand All @@ -52,12 +52,12 @@ private DefaultServiceBinder(PicoServices picoServices,
* @param trusted are we in trusted mode (typically only set during early initialization sequence)
* @return the newly created service binder
*/
public static DefaultServiceBinder create(PicoServices picoServices,
public static ServiceBinderDefault create(PicoServices picoServices,
String moduleName,
boolean trusted) {
Objects.requireNonNull(picoServices);
Objects.requireNonNull(moduleName);
return new DefaultServiceBinder(picoServices, moduleName, trusted);
return new ServiceBinderDefault(picoServices, moduleName, trusted);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import io.helidon.pico.api.PicoServicesHolder;
import io.helidon.pico.api.Resettable;
import io.helidon.pico.api.ServiceProvider;
import io.helidon.pico.runtime.DefaultServiceBinder;
import io.helidon.pico.runtime.ServiceBinderDefault;

/**
* Supporting helper utilities unit-testing Pico services.
Expand All @@ -60,7 +60,7 @@ public static void resetAll() {
*/
public static void bind(PicoServices picoServices,
ServiceProvider<?> serviceProvider) {
DefaultServiceBinder binder = DefaultServiceBinder.create(picoServices, PicoTestingSupport.class.getSimpleName(), true);
ServiceBinderDefault binder = ServiceBinderDefault.create(picoServices, PicoTestingSupport.class.getSimpleName(), true);
binder.bind(serviceProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import io.helidon.pico.api.PicoServicesConfig;
import io.helidon.pico.api.ServiceProvider;
import io.helidon.pico.runtime.AbstractServiceProvider;
import io.helidon.pico.runtime.DefaultServiceBinder;
import io.helidon.pico.runtime.ServiceBinderDefault;

import static io.helidon.pico.tools.CommonUtils.hasValue;
import static io.helidon.pico.tools.TypeTools.needToDeclareModuleUsage;
Expand Down Expand Up @@ -111,7 +111,7 @@ static String toActivatorCodeGen(ServiceProvider<?> sp) {
if (sp instanceof AbstractServiceProvider && ((AbstractServiceProvider<?>) sp).isCustom()) {
return null;
}
return DefaultServiceBinder.toRootProvider(sp).activator().orElseThrow().getClass().getName() + ".INSTANCE";
return ServiceBinderDefault.toRootProvider(sp).activator().orElseThrow().getClass().getName() + ".INSTANCE";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import io.helidon.pico.api.ServiceProvider;
import io.helidon.pico.api.Services;
import io.helidon.pico.runtime.AbstractServiceProvider;
import io.helidon.pico.runtime.DefaultServiceBinder;
import io.helidon.pico.runtime.PicoInjectionPlan;
import io.helidon.pico.runtime.ServiceBinderDefault;
import io.helidon.pico.tools.spi.ApplicationCreator;

import jakarta.inject.Provider;
Expand Down Expand Up @@ -322,7 +322,7 @@ String toServiceTypeInjectionPlan(PicoServices picoServices,
@SuppressWarnings("unchecked")
List<String> toInjectionPlanBindings(ServiceProvider<?> sp) {
AbstractServiceProvider<?> asp = AbstractServiceProvider
.toAbstractServiceProvider(DefaultServiceBinder.toRootProvider(sp), true).orElseThrow();
.toAbstractServiceProvider(ServiceBinderDefault.toRootProvider(sp), true).orElseThrow();
DependenciesInfo deps = asp.dependencies();
if (deps.allDependencies().isEmpty()) {
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ void testCheckInjection() {
WebTarget target = baseTarget.path("/check");
assertThat(target.request().get().getStatus(), is(200));
}
}
}

0 comments on commit 1c74f7c

Please sign in to comment.