|
52 | 52 | import java.util.stream.Collectors; |
53 | 53 | import java.util.zip.ZipError; |
54 | 54 |
|
| 55 | +import org.objectweb.asm.AnnotationVisitor; |
55 | 56 | import org.objectweb.asm.ClassReader; |
56 | 57 | import org.objectweb.asm.ClassVisitor; |
57 | 58 | import org.objectweb.asm.ClassWriter; |
58 | 59 | import org.objectweb.asm.FieldVisitor; |
59 | 60 | import org.objectweb.asm.MethodVisitor; |
60 | 61 | import org.objectweb.asm.Opcodes; |
| 62 | +import org.objectweb.asm.RecordComponentVisitor; |
61 | 63 | import org.objectweb.asm.commons.Remapper; |
62 | 64 | import org.objectweb.asm.util.CheckClassAdapter; |
63 | 65 |
|
@@ -1138,6 +1140,69 @@ private byte[] apply(final ClassInstance cls) { |
1138 | 1140 | return writer.toByteArray(); |
1139 | 1141 | } |
1140 | 1142 |
|
| 1143 | + /** |
| 1144 | + * Creates a class visitor which remaps the visited class before passing it to the downstream visitor. |
| 1145 | + * |
| 1146 | + * <p><strong>This class visitor will only remap, any registered pre- and post-visitors will not be returned by |
| 1147 | + * this method! Since the class is only analyzed in isolation, package access fixes will also not be applied.</strong> |
| 1148 | + * |
| 1149 | + * <p>This method will use the default multi-release jar (MRJ) context, i.e. no context from classes in |
| 1150 | + * {@code META-INF/versions/*}. |
| 1151 | + * |
| 1152 | + * @param delegate The downstream visitor called with the remapped class. |
| 1153 | + * @return The remapping class visitor. |
| 1154 | + */ |
| 1155 | + public ClassVisitor createClassRemapperVisitor(ClassVisitor delegate) { |
| 1156 | + return new AsmClassRemapper(delegate, defaultState.remapper, rebuildSourceFilenames, |
| 1157 | + false, skipLocalMapping, renameInvalidLocals, invalidLvNamePattern, inferNameFromSameLvIndex); |
| 1158 | + } |
| 1159 | + |
| 1160 | + /** |
| 1161 | + * Creates a field visitor which remaps the visited field before passing it to the downstream visitor. |
| 1162 | + * |
| 1163 | + * @param delegate The downstream visitor called with the remapped field. |
| 1164 | + * @return The remapping field visitor. |
| 1165 | + */ |
| 1166 | + public FieldVisitor createFieldRemapperVisitor(FieldVisitor delegate) { |
| 1167 | + return new AsmClassRemapper.AsmFieldRemapper(delegate, defaultState.remapper); |
| 1168 | + } |
| 1169 | + |
| 1170 | + /** |
| 1171 | + * Creates a method visitor which remaps the visited method before passing it to the downstream visitor. |
| 1172 | + * |
| 1173 | + * @param delegate The downstream visitor called with the remapped method. |
| 1174 | + * @param owner The internal name of the class owning the method. |
| 1175 | + * @param access The access flags of the method. |
| 1176 | + * @param name The name of the method being visited. |
| 1177 | + * @param desc The descriptor of the method being visited. |
| 1178 | + * @return The remapping method visitor. |
| 1179 | + */ |
| 1180 | + public MethodVisitor createMethodRemapperVisitor(MethodVisitor delegate, String owner, int access, String name, String desc) { |
| 1181 | + return new AsmClassRemapper.AsmMethodRemapper(delegate, defaultState.remapper, owner, access, name, desc, |
| 1182 | + skipLocalMapping, renameInvalidLocals, invalidLvNamePattern, inferNameFromSameLvIndex); |
| 1183 | + } |
| 1184 | + |
| 1185 | + /** |
| 1186 | + * Creates a record component visitor which remaps the visited record component before passing it to the downstream visitor. |
| 1187 | + * |
| 1188 | + * @param delegate The downstream visitor called with the remapped record component. |
| 1189 | + * @return The remapping record component visitor. |
| 1190 | + */ |
| 1191 | + public RecordComponentVisitor createRecordComponentRemapperVisitor(RecordComponentVisitor delegate) { |
| 1192 | + return new AsmClassRemapper.AsmRecordComponentRemapper(delegate, defaultState.remapper); |
| 1193 | + } |
| 1194 | + |
| 1195 | + /** |
| 1196 | + * Creates an annotation visitor which remaps the visited annotation before passing it to the downstream visitor. |
| 1197 | + * |
| 1198 | + * @param delegate The downstream visitor that receives the remapped annotation. |
| 1199 | + * @param desc The descriptor of the annotation. |
| 1200 | + * @return The remapping annotation visitor. |
| 1201 | + */ |
| 1202 | + public AnnotationVisitor createAnnotationRemapperVisitor(AnnotationVisitor delegate, String desc) { |
| 1203 | + return new AsmClassRemapper.AsmAnnotationRemapper(desc, delegate, defaultState.remapper); |
| 1204 | + } |
| 1205 | + |
1141 | 1206 | private byte[] fixClass(ClassInstance cls, byte[] data) { |
1142 | 1207 | boolean makeClsPublic = classesToMakePublic.contains(cls); |
1143 | 1208 | Set<String> clsMembersToMakePublic = null; |
|
0 commit comments