Cached length
This commit is contained in:
parent
9c1161e84c
commit
3acc28dbbf
9 changed files with 97 additions and 29 deletions
|
|
@ -0,0 +1,5 @@
|
|||
package love.distributedrebirth.bassboonyd;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
||||
public interface BãßBȍőnInitMarkerʸᴰ {
|
||||
}
|
||||
|
|
@ -18,14 +18,6 @@ public interface DefaultEnumSetʸᴰ<T> extends DefaultEnumBaseʸᴰ<T> {
|
|||
return ordinal() + 1;
|
||||
}
|
||||
|
||||
default int LENGTH() {
|
||||
return BãßĦǿɇṽḝę̃ɬḪễïđ();
|
||||
}
|
||||
|
||||
default int BãßĦǿɇṽḝę̃ɬḪễïđ() {
|
||||
return BãßInstances().length;
|
||||
}
|
||||
|
||||
default List<T> BãßInstancesList() {
|
||||
return Arrays.asList(BãßInstances());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,63 @@
|
|||
package love.distributedrebirth.bassboonyd;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@BãßBȍőnAuthorInfoʸᴰ(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
||||
@BãßBȍőnAnnotationInfoʸᴰ(required = {})
|
||||
public interface DefaultInitMethodʸᴰ {
|
||||
|
||||
default void BOON_INIT(Object boon) {
|
||||
try {
|
||||
for (Method m:boon.getClass().getMethods()) {
|
||||
if (m.isAnnotationPresent(BãßBȍőnInitMethodʸᴰ.class)) {
|
||||
m.invoke(boon, this);
|
||||
|
||||
final class InitScanner {
|
||||
|
||||
public void scanInterfaces(Object boon, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
for (Class<?> interfaceClass:walkInterfaces(boon.getClass(), new LinkedHashSet<>())) {
|
||||
for (Class<?> declaredClass:((Class<?>) interfaceClass).getDeclaredClasses()) {
|
||||
initStaticMarker(declaredClass, bbc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void scanClass(Object boon, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
for (Class<?> declaredClass:boon.getClass().getDeclaredClasses()) {
|
||||
initStaticMarker(declaredClass, bbc);
|
||||
}
|
||||
}
|
||||
|
||||
private void initStaticMarker(Class<?> declaredClass, Object bbc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
if (!BãßBȍőnInitMarkerʸᴰ.class.isAssignableFrom(declaredClass)) {
|
||||
return;
|
||||
}
|
||||
for (Method m:declaredClass.getDeclaredMethods()) {
|
||||
if (m.isAnnotationPresent(BãßBȍőnInitMethodʸᴰ.class)) {
|
||||
m.setAccessible(true);
|
||||
m.invoke(null, bbc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Class<?>> walkInterfaces(Class<?> clazz, Set<Class<?>> result) {
|
||||
while (clazz != null) {
|
||||
for (Class<?> next : clazz.getInterfaces()) {
|
||||
if (result.add(next)) {
|
||||
return walkInterfaces(next, result);
|
||||
}
|
||||
}
|
||||
clazz = clazz.getSuperclass();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
InitScanner init = new InitScanner();
|
||||
try {
|
||||
init.scanInterfaces(boon, this);
|
||||
init.scanClass(boon, this);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue