Skip to content

Commit

Permalink
er
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspernielsen committed Feb 13, 2024
1 parent 6820646 commit 6b4dd0e
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private static class BootstrapAppExtension extends FrameworkExtension<BootstrapA

MethodHandle mh;

private <T> void newApplication(BeanHandle<T> handle) {
private <T> void newApplication(BeanHandle handle) {
runOnCodegen(() -> mh = handle.lifetimeOperations().get(0).generateMethodHandle());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
public non-sealed class BeanConfiguration implements ComponentConfiguration , BeanLocalAccessor {

/** The bean handle. We don't store BeanSetup directly because it is not generified */
private final PackedBeanHandle<?> handle;
private final PackedBeanHandle handle;

public BeanConfiguration() {
// Will fail if the bean configuration is not initialized from within the framework
this.handle = new PackedBeanHandle<>(BeanSetup.initFromBeanConfiguration(this));
this.handle = new PackedBeanHandle(BeanSetup.initFromBeanConfiguration(this));
}

/**
Expand All @@ -36,8 +36,8 @@ public BeanConfiguration() {
* @param handle
* the bean handle
*/
public BeanConfiguration(BeanHandle<?> handle) {
this.handle = (PackedBeanHandle<?>) requireNonNull(handle, "handle is null");
public BeanConfiguration(BeanHandle handle) {
this.handle = (PackedBeanHandle) requireNonNull(handle, "handle is null");
this.handle.bean().initConfiguration(this);
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public final Stream<BeanFactoryConfiguration> factories() {
}

/** {@return the bean handle that was used to create this configuration.} */
protected final BeanHandle<?> handle() {
protected final BeanHandle handle() {
return handle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public InstanceBeanConfiguration() {}
* @param handle
* the bean handle
*/
public InstanceBeanConfiguration(BeanHandle<T> handle) {
public InstanceBeanConfiguration(BeanHandle handle) {
super(handle);
}

Expand All @@ -51,12 +51,6 @@ public InstanceBeanConfiguration<T> allowMultiClass() {
return this;
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
protected final BeanHandle<T> instanceHandle() {
return (BeanHandle<T>) handle();
}

/** {@inheritDoc} */
@Override
public InstanceBeanConfiguration<T> named(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/**
*
*/

// Abstract Class????
public interface ComponentHandle {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ <T> ServiceableBeanConfiguration<T> transformingInstall(Class<T> implementation,
* @see BaseAssembly#install(Class)
*/
public <T> ServiceableBeanConfiguration<T> install(Class<T> implementation) {
BeanHandle<T> handle = install0(BeanKind.CONTAINER.template()).install(implementation);
BeanHandle handle = install0(BeanKind.CONTAINER.template()).install(implementation);
return handle.configure(ServiceableBeanConfiguration::new);
}

Expand All @@ -212,7 +212,7 @@ public <T> ServiceableBeanConfiguration<T> install2(Class<T> implementation) {
* @see CommonContainerAssembly#install(Op)
*/
public <T> ServiceableBeanConfiguration<T> install(Op<T> op) {
BeanHandle<T> handle = install0(BeanKind.CONTAINER.template()).install(op);
BeanHandle handle = install0(BeanKind.CONTAINER.template()).install(op);
return new ServiceableBeanConfiguration<>(handle);
}

Expand All @@ -232,27 +232,27 @@ private PackedBeanHandleBuilder install0(BeanTemplate template) {
* @return this configuration
*/
public <T> ServiceableBeanConfiguration<T> installInstance(T instance) {
BeanHandle<T> handle = install0(BeanKind.CONTAINER.template()).installInstance(instance);
BeanHandle handle = install0(BeanKind.CONTAINER.template()).installInstance(instance);
return new ServiceableBeanConfiguration<>(handle);
}

public <T> ServiceableBeanConfiguration<T> installLazy(Class<T> implementation) {
BeanHandle<T> handle = install0(BeanKind.LAZY.template()).install(implementation);
BeanHandle handle = install0(BeanKind.LAZY.template()).install(implementation);
return new ServiceableBeanConfiguration<>(handle); // Providable???
}

public <T> ServiceableBeanConfiguration<T> installLazy(Op<T> op) {
BeanHandle<T> handle = install0(BeanKind.LAZY.template()).install(op);
BeanHandle handle = install0(BeanKind.LAZY.template()).install(op);
return new ServiceableBeanConfiguration<>(handle); // Providable???
}

public <T> ServiceableBeanConfiguration<T> installPrototype(Class<T> implementation) {
BeanHandle<T> handle = install0(BeanKind.UNMANAGED.template()).install(implementation);
BeanHandle handle = install0(BeanKind.UNMANAGED.template()).install(implementation);
return new ServiceableBeanConfiguration<>(handle);
}

public <T> ServiceableBeanConfiguration<T> installPrototype(Op<T> op) {
BeanHandle<T> handle = install0(BeanKind.UNMANAGED.template()).install(op);
BeanHandle handle = install0(BeanKind.UNMANAGED.template()).install(op);
return new ServiceableBeanConfiguration<>(handle);
}

Expand All @@ -267,7 +267,7 @@ public <T> ServiceableBeanConfiguration<T> installPrototype(Op<T> op) {
* @see BeanSourceKind#CLASS
*/
public BeanConfiguration installStatic(Class<?> implementation) {
BeanHandle<?> handle = install0(BeanKind.STATIC.template()).install(implementation);
BeanHandle handle = install0(BeanKind.STATIC.template()).install(implementation);
return new BeanConfiguration(handle);
}

Expand All @@ -280,7 +280,7 @@ void lifetimeExportServiceLocator() {
// Create a new bean that holds the ServiceLocator to export
// will fail if installed multiple times

BeanHandle<PackedServiceLocator> h = newBeanBuilderSelf(BeanKind.CONTAINER.template()).install(PackedServiceLocator.class)
BeanHandle h = newBeanBuilderSelf(BeanKind.CONTAINER.template()).install(PackedServiceLocator.class)
.exportAs(ServiceLocator.class);

// PackedServiceLocator needs a Map<Key, MethodHandle> which is created in the code generation phase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public <K> void addCodeGenerator(BeanConfiguration bean, Key<K> key, Supplier<?
}

public <T> ServiceableBeanConfiguration<T> install(Class<T> implementation) {
BeanHandle<T> handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).install(implementation);
BeanHandle handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).install(implementation);
return new ServiceableBeanConfiguration<>(handle);
}

Expand All @@ -133,7 +133,7 @@ public <T> ServiceableBeanConfiguration<T> install(Class<T> implementation) {
* @return a configuration object representing the installed bean
*/
public <T> InstanceBeanConfiguration<T> install(Op<T> op) {
BeanHandle<T> handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).install(op);
BeanHandle handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).install(op);
// return handle.initialize(IBC::new);
return new InstanceBeanConfiguration<>(handle);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public <T> InstanceBeanConfiguration<T> installIfAbsent(Class<T> clazz) {
@SuppressWarnings("unchecked")
public <T> InstanceBeanConfiguration<T> installIfAbsent(Class<T> clazz, Consumer<? super InstanceBeanConfiguration<T>> action) {
requireNonNull(action, "action is null");
BeanHandle<T> handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).installIfAbsent(clazz,
BeanHandle handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).installIfAbsent(clazz,
h -> action.accept(new InstanceBeanConfiguration<>(h)));
BeanConfiguration bc = BeanSetup.crack(handle).configuration;
if (bc == null) {
Expand All @@ -192,7 +192,7 @@ public <T> InstanceBeanConfiguration<T> installIfAbsent(Class<T> clazz, Consumer
}

public <T> InstanceBeanConfiguration<T> installInstance(T instance) {
BeanHandle<T> handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).installInstance(instance);
BeanHandle handle = newBeanForDependantExtension(BeanKind.CONTAINER.template(), context()).installInstance(instance);
return new InstanceBeanConfiguration<>(handle);
}

Expand All @@ -211,7 +211,7 @@ public <T> InstanceBeanConfiguration<T> installInstance(T instance) {
* @return a configuration object representing the installed bean
*/
public BeanConfiguration installStatic(Class<?> beanClass) {
BeanHandle<?> handle = newBeanForDependantExtension(BeanKind.STATIC.template(), context()).install(beanClass);
BeanHandle handle = newBeanForDependantExtension(BeanKind.STATIC.template(), context()).install(beanClass);
return new BeanConfiguration(handle);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ServiceableBeanConfiguration() {}
* @param handle
* the bean handle this configuration wraps
*/
public ServiceableBeanConfiguration(BeanHandle<T> handle) {
public ServiceableBeanConfiguration(BeanHandle handle) {
super(handle);
}

Expand All @@ -45,8 +45,9 @@ public ServiceableBeanConfiguration<T> allowMultiClass() {
}

/** {@return the default key that services will be provided as.} */
@SuppressWarnings("unchecked")
public Key<T> defaultKey() {
return instanceHandle().defaultKey();
return (Key<T>) handle().defaultKey();
}

public ServiceableBeanConfiguration<T> export() {
Expand All @@ -58,7 +59,7 @@ public ServiceableBeanConfiguration<T> exportAs(Class<? super T> key) {
}

public ServiceableBeanConfiguration<T> exportAs(Key<? super T> key) {
instanceHandle().exportAs(key);
handle().exportAs(key);
return this;
}

Expand Down Expand Up @@ -96,7 +97,7 @@ public ServiceableBeanConfiguration<T> provideAs(Class<? super T> key) {
* @see #provideAs(Class)
*/
public ServiceableBeanConfiguration<T> provideAs(Key<? super T> key) {
instanceHandle().provideAs(key);
handle().provideAs(key);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,16 @@ public void named(String newName) {
* @return the bean setup
*/
public static BeanSetup crack(BeanConfiguration configuration) {
PackedBeanHandle<?> handle = (PackedBeanHandle<?>) VH_BEAN_CONFIGURATION_TO_HANDLE.get(configuration);
PackedBeanHandle handle = (PackedBeanHandle) VH_BEAN_CONFIGURATION_TO_HANDLE.get(configuration);
return handle.bean();
}

public static BeanSetup crack(BeanElement element) {
return ((PackedBeanElement) element).bean();
}

public static BeanSetup crack(BeanHandle<?> handle) {
return ((PackedBeanHandle<?>) handle).bean();
public static BeanSetup crack(BeanHandle handle) {
return ((PackedBeanHandle) handle).bean();
}

public static BeanSetup crack(BeanIntrospector introspector) {
Expand All @@ -299,7 +299,7 @@ public static BeanSetup crack(BeanLocalAccessor accessor) {
return switch (accessor) {
case BeanConfiguration b -> crack(b);
case BeanElement b -> crack(b);
case BeanHandle<?> b -> crack(b);
case BeanHandle b -> crack(b);
case BeanIntrospector b -> crack(b);
case BeanMirror b -> crack(b);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import sandbox.extension.operation.OperationHandle;

/** Implementation of {@link BeanHandle}. */
public record PackedBeanHandle<T>(BeanSetup bean) implements BeanHandle<T> {
public record PackedBeanHandle(BeanSetup bean) implements BeanHandle {

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -81,15 +81,15 @@ public Authority owner() {

/** {@inheritDoc} */
@Override
public BeanHandle<T> exportAs(Key<? super T> key) {
public BeanHandle exportAs(Key<?> key) {
checkIsConfigurable();
bean.container.sm.export(key, bean.instanceAccessOperation());
return this;
}

/** {@inheritDoc} */
@Override
public void provideAs(Key<? super T> key) {
public void provideAs(Key<?> key) {
Key<?> k = InternalServiceUtil.checkKey(bean.beanClass, key);
checkIsConfigurable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,30 @@ private void checkIsBuildable() {}

/** {@inheritDoc} */
@Override
public <T> BeanHandle<T> install(Class<T> beanClass) {
public <T> BeanHandle install(Class<T> beanClass) {
requireNonNull(beanClass, "beanClass is null");
return newBean(beanClass, BeanSourceKind.CLASS, beanClass);
}

/** {@inheritDoc} */
@Override
public <T, C extends BeanConfiguration> InstalledComponent<BeanHandle<T>, C> install(Class<T> beanClass, Supplier<? extends C> newConfiguration) {
BeanHandle<T> h = newBean(beanClass, BeanSourceKind.CLASS, beanClass);
return new InstalledComponent<BeanHandle<T>, C>(h, newConfiguration.get());
public <T, C extends BeanConfiguration> InstalledComponent<BeanHandle, C> install(Class<T> beanClass, Supplier<? extends C> newConfiguration) {
BeanHandle h = newBean(beanClass, BeanSourceKind.CLASS, beanClass);
return new InstalledComponent<BeanHandle, C>(h, newConfiguration.get());
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T> BeanHandle<T> install(Op<T> op) {
public <T> BeanHandle install(Op<T> op) {
PackedOp<?> pop = PackedOp.crack(op);
Class<?> beanClass = pop.type.returnRawType();
return newBean((Class<T>) beanClass, BeanSourceKind.OP, pop);
}

/** {@inheritDoc} */
@Override
public <T> BeanHandle<T> installIfAbsent(Class<T> beanClass, Consumer<? super BeanHandle<T>> onInstall) {
public <T> BeanHandle installIfAbsent(Class<T> beanClass, Consumer<? super BeanHandle> onInstall) {
requireNonNull(beanClass, "beanClass is null");

BeanClassKey e = new BeanClassKey(owner.authority(), beanClass);
Expand All @@ -136,18 +136,18 @@ public <T> BeanHandle<T> installIfAbsent(Class<T> beanClass, Consumer<? super Be
if (ContainerBeanStore.isMultiInstall(existingBean)) {
throw new IllegalArgumentException("MultiInstall Bean");
} else {
return new PackedBeanHandle<>(existingBean);
return new PackedBeanHandle(existingBean);
}
}
BeanHandle<T> handle = newBean(beanClass, BeanSourceKind.CLASS, beanClass);
BeanHandle handle = newBean(beanClass, BeanSourceKind.CLASS, beanClass);
onInstall.accept(handle);
return handle;
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <T> BeanHandle<T> installInstance(T instance) {
public <T> BeanHandle installInstance(T instance) {
requireNonNull(instance, "instance is null");
Class<?> beanClass = instance.getClass();
return newBean((Class<T>) beanClass, BeanSourceKind.INSTANCE, instance);
Expand All @@ -165,7 +165,7 @@ public <T> BeanHandle<T> installInstance(T instance) {
* @see app.packed.bean.BeanSourceKind#SOURCELESS
*/
@Override
public BeanHandle<?> installSourceless() {
public BeanHandle installSourceless() {
if (template.kind() != BeanKind.STATIC) {
throw new InternalExtensionException("Only static beans can be source less");
}
Expand Down Expand Up @@ -193,7 +193,7 @@ public PackedBeanHandleBuilder namePrefix(String prefix) {
* @return a handle for the bean
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T> BeanHandle<T> newBean(Class<T> beanClass, BeanSourceKind sourceKind, @Nullable Object source) {
private <T> BeanHandle newBean(Class<T> beanClass, BeanSourceKind sourceKind, @Nullable Object source) {
if (sourceKind != BeanSourceKind.SOURCELESS && ILLEGAL_BEAN_CLASSES.contains(beanClass)) {
throw new IllegalArgumentException("Cannot install a bean with bean class " + beanClass);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ private <T> BeanHandle<T> newBean(Class<T> beanClass, BeanSourceKind sourceKind,
new BeanScanner(bean).introspect();
}

return new PackedBeanHandle<>(bean);
return new PackedBeanHandle(bean);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ApplicationHostConfiguration<T> extends InstanceBeanConfiguration<T> {
/**
* @param handle
*/
public ApplicationHostConfiguration(BeanHandle<T> handle) {
public ApplicationHostConfiguration(BeanHandle handle) {
super(handle);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ApplicationHostExtension2 extends FrameworkExtension<ApplicationHostExtens

ApplicationHostExtension2() {}

private <T> ApplicationHostConfiguration<T> newApplication(BeanHandle<T> handle) {
private <T> ApplicationHostConfiguration<T> newApplication(BeanHandle handle) {
runOnCodegen(() -> mh = handle.lifetimeOperations().get(0).generateMethodHandle());

return handle.configure(ApplicationHostConfiguration::new);
Expand Down
Loading

0 comments on commit 6b4dd0e

Please sign in to comment.