package love.distributedrebirth.bassboonyd; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.LinkedHashSet; import java.util.Set; import java.util.function.Consumer; import love.distributedrebirth.bassboonyd.BãßBȍőnSpiderʸᴰ.SpiderSilk; import love.distributedrebirth.bassboonyd.info.BãßBȍőnAuthor注; @BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天") public final class BãßBȍőnLoad殭屍 { public static class Ꝑŕḯṿª₮ḕ implements BãßBȍőnꝐŕḯṿª₮ḕ { private static final BãßBȍőnSpiderʸᴰ BLACK_WIDOW = new BãßBȍőnSpiderʸᴰ(); private static final Set> SCANNED = new LinkedHashSet<>(); } @SafeVarargs protected static void CAST_BONE_MAGIC(BãßBȍőn boon, Consumer>...coffinFillers) { BãßBȍőnCoffinOpenʸᴰ bbc = BãßBȍőnCoffinOpenʸᴰ.FROM(boon); try { for (Consumer> embalmFactory:coffinFillers) { embalmFactory.accept(bbc); } for (BãßBȍőnꝐŕḯṿª₮ḕInitPhaseʸᴰ phase:BãßBȍőnꝐŕḯṿª₮ḕInitPhaseʸᴰ.values()) { initPrivate(phase, boon); } initSpiderEggs(boon, bbc); initSpiderWires(boon, bbc); } catch (Exception e) { throw new RuntimeException(e); } } private static void initSpiderWires(Object boon, BãßBȍőnCoffinOpenʸᴰ bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { //System.out.println("SCAN-BOON-FIELD: "+boon.getClass().getSimpleName()); for (Field m:boon.getClass().getDeclaredFields()) { if (!m.isAnnotationPresent(BãßBȍőnSpiderWire注.class)) { continue; } BãßBȍőnSpiderWire注 anno = m.getAnnotation(BãßBȍőnSpiderWire注.class); SpiderSilk silkRoad = Ꝑŕḯṿª₮ḕ.BLACK_WIDOW.silkRoad(m.getType()); Object bean = silkRoad.senseWire(boon, anno.name(), anno.description()); //System.out.println("type: "+ m.getType() +" wth name: "+anno.name()+" of boon: "+boon.getClass()); m.setAccessible(true); m.set(boon, bean); } } private static void initSpiderEggs(BãßBȍőn boon, BãßBȍőnCoffinOpenʸᴰ bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { for (Class interfaceClass:walkInterfaces(boon.getClass(), new LinkedHashSet<>())) { for (Class declaredClass:((Class) interfaceClass).getDeclaredClasses()) { initSpiderEggRegistrate(boon, declaredClass); } } for (Class declaredClass:boon.getClass().getDeclaredClasses()) { initSpiderEggRegistrate(boon, declaredClass); } } private static void initSpiderEggRegistrate(BãßBȍőn boon, Class declaredClass) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (!BãßBȍőnꝐŕḯṿª₮ḕ.class.isAssignableFrom(declaredClass)) { return; } if (Ꝑŕḯṿª₮ḕ.SCANNED.contains(declaredClass)) { return; } Ꝑŕḯṿª₮ḕ.SCANNED.add(declaredClass); for (Method m:declaredClass.getDeclaredMethods()) { if (!m.isAnnotationPresent(BãßBȍőnSpiderEgg注.class)) { continue; } //System.out.println("annoEgg: "+boon.getClass().getSimpleName()+"."+boon+" from: "+declaredClass.getName()+" m="+m.toGenericString()); m.setAccessible(true); Ꝑŕḯṿª₮ḕ.BLACK_WIDOW.registrateEgg(m.getReturnType(), m); } } private static void initPrivate(BãßBȍőnꝐŕḯṿª₮ḕInitPhaseʸᴰ phase, BãßBȍőn boon) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { for (Class interfaceClass:walkInterfaces(boon.getClass(), new LinkedHashSet<>())) { for (Class declaredClass:((Class) interfaceClass).getDeclaredClasses()) { initPrivateInvoke(phase, boon, declaredClass); } } for (Class declaredClass:boon.getClass().getDeclaredClasses()) { initPrivateInvoke(phase, boon, declaredClass); } } private static void initPrivateInvoke(BãßBȍőnꝐŕḯṿª₮ḕInitPhaseʸᴰ phase, BãßBȍőn boon, Class declaredClass) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (!BãßBȍőnꝐŕḯṿª₮ḕ.class.isAssignableFrom(declaredClass)) { return; } for (Method m:declaredClass.getDeclaredMethods()) { if (!m.isAnnotationPresent(BãßBȍőnꝐŕḯṿª₮ḕInit注.class)) { continue; } BãßBȍőnꝐŕḯṿª₮ḕInit注 anno = m.getAnnotation(BãßBȍőnꝐŕḯṿª₮ḕInit注.class); if (phase != anno.phase()) { continue; // TODO: redo to fast code path } //System.out.println("annoInvoke: req="+phase+" of "+boon.getClass().getSimpleName()+"."+boon+" from: "+declaredClass.getName()); m.setAccessible(true); Class[] para = m.getParameterTypes(); if (para.length == 0) { m.invoke(null); return; } if (para.length == 1 && BãßBȍőn.class.isAssignableFrom(para[0])) { m.invoke(null, boon); return; } throw new IllegalStateException("Unknown method parameters on: "+declaredClass.getSimpleName()+"."+m.toGenericString()); } } public static Set> walkInterfaces(Class clazz, Set> result) { while (clazz != null) { for (Class next : clazz.getInterfaces()) { if (result.add(next)) { walkInterfaces(next, result); } } clazz = clazz.getSuperclass(); } return result; } }