把部分硬编码语言文件抽取到新的语言系统

This commit is contained in:
Izzel_Aliz
2018-04-28 22:56:16 +08:00
parent 20fcb3dfa0
commit 250d168c2e
24 changed files with 434 additions and 325 deletions

View File

@@ -22,7 +22,7 @@ public class Ref {
public static final int ACC_SYNTHETIC = 0x1000;
public static List<Field> getDeclaredFields(Class<?> clazz) {
return getDeclaredFields(clazz, 0, false);
return getDeclaredFields(clazz, 0, true);
}
public static List<Field> getDeclaredFields(String clazz, int excludeModifiers, boolean cache) {
@@ -40,7 +40,6 @@ public class Ref {
if (clazz == TLib.class)
return Arrays.asList(clazz.getDeclaredFields());
Class.forName("org.objectweb.asm.ClassVisitor");
List<Field> fields;
if ((fields = cachedFields.get(clazz.getName())) != null) return fields;
ClassReader classReader = new ClassReader(clazz.getResourceAsStream("/" + clazz.getName().replace('.', '/') + ".class"));
@@ -55,8 +54,15 @@ public class Ref {
}).filter(Objects::nonNull).collect(Collectors.toList());
if (cache) cachedFields.putIfAbsent(clazz.getName(), fields);
return fields;
} catch (Exception e) {
return Collections.emptyList();
} catch (Exception | Error e) {
try {
List<Field> list = Arrays.stream(clazz.getDeclaredFields())
.filter(field -> (field.getModifiers() & excludeModifiers) == 0).collect(Collectors.toList());
cachedFields.putIfAbsent(clazz.getName(), list);
return list;
} catch (Error err) {
return Collections.emptyList();
}
}
}

View File

@@ -10,7 +10,7 @@ public class Strings {
* @return 替换好的字符串
*/
public static String replaceWithOrder(String template, String... args) {
if (args.length == 0) return template;
if (args.length == 0 || template.length() == 0) return template;
char[] arr = template.toCharArray();
StringBuilder stringBuilder = new StringBuilder(template.length());
for (int i = 0; i < arr.length; i++) {

View File

@@ -0,0 +1,4 @@
package com.ilummc.tlib.util.asm;
public class AsmClassTransformer {
}