another ~0.03s less :3
This commit is contained in:
parent
1dcd0c8c05
commit
dd8b87a1cf
|
@ -103,7 +103,7 @@ class AWProcessor {
|
||||||
|
|
||||||
classNames.parallelStream().forEach(name -> {
|
classNames.parallelStream().forEach(name -> {
|
||||||
try {
|
try {
|
||||||
processFile(out.getPath("/" + name + ".class"), classMap, fields, methods, mutations);
|
processFile(name, out.getPath("/" + name + ".class"), classMap, fields, methods, mutations);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
|
@ -113,63 +113,60 @@ class AWProcessor {
|
||||||
LOGGER.info(String.format("Applied AccessWideners in %.2fs", (System.currentTimeMillis() - startTime) / 1000f));
|
LOGGER.info(String.format("Applied AccessWideners in %.2fs", (System.currentTimeMillis() - startTime) / 1000f));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processFile(Path file, Map<String, Entry> classMap, Map<String, Map<String, Entry>> fields, Map<String, Map<String, Entry>> methods, Map<String, Map<String, Entry>> mutations) throws IOException {
|
private static void processFile(String className, Path file, Map<String, Entry> classMap, Map<String, Map<String, Entry>> fields, Map<String, Map<String, Entry>> methods, Map<String, Map<String, Entry>> mutations) throws IOException {
|
||||||
var className = file.toString().substring(1, file.toString().length() - 6);
|
ClassReader reader = new ClassReader(Files.newInputStream(file));
|
||||||
if (file.getFileName().toString().endsWith(".class") && (classMap.containsKey(className) || fields.containsKey(className) || methods.containsKey(className) || mutations.containsKey(className))) {
|
ClassWriter writer = new ClassWriter(0);
|
||||||
ClassReader reader = new ClassReader(Files.newInputStream(file));
|
ClassVisitor mapper = new ClassVisitor(Opcodes.ASM9, writer) {
|
||||||
ClassWriter writer = new ClassWriter(0);
|
@Override
|
||||||
ClassVisitor mapper = new ClassVisitor(Opcodes.ASM9, writer) {
|
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||||
@Override
|
Entry e = classMap.get(className);
|
||||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
if (e != null) {
|
||||||
Entry e = classMap.get(className);
|
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||||
|
access |= e.type.access;
|
||||||
|
}
|
||||||
|
if (fields.containsKey(className) || methods.containsKey(className) || mutations.containsKey(className)) { // make all classes with modifications public as well
|
||||||
|
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||||
|
access |= Opcodes.ACC_PUBLIC;
|
||||||
|
}
|
||||||
|
super.visit(version, access, name, signature, superName, interfaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
|
||||||
|
Map<String, Entry> map = fields.get(className);
|
||||||
|
if (map != null) {
|
||||||
|
Entry e = map.get(name + descriptor);
|
||||||
|
if (e != null) {
|
||||||
|
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC); // remove all access modifiers
|
||||||
|
access |= e.type.access; // re-add the new one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((map = mutations.get(className)) != null) {
|
||||||
|
var e = map.get(name + descriptor);
|
||||||
|
if (e != null) {
|
||||||
|
access &= ~Opcodes.ACC_FINAL; // always AccessType.MUTABLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.visitField(access, name, descriptor, signature, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||||
|
Map<String, Entry> map = methods.get(className);
|
||||||
|
if (map != null) {
|
||||||
|
Entry e = map.get(name + descriptor);
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||||
access |= e.type.access;
|
access |= e.type.access;
|
||||||
}
|
}
|
||||||
if (fields.containsKey(className) || methods.containsKey(className) || mutations.containsKey(className)) { // make all classes with modifications public as well
|
|
||||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
|
||||||
access |= Opcodes.ACC_PUBLIC;
|
|
||||||
}
|
|
||||||
super.visit(version, access, name, signature, superName, interfaces);
|
|
||||||
}
|
}
|
||||||
|
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
reader.accept(mapper, 0);
|
||||||
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
|
|
||||||
Map<String, Entry> map = fields.get(className);
|
|
||||||
if (map != null) {
|
|
||||||
Entry e = map.get(name + descriptor);
|
|
||||||
if (e != null) {
|
|
||||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC); // remove all access modifiers
|
|
||||||
access |= e.type.access; // re-add the new one
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((map = mutations.get(className)) != null) {
|
|
||||||
var e = map.get(name + descriptor);
|
|
||||||
if (e != null) {
|
|
||||||
access &= ~Opcodes.ACC_FINAL; // always AccessType.MUTABLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.visitField(access, name, descriptor, signature, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
Files.write(file, writer.toByteArray());
|
||||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
|
||||||
Map<String, Entry> map = methods.get(className);
|
|
||||||
if (map != null) {
|
|
||||||
Entry e = map.get(name + descriptor);
|
|
||||||
if (e != null) {
|
|
||||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
|
||||||
access |= e.type.access;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.accept(mapper, 0);
|
|
||||||
|
|
||||||
Files.write(file, writer.toByteArray());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private record Entry(AccessType type, String targetType, String className, String name, String descriptor) {
|
private record Entry(AccessType type, String targetType, String className, String name, String descriptor) {
|
||||||
|
|
Loading…
Reference in a new issue