|
2 | 2 |
|
3 | 3 | import com.coditory.quark.context.annotations.Bean; |
4 | 4 | import com.coditory.quark.context.annotations.Configuration; |
5 | | -import com.coditory.quark.context.annotations.Init; |
6 | | -import com.coditory.quark.context.annotations.PostInit; |
7 | 5 | import com.coditory.quark.context.events.ContextEventHandler; |
8 | 6 | import com.coditory.quark.eventbus.DispatchExceptionHandler; |
9 | 7 | import com.coditory.quark.eventbus.EventBus; |
10 | 8 | import com.coditory.quark.eventbus.EventBusBuilder; |
11 | | -import com.coditory.quark.eventbus.EventEmitter; |
12 | 9 | import com.coditory.quark.eventbus.EventListener; |
13 | 10 | import com.coditory.quark.eventbus.Subscription; |
14 | 11 | import org.jetbrains.annotations.NotNull; |
15 | 12 |
|
16 | 13 | import java.lang.reflect.Method; |
17 | 14 | import java.time.Duration; |
18 | 15 | import java.util.ArrayList; |
| 16 | +import java.util.Arrays; |
| 17 | +import java.util.Comparator; |
19 | 18 | import java.util.LinkedHashMap; |
20 | 19 | import java.util.LinkedHashSet; |
21 | 20 | import java.util.List; |
|
32 | 31 | import static com.coditory.quark.context.Preconditions.expect; |
33 | 32 | import static com.coditory.quark.context.Preconditions.expectNonBlank; |
34 | 33 | import static com.coditory.quark.context.Preconditions.expectNonNull; |
35 | | -import static java.util.stream.Collectors.toCollection; |
36 | 34 |
|
37 | 35 | public final class ContextBuilder { |
38 | 36 | public static final String CONTEXT_EVENT_BUS_NAME = "ContextEventBus"; |
@@ -187,12 +185,14 @@ private <T> void addBeansFromConfiguration(Configuration configuration, Class<T> |
187 | 185 | BeanConfig config = BeanConfig.fromAnnotationOrDefault(configuration); |
188 | 186 | BeanHolder<T> holder = holder(descriptor(type, name), fromConstructor(type), config); |
189 | 187 | addBeanHolder(holder); |
190 | | - for (Method method : type.getDeclaredMethods()) { |
191 | | - if (method.isAnnotationPresent(Bean.class)) { |
192 | | - method.setAccessible(true); |
193 | | - addFromAnnotatedConfiguration(holder, method, method.getReturnType()); |
194 | | - } |
195 | | - } |
| 188 | + Arrays.stream(type.getDeclaredMethods()) |
| 189 | + .filter((Method method) -> method.isAnnotationPresent(Bean.class)) |
| 190 | + // sort by name to stabilize registration order |
| 191 | + .sorted(Comparator.comparing(Method::getName)) |
| 192 | + .forEach((Method method) -> { |
| 193 | + method.setAccessible(true); |
| 194 | + addFromAnnotatedConfiguration(holder, method, method.getReturnType()); |
| 195 | + }); |
196 | 196 | } |
197 | 197 |
|
198 | 198 | private <T> void addFromAnnotatedConfiguration(BeanHolder<?> holder, Method method, Class<T> returnType) { |
|
0 commit comments