Skip to content

Commit 6061fc0

Browse files
committed
rename InteractionControllerInstantiator to Instantiator
1 parent f68c8fb commit 6061fc0

15 files changed

Lines changed: 57 additions & 91 deletions

File tree

‎core/src/main/java/io/github/kaktushose/jdac/JDACBuilder.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import io.github.kaktushose.jdac.dispatching.adapter.TypeAdapter;
1616
import io.github.kaktushose.jdac.dispatching.adapter.internal.TypeAdapters;
1717
import io.github.kaktushose.jdac.dispatching.expiration.ExpirationStrategy;
18-
import io.github.kaktushose.jdac.dispatching.instance.InteractionControllerInstantiator;
18+
import io.github.kaktushose.jdac.dispatching.instance.Instantiator;
1919
import io.github.kaktushose.jdac.dispatching.middleware.Middleware;
2020
import io.github.kaktushose.jdac.dispatching.middleware.Priority;
2121
import io.github.kaktushose.jdac.dispatching.middleware.internal.Middlewares;
@@ -73,7 +73,7 @@
7373
///
7474
/// - [#descriptor(Descriptor)]
7575
/// - [#classFinders(ClassFinder...)]
76-
/// - [#instanceProvider(InteractionControllerInstantiator)]
76+
/// - [#instantiator(Instantiator)]
7777
///
7878
///
7979
/// In addition to manually configuring this builder, you can also provide implementations of [Extension] trough Javas [`service
@@ -233,9 +233,9 @@ public JDACBuilder localizer(Localizer localizer) {
233233
return addUserProperty(LOCALIZER, _ -> localizer);
234234
}
235235

236-
/// @param instanceProvider the implementation of [InteractionControllerInstantiator] to use
237-
public JDACBuilder instanceProvider(InteractionControllerInstantiator instanceProvider) {
238-
return addUserProperty(INTERACTION_CONTROLLER_INSTANTIATOR, _ -> instanceProvider);
236+
/// @param instantiator the implementation of [Instantiator] to use
237+
public JDACBuilder instantiator(Instantiator instantiator) {
238+
return addUserProperty(INSTANTIATOR, _ -> instantiator);
239239
}
240240

241241
/// @param strategy The [ExpirationStrategy] to be used

‎core/src/main/java/io/github/kaktushose/jdac/configuration/Extension.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io.github.kaktushose.jdac.annotations.IntrospectionAccess;
66
import io.github.kaktushose.jdac.configuration.Property.Category;
77
import io.github.kaktushose.jdac.definitions.description.Descriptor;
8-
import io.github.kaktushose.jdac.dispatching.instance.InteractionControllerInstantiator;
8+
import io.github.kaktushose.jdac.dispatching.instance.Instantiator;
99
import io.github.kaktushose.jdac.introspection.Introspection;
1010
import io.github.kaktushose.jdac.introspection.Stage;
1111
import org.jspecify.annotations.Nullable;
@@ -22,7 +22,7 @@
2222
///
2323
/// ## Properties
2424
/// By implementing [#properties()] and returning a collection of [PropertyProvider]s, you can
25-
/// for example provide an own implementation of [InteractionControllerInstantiator]
25+
/// for example provide an own implementation of [Instantiator]
2626
/// or [Descriptor]. These implementations will override the default ones.
2727
///
2828
/// It's important to know, that you can only return [PropertyProvider]s of [Property]s
@@ -38,7 +38,7 @@
3838
/// This allows further configuration, e.g. through the [Introspection] API by using [JDACommands#introspection()].
3939
///
4040
/// ## Example
41-
/// This example extension provides an own implementation of [InteractionControllerInstantiator].
41+
/// This example extension provides an own implementation of [Instantiator].
4242
/// ```java
4343
/// public class DIExtension implements Extension<DIExtensionData> {
4444
///
@@ -54,7 +54,7 @@
5454
/// @Override
5555
/// public Collection<PropertyProvider<?>> properties() {
5656
/// return List.of(PropertyProvider.create(
57-
/// Property.INTERACTION_CONTROLLER_INSTANTIATOR,
57+
/// Property.INSTANTIATOR,
5858
/// 2000,
5959
/// _ -> new CustomInteractionClassProvider(this))
6060
/// );

‎core/src/main/java/io/github/kaktushose/jdac/configuration/Property.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import io.github.kaktushose.jdac.dispatching.context.KeyValueStore;
1414
import io.github.kaktushose.jdac.dispatching.events.Event;
1515
import io.github.kaktushose.jdac.dispatching.expiration.ExpirationStrategy;
16-
import io.github.kaktushose.jdac.dispatching.instance.InteractionControllerInstantiator;
16+
import io.github.kaktushose.jdac.dispatching.instance.Instantiator;
1717
import io.github.kaktushose.jdac.dispatching.middleware.Middleware;
1818
import io.github.kaktushose.jdac.dispatching.middleware.Priority;
1919
import io.github.kaktushose.jdac.dispatching.validation.Validator;
@@ -106,10 +106,9 @@ public sealed interface Property<T> permits Property.Enumeration, Property.Singl
106106
Property<Localizer> LOCALIZER =
107107
new Singleton<>("LOCALIZER", Category.LOADABLE, Localizer.class, Stage.CONFIGURATION);
108108

109-
/// @see JDACBuilder#instanceProvider(InteractionControllerInstantiator)
109+
/// @see JDACBuilder#instantiator(Instantiator)
110110
@PropertyInformation(stage = Stage.CONFIGURATION, category = Category.LOADABLE)
111-
Property<InteractionControllerInstantiator> INTERACTION_CONTROLLER_INSTANTIATOR =
112-
new Singleton<>("INTERACTION_CONTROLLER_INSTANTIATOR", Category.LOADABLE, InteractionControllerInstantiator.class, Stage.CONFIGURATION);
111+
Property<Instantiator> INSTANTIATOR = new Singleton<>("INSTANTIATOR", Category.LOADABLE, Instantiator.class, Stage.CONFIGURATION);
113112

114113
/// MIDDLEWARE property holds multiple [Middleware]s associated with their [Priority]
115114
/// @see JDACBuilder#middleware(Priority, Middleware)

‎core/src/main/java/io/github/kaktushose/jdac/configuration/PropertyProvider.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
/// class Foo {
3535
/// public bar(...) {
3636
/// var provider = new PropertyProvider(
37-
/// Type.INTERACTION_CONTROLLER_INSTANTIATOR,
37+
/// Property.INSTANTIATOR,
3838
/// 2000, // just some random priority
3939
/// Foo.class, // used as a waypoint for debugging
40-
/// ctx -> new MyInteractionControllerInstantiator(ctx.get(Property.I18N)) // needs the I18n instance
40+
/// ctx -> new MyInstantiator(ctx.get(Property.I18N)) // needs the I18n instance
4141
/// )
4242
/// }
4343
/// }

‎core/src/main/java/io/github/kaktushose/jdac/definitions/interactions/command/OptionDataDefinition.java‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717
import io.github.kaktushose.jdac.dispatching.events.interactions.CommandEvent;
1818
import io.github.kaktushose.jdac.dispatching.events.interactions.ComponentEvent;
1919
import io.github.kaktushose.jdac.dispatching.events.interactions.ModalEvent;
20-
import io.github.kaktushose.jdac.dispatching.instance.InteractionControllerInstantiator;
2120
import io.github.kaktushose.jdac.dispatching.validation.Validator;
2221
import io.github.kaktushose.jdac.dispatching.validation.internal.Validators;
2322
import io.github.kaktushose.jdac.exceptions.ConfigurationException;
2423
import io.github.kaktushose.jdac.exceptions.InternalException;
2524
import io.github.kaktushose.jdac.exceptions.InvalidDeclarationException;
2625
import io.github.kaktushose.jdac.internal.Helpers;
2726
import io.github.kaktushose.jdac.introspection.Introspection;
28-
import io.github.kaktushose.jdac.introspection.internal.IntrospectionAccess;
29-
import io.github.kaktushose.jdac.introspection.internal.IntrospectionImpl;
3027
import io.github.kaktushose.jdac.message.resolver.MessageResolver;
3128
import io.github.kaktushose.proteus.Proteus;
3229
import io.github.kaktushose.proteus.type.Type;
@@ -265,7 +262,7 @@ private static List<Choice> indexChoices(ClassDescription classDescription, Para
265262
Helpers.checkParametrizedType(method.genericReturnType(), List.class, String.class);
266263

267264
try {
268-
var instantiator = introspection.get(Property.INTERACTION_CONTROLLER_INSTANTIATOR);
265+
var instantiator = introspection.get(Property.INSTANTIATOR);
269266
List<Object> arguments = method.parameters().stream()
270267
.map(ParameterDescription::type)
271268
.map(it -> (Object) instantiator.instance(it, introspection))

‎core/src/main/java/io/github/kaktushose/jdac/dispatching/FrameworkContext.java‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎core/src/main/java/io/github/kaktushose/jdac/dispatching/Runtime.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public KeyValueStore keyValueStore() {
138138
}
139139

140140
public <T> T interactionInstance(Class<T> clazz) {
141-
return introspection.get(Property.INTERACTION_CONTROLLER_INSTANTIATOR).instance(clazz, introspection);
141+
return introspection.get(Property.INSTANTIATOR).instance(clazz, introspection);
142142
}
143143

144144
@Override
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.github.kaktushose.jdac.dispatching.instance;
2+
3+
import io.github.kaktushose.jdac.annotations.IntrospectionAccess;
4+
import io.github.kaktushose.jdac.annotations.interactions.Interaction;
5+
import io.github.kaktushose.jdac.introspection.Introspection;
6+
import io.github.kaktushose.jdac.introspection.Stage;
7+
import io.github.kaktushose.jdac.message.resolver.MessageResolver;
8+
9+
/// An [Instantiator] is used get instances of classes, if needed creating those.
10+
///
11+
/// For classes annotated with [Interaction], there can be only one instance per class of those per
12+
/// [`Runtime`]({@docRoot}/index.html#runtime-concept-heading). Instances of interactions should be treated like
13+
/// runtime scoped singletons, so to speak.
14+
@FunctionalInterface
15+
public interface Instantiator {
16+
17+
/// This method will be called each time an instance of a class is needed.
18+
///
19+
/// The provided [Introspection] instance or [Introspection#accessScoped()] can be used to retrieve other
20+
/// components/parts of this framework, e.g. [MessageResolver].
21+
///
22+
/// @param clazz the [Class] of needed instance
23+
/// @param introspection the [Introspection] instance of this runtime (stage = [Stage#RUNTIME]).
24+
@IntrospectionAccess(Stage.RUNTIME)
25+
<T> T instance(Class<T> clazz, Introspection introspection);
26+
}

‎core/src/main/java/io/github/kaktushose/jdac/dispatching/instance/InteractionControllerInstantiator.java‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎core/src/main/java/io/github/kaktushose/jdac/introspection/Stage.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io.github.kaktushose.jdac.annotations.IntrospectionAccess;
55
import io.github.kaktushose.jdac.configuration.Property;
66
import io.github.kaktushose.jdac.dispatching.context.InvocationContext;
7-
import io.github.kaktushose.jdac.dispatching.instance.InteractionControllerInstantiator;
7+
import io.github.kaktushose.jdac.dispatching.instance.Instantiator;
88
import io.github.kaktushose.jdac.dispatching.middleware.Middleware;
99
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
1010

@@ -13,7 +13,7 @@
1313
/// JDA-Commands has the following stages in this order:
1414
/// 1. [#CONFIGURATION] -> setting of builder properties, extension loading, construction of framework components
1515
/// 2. [#INITIALIZED] -> after starting the framework (basically after [JDACBuilder#start()] completed), e.g. all definitions are indexed etc.
16-
/// 3. [#RUNTIME] -> inside a runtime but outside of processing an [GenericInteractionCreateEvent], e.g. when [InteractionControllerInstantiator#instance(Class, Introspection)] is called
16+
/// 3. [#RUNTIME] -> inside a runtime but outside of processing an [GenericInteractionCreateEvent], e.g. when [Instantiator#instance(Class, Introspection)] is called
1717
/// 4. [#PREPARATION] -> during the preparation of an [GenericInteractionCreateEvent] for the [#INTERACTION] stage, e.g. where type adapters get called
1818
/// 5. [#INTERACTION] -> when processing an [GenericInteractionCreateEvent], e.g. in [Middleware#accept(InvocationContext)] or inside a user defined interaction controller method
1919
///

0 commit comments

Comments
 (0)