2022-10-31 03:39:32 +00:00
|
|
|
|
package ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ;
|
2022-10-20 01:06:56 +00:00
|
|
|
|
|
2022-10-30 07:26:14 +00:00
|
|
|
|
import java.lang.annotation.Annotation;
|
2022-10-20 01:06:56 +00:00
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Comparator;
|
2022-10-20 21:04:45 +00:00
|
|
|
|
import java.util.HashSet;
|
2022-10-20 01:06:56 +00:00
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
import java.util.List;
|
2022-10-22 00:55:03 +00:00
|
|
|
|
import java.util.Map;
|
2022-10-30 08:53:44 +00:00
|
|
|
|
import java.util.Optional;
|
2022-10-20 01:06:56 +00:00
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
2022-10-31 03:39:32 +00:00
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒼᒻᣔᙆᙆ.ᣖᑊᣗᣔᐪᓫ.BãßBȍőnPiratePhaseBarrier注;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒼᒻᣔᙆᙆ.ᣖᑊᣗᣔᐪᓫ.BãßBȍőnPiratePhase注;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒼᒻᣔᙆᙆ.ᣖᑊᣗᣔᐪᓫ.BãßBȍőnPirateʸᴰ;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒼᒻᣔᙆᙆ.ᣖᑊᣗᣔᐪᓫ.BãßBȍőnꝐŕḯṿª₮ḕ;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒄᓫᣔᐪᑋ.BãßBȍőnCoffinDuytschenᵗˣᵗ;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒄᓫᣔᐪᑋ.ᔆᣖᑊᒄᓫᣗ.BãßBȍőnSpider;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒄᓫᣔᐪᑋ.ᔆᣖᑊᒄᓫᣗ.BãßBȍőnSpiderEgg注;
|
2022-11-01 21:23:15 +00:00
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒄᓫᣔᐪᑋ.ᔆᣖᑊᒄᓫᣗ.BãßBȍőnSpiderEye注;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒄᓫᣔᐪᑋ.ᔆᣖᑊᒄᓫᣗ.BãßBȍőnSpiderSilkHunt;
|
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒄᓫᣔᐪᑋ.ᔆᣖᑊᒄᓫᣗ.BãßBȍőnSpiderSilkRoad;
|
2022-10-31 03:39:32 +00:00
|
|
|
|
import ᒢᐩᐩ.ᒃᣔᔆᔆᒃᐤᐤᣕ.ᒄᓫᣔᐪᑋ.ᔆᣖᑊᒄᓫᣗ.BãßBȍőnSpiderWire注;
|
2022-11-05 12:41:48 +00:00
|
|
|
|
import ᒢᐩᐩ.ᔆʸᔆᐪᓫᔿ.ᒃᣔᒃᓫᒻ.ᑊᐣᓑᖮᐪᔆ.DuytsDocAuthor注;
|
2022-11-03 02:58:54 +00:00
|
|
|
|
import ᒢᐩᐩ.ᔆʸᔆᐪᓫᔿ.ᒻᐤᕐᕐᓫᣗ.SoepLepelբ;
|
2022-10-20 01:06:56 +00:00
|
|
|
|
|
2022-10-30 15:59:24 +00:00
|
|
|
|
@DuytsDocAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
2022-10-24 12:34:30 +00:00
|
|
|
|
public final class DefaultBȍőnLoader implements Bãß.𝔅𝔬𝔫𝔢𝔏𝔬𝔞𝔡𝔢𝔯ʸᴰ {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
|
2022-11-01 21:23:15 +00:00
|
|
|
|
private final SoepLepelբ log;
|
|
|
|
|
|
2022-10-24 12:34:30 +00:00
|
|
|
|
protected DefaultBȍőnLoader() {
|
2022-11-01 21:23:15 +00:00
|
|
|
|
log = soepLepel();
|
2022-10-20 01:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 12:34:30 +00:00
|
|
|
|
public <T extends BãßBȍőnʸᴰ<T>> void 𝔩𝔬𝔠𝔨𝔅𝔬𝔫𝔢𝔐𝔞𝔤𝔦𝔠(BãßBȍőnʸᴰ<T> boon, BãßBȍőnSpider spider) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
try {
|
2022-10-24 15:46:37 +00:00
|
|
|
|
List<PiratePhaseBoat> filoBoats = loadPirateBoats(boon);// TODO: run from spider objects...
|
2022-10-20 01:06:56 +00:00
|
|
|
|
Collections.reverse(filoBoats);
|
2022-10-20 21:04:45 +00:00
|
|
|
|
|
|
|
|
|
// Set<Class<?>> ydmods = new HashSet<>();
|
2022-10-24 15:46:37 +00:00
|
|
|
|
for (PiratePhaseBoat boat : filoBoats) {
|
2022-10-20 21:04:45 +00:00
|
|
|
|
// if (ydmods.add(boat.pirateClazz.getDeclaringClass())) {
|
|
|
|
|
// spider.registrateEgg(boat.pirateClazz.getDeclaringClass(), new BãßBȍőnSpiderSilk() {
|
|
|
|
|
// @Override
|
|
|
|
|
// public Object senseWire(BãßBȍőnʸᴰ<?> boonTmp, String name, String description)
|
|
|
|
|
// throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
|
|
|
// return boonTmp;
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
//registrateSpiderEggs(boat.pirateClazz, spider, boat.pirate);
|
2022-11-01 21:23:15 +00:00
|
|
|
|
spiderWeave(boat.pirate, boon, spider);
|
2022-10-20 21:04:45 +00:00
|
|
|
|
boat.pirate.lock();
|
2022-10-20 01:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 12:34:30 +00:00
|
|
|
|
public <T extends BãßBȍőnʸᴰ<T>> void 𝔦𝔫𝔦𝔱𝔅𝔬𝔫𝔢𝔐𝔞𝔤𝔦𝔠(BãßBȍőnʸᴰ<T> boon, BãßBȍőnSpider spider, Map<Class<? extends BãßBȍőnCoffinDuytschenᵗˣᵗ>,BãßBȍőnCoffinDuytschenᵗˣᵗ> duytschenCoffins) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
try {
|
2022-11-01 21:23:15 +00:00
|
|
|
|
log.groente("INIT "+boon.getClass().getName());
|
2022-10-22 00:55:03 +00:00
|
|
|
|
for (Class<?> duytschenType:duytschenCoffins.keySet()) {
|
|
|
|
|
BãßBȍőnCoffinDuytschenᵗˣᵗ duytschenCoffin = duytschenCoffins.get(duytschenType);
|
2022-11-01 21:23:15 +00:00
|
|
|
|
log.groente("INIT.REG_TXT "+duytschenType+" senseResult="+duytschenCoffin);
|
|
|
|
|
spider.registrateSilkHighWay(duytschenType, () -> duytschenCoffin);
|
2022-10-22 00:55:03 +00:00
|
|
|
|
}
|
2022-10-30 07:26:14 +00:00
|
|
|
|
for (Annotation anno:boon.getClass().getDeclaredAnnotations()) {
|
2022-11-01 21:23:15 +00:00
|
|
|
|
log.groente("INIT.REG_ANNO "+anno.annotationType());
|
|
|
|
|
spider.registrateSilkHighWay(anno.annotationType(), () -> anno);
|
2022-10-30 07:26:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-20 21:04:45 +00:00
|
|
|
|
Set<Class<?>> ydmods = new HashSet<>();
|
2022-10-24 15:46:37 +00:00
|
|
|
|
for (PiratePhaseBoat boat : loadPirateBoats(boon)) {
|
2022-11-01 21:23:15 +00:00
|
|
|
|
log.groente("INIT.RUN "+boat.pirateClazz.getName());
|
2022-10-20 21:04:45 +00:00
|
|
|
|
|
|
|
|
|
if (ydmods.add(boat.pirateClazz.getDeclaringClass())) {
|
2022-11-01 21:23:15 +00:00
|
|
|
|
log.groente("INIT.REG_MOD "+boat.pirateClazz.getDeclaringClass());
|
|
|
|
|
spider.registrateSilkHighWay(boat.pirateClazz.getDeclaringClass(), () -> boon);
|
2022-10-20 21:04:45 +00:00
|
|
|
|
}
|
2022-11-01 21:23:15 +00:00
|
|
|
|
for (Method m:boat.pirateClazz.getDeclaredMethods()) {
|
|
|
|
|
BãßBȍőnSpiderEgg注 annoEgg = m.getAnnotation(BãßBȍőnSpiderEgg注.class);
|
|
|
|
|
if (annoEgg == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Class<?> resultType = m.getReturnType();
|
|
|
|
|
if (!annoEgg.silk().equals(BãßBȍőnSpiderEgg注.class)) {
|
|
|
|
|
resultType = annoEgg.silk();
|
|
|
|
|
}
|
|
|
|
|
log.groente("INIT.REG_HUNT: "+boat.pirateClazz.getDeclaringClass().getName()+"."+boat.pirateClazz.getSimpleName()+"."+m.getName());
|
|
|
|
|
|
|
|
|
|
// TODO: merge back to common interface ?
|
|
|
|
|
spider.registrateSilkHuntMethod(resultType, boat.pirate, m);
|
|
|
|
|
if (m.getParameterCount() == 0) {
|
|
|
|
|
spider.registrateSilkHighWay(resultType, () -> {
|
|
|
|
|
try {
|
|
|
|
|
return m.invoke(boat.pirate);
|
|
|
|
|
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-10-20 21:04:45 +00:00
|
|
|
|
}
|
2022-11-01 21:23:15 +00:00
|
|
|
|
spiderWeave(boat.pirate, boon, spider);
|
|
|
|
|
boat.pirate.init();
|
2022-10-20 01:06:56 +00:00
|
|
|
|
}
|
2022-11-01 21:23:15 +00:00
|
|
|
|
spiderWeave(boon, boon, spider);
|
2022-10-20 01:06:56 +00:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 21:23:15 +00:00
|
|
|
|
private void spiderWeave(Object target, BãßBȍőnʸᴰ<?> boon, BãßBȍőnSpider spider) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
|
|
|
if (target.getClass().getDeclaredFields().length == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
log.groente("SPIDER.WEAVE: "+target.getClass().getName());
|
2022-11-01 01:02:45 +00:00
|
|
|
|
for (Field field:target.getClass().getDeclaredFields()) {
|
2022-11-01 21:23:15 +00:00
|
|
|
|
BãßBȍőnSpiderWire注 annoWire = field.getAnnotation(BãßBȍőnSpiderWire注.class);
|
|
|
|
|
if (annoWire == null) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-11-01 21:23:15 +00:00
|
|
|
|
Class<?> requestType = field.getType();
|
|
|
|
|
if (!annoWire.silk().equals(BãßBȍőnSpiderWire注.class)) {
|
|
|
|
|
requestType = annoWire.silk();
|
|
|
|
|
}
|
|
|
|
|
Object bean = null;
|
|
|
|
|
if (annoWire.hunt().fly().isBlank()) {
|
|
|
|
|
boolean canResolve = spider.hasSilkRoad(requestType);
|
|
|
|
|
if (canResolve == false && annoWire.required() == false) {
|
|
|
|
|
continue; // optional
|
|
|
|
|
}
|
|
|
|
|
if (canResolve == false) {
|
|
|
|
|
boolean canResolve2 = spider.hasSilkHunt(requestType);
|
|
|
|
|
if (canResolve2 == false) {
|
|
|
|
|
throw new RuntimeException("Can't find fly hunter for field: "+field);
|
|
|
|
|
}
|
|
|
|
|
BãßBȍőnSpiderSilkHunt silkHunt = spider.getSilkHunt(requestType);
|
|
|
|
|
bean = silkHunt.dragonFly(null, null, null);
|
|
|
|
|
log.groente("SPIDER.WEAVE.HUNT: "+ requestType.getSimpleName() +" result: "+bean.getClass().getName());
|
|
|
|
|
} else {
|
|
|
|
|
BãßBȍőnSpiderSilkRoad silkRoad = spider.getSilkRoad(requestType);
|
|
|
|
|
bean = silkRoad.weaveWire();
|
|
|
|
|
log.groente("SPIDER.WEAVE.WIRE: "+ requestType.getSimpleName() +" result: "+bean.getClass().getName());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
BãßBȍőnSpiderEye注 annoEye = annoWire.hunt();
|
|
|
|
|
boolean canResolve = spider.hasSilkHunt(requestType);
|
|
|
|
|
if (canResolve == false) {
|
|
|
|
|
throw new RuntimeException("Can't find fly hunter for field: "+field);
|
|
|
|
|
}
|
|
|
|
|
BãßBȍőnSpiderSilkHunt silkHunt = spider.getSilkHunt(requestType);
|
|
|
|
|
bean = silkHunt.dragonFly(annoEye.fly(), annoEye.name(), annoEye.description());
|
|
|
|
|
log.groente("SPIDER.WEAVE.HUNT: "+ requestType.getSimpleName() +" result: "+bean.getClass().getName());
|
|
|
|
|
}
|
2022-11-01 01:02:45 +00:00
|
|
|
|
if (field.trySetAccessible() ) {
|
|
|
|
|
field.set(target, bean);
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("Can't access field: "+field);
|
|
|
|
|
}
|
2022-10-20 01:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 15:46:37 +00:00
|
|
|
|
private static class PiratePhaseBoat {
|
|
|
|
|
private Class<BãßBȍőnꝐŕḯṿª₮ḕ> pirateClazz;
|
|
|
|
|
private BãßBȍőnꝐŕḯṿª₮ḕ pirate;
|
2022-10-20 01:06:56 +00:00
|
|
|
|
|
2022-10-24 15:46:37 +00:00
|
|
|
|
private PiratePhaseBoat(Class<BãßBȍőnꝐŕḯṿª₮ḕ> pirateClazz) {
|
2022-10-23 01:04:55 +00:00
|
|
|
|
if (pirateClazz.isEnum()) {
|
|
|
|
|
throw new IllegalStateException("Can't hide enum pirate type: "+pirateClazz);
|
|
|
|
|
}
|
2022-10-20 01:06:56 +00:00
|
|
|
|
this.pirateClazz = pirateClazz;
|
|
|
|
|
try {
|
2022-10-24 15:46:37 +00:00
|
|
|
|
this.pirate = (BãßBȍőnꝐŕḯṿª₮ḕ) pirateClazz.getConstructor().newInstance();
|
2022-10-20 01:06:56 +00:00
|
|
|
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
|
|
|
|
| NoSuchMethodException | SecurityException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 21:23:15 +00:00
|
|
|
|
private <T extends BãßBȍőnʸᴰ<T>> List<PiratePhaseBoat> loadPirateBoats(BãßBȍőnʸᴰ<T> boon) {
|
2022-10-24 15:46:37 +00:00
|
|
|
|
List<PiratePhaseBoat> boonInits = new ArrayList<>();
|
|
|
|
|
List<PiratePhaseBoat> serviceInits = new ArrayList<>();
|
2022-10-20 01:06:56 +00:00
|
|
|
|
walkPrivate(boon, v -> {
|
|
|
|
|
BãßBȍőnPiratePhaseBarrier注 anno = v.getAnnotation(BãßBȍőnPiratePhaseBarrier注.class);
|
|
|
|
|
if (anno != null) {
|
2022-10-24 15:46:37 +00:00
|
|
|
|
boonInits.add(new PiratePhaseBoat(v));
|
2022-10-20 01:06:56 +00:00
|
|
|
|
} else {
|
2022-10-24 15:46:37 +00:00
|
|
|
|
serviceInits.add(new PiratePhaseBoat(v));
|
2022-10-20 01:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-24 15:46:37 +00:00
|
|
|
|
boonInits.sort(new Comparator<PiratePhaseBoat>() {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
@Override
|
2022-10-24 15:46:37 +00:00
|
|
|
|
public int compare(PiratePhaseBoat p0, PiratePhaseBoat p1) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
BãßBȍőnPiratePhaseBarrier注 anno0 = p0.pirateClazz.getAnnotation(BãßBȍőnPiratePhaseBarrier注.class);
|
|
|
|
|
BãßBȍőnPiratePhaseBarrier注 anno1 = p1.pirateClazz.getAnnotation(BãßBȍőnPiratePhaseBarrier注.class);
|
|
|
|
|
return Integer.compare(anno0.order(), anno1.order());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-24 15:46:37 +00:00
|
|
|
|
List<PiratePhaseBoat> result = new ArrayList<>();
|
|
|
|
|
for (PiratePhaseBoat startupPhase:boonInits) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
result.add(startupPhase);
|
2022-10-24 15:46:37 +00:00
|
|
|
|
for (PiratePhaseBoat v:new ArrayList<>(serviceInits)) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
int depCount = 0;
|
2022-10-24 15:46:37 +00:00
|
|
|
|
List<Class<? extends BãßBȍőnꝐŕḯṿª₮ḕ>> deps = new ArrayList<>();
|
2022-10-20 01:06:56 +00:00
|
|
|
|
BãßBȍőnPiratePhase注 anno = v.pirateClazz.getAnnotation(BãßBȍőnPiratePhase注.class);
|
|
|
|
|
if (anno != null) {
|
|
|
|
|
deps.addAll(Arrays.asList(anno.dependencies()));
|
|
|
|
|
} else {
|
|
|
|
|
deps.add(BãßBȍőnPirateʸᴰ.שְׁלֹמֹה.DEFAULT_PHASE);
|
|
|
|
|
}
|
|
|
|
|
for (Class<?> clazz:deps) {
|
2022-10-24 15:46:37 +00:00
|
|
|
|
for (PiratePhaseBoat doneInit:result) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
if (clazz.equals(doneInit.pirateClazz)) {
|
|
|
|
|
depCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (depCount == deps.size()) {
|
|
|
|
|
result.add(v);
|
|
|
|
|
serviceInits.remove(v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.addAll(serviceInits);
|
2022-11-01 21:23:15 +00:00
|
|
|
|
for (PiratePhaseBoat boat:result) {
|
|
|
|
|
log.groente("INIT.ORDER "+boat.pirateClazz.getName());
|
|
|
|
|
}
|
2022-10-20 01:06:56 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2022-10-24 15:46:37 +00:00
|
|
|
|
private static <T extends BãßBȍőnʸᴰ<T>> void walkPrivate(BãßBȍőnʸᴰ<T> boon, Consumer<Class<BãßBȍőnꝐŕḯṿª₮ḕ>> runPrivate) {
|
2022-10-20 01:06:56 +00:00
|
|
|
|
for (Class<?> interfaceClass:walkInterfaces(boon.getClass(), new LinkedHashSet<>())) {
|
|
|
|
|
for (Class<?> declaredClass:interfaceClass.getDeclaredClasses()) {
|
|
|
|
|
if (!BãßBȍőnꝐŕḯṿª₮ḕ.class.isAssignableFrom(declaredClass)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-10-24 15:46:37 +00:00
|
|
|
|
runPrivate.accept((Class<BãßBȍőnꝐŕḯṿª₮ḕ>)declaredClass);
|
2022-10-20 01:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (Class<?> declaredClass:boon.getClass().getDeclaredClasses()) {
|
|
|
|
|
if (!BãßBȍőnꝐŕḯṿª₮ḕ.class.isAssignableFrom(declaredClass)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-10-24 15:46:37 +00:00
|
|
|
|
runPrivate.accept((Class<BãßBȍőnꝐŕḯṿª₮ḕ>)declaredClass);
|
2022-10-20 01:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-30 08:53:44 +00:00
|
|
|
|
public static Optional<Class<?>> findInterfaceByAnnotation(Class<?> clazz, Class<? extends Annotation> annoType) {
|
|
|
|
|
return walkInterfaces(clazz, new LinkedHashSet<>()).stream().filter(v -> v.isAnnotationPresent(annoType)).findFirst();
|
2022-10-30 07:26:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-20 01:06:56 +00:00
|
|
|
|
public static Set<Class<?>> walkInterfaces(Class<?> clazz, Set<Class<?>> result) {
|
|
|
|
|
return walkTree(clazz, result, v -> Arrays.asList(v.getInterfaces()), v -> v.getSuperclass());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static <N> Set<N> walkTree(N node, Set<N> result, Function<N, Collection<N>> childs, Function<N,N> resolve) {
|
|
|
|
|
while (node != null) {
|
|
|
|
|
for (N next : childs.apply(node)) {
|
|
|
|
|
if (result.add(next)) {
|
|
|
|
|
walkTree(next, result, childs, resolve);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
node = resolve.apply(node);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|