船新 I18n 系统

修了一个配置文件小bug
This commit is contained in:
Izzel_Aliz
2018-04-22 13:30:50 +08:00
parent 385b2aa974
commit c573617a01
18 changed files with 479 additions and 38 deletions

View File

@@ -4,6 +4,7 @@ import com.ilummc.tlib.TLib;
import com.ilummc.tlib.util.asm.AsmAnalyser;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import sun.reflect.Reflection;
import javax.annotation.concurrent.ThreadSafe;
import java.lang.reflect.Field;
@@ -46,11 +47,10 @@ public class Ref {
classReader.accept(analyser, ClassReader.SKIP_DEBUG);
fields = analyser.getFields().stream().map(name -> {
try {
System.out.println(name);
return clazz.getDeclaredField(name);
} catch (Throwable ignored) {
return null;
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
if (cache) cachedFields.putIfAbsent(clazz.getName(), fields);
return fields;
@@ -59,4 +59,44 @@ public class Ref {
}
}
public static Optional<Class<?>> getCallerClass(int depth) {
return Optional.ofNullable(CallerClass.impl.getCallerClass(depth + 1));
}
private static abstract class CallerClass {
private static CallerClass impl;
static {
try {
Class.forName("sun.reflect.Reflection");
impl = new ReflectionImpl();
} catch (ClassNotFoundException e) {
impl = new StackTraceImpl();
}
}
abstract Class<?> getCallerClass(int i);
private static class ReflectionImpl extends CallerClass {
@Override
Class<?> getCallerClass(int i) {
return Reflection.getCallerClass(i);
}
}
private static class StackTraceImpl extends CallerClass {
@Override
Class<?> getCallerClass(int i) {
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
try {
return Class.forName(elements[i].getClassName());
} catch (ClassNotFoundException e) {
return null;
}
}
}
}
}