-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Patches.java
631 lines (580 loc) · 22.9 KB
/
Patches.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
package me.nallar.tickthreading.patcher;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Splitter;
import javassist.CannotCompileException;
import javassist.ClassMap;
import javassist.CtBehavior;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtField;
import javassist.CtMethod;
import javassist.CtNewMethod;
import javassist.Modifier;
import javassist.NotFoundException;
import javassist.bytecode.BadBytecode;
import javassist.expr.Cast;
import javassist.expr.ConstructorCall;
import javassist.expr.ExprEditor;
import javassist.expr.FieldAccess;
import javassist.expr.Handler;
import javassist.expr.Instanceof;
import javassist.expr.MethodCall;
import javassist.expr.NewArray;
import javassist.expr.NewExpr;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.mappings.MethodDescription;
@SuppressWarnings ("MethodMayBeStatic")
public class Patches {
private final ClassRegistry classRegistry;
public Patches(ClassRegistry classRegistry) {
this.classRegistry = classRegistry;
}
@Patch
public void markDirty(CtClass ctClass) {
// A NOOP patch to make sure META-INF is removed
}
@Patch (
name = "volatile"
)
public void volatile_(CtClass ctClass, Map<String, String> attributes) throws NotFoundException {
String field = attributes.get("field");
if (field == null) {
for (CtField ctField : ctClass.getDeclaredFields()) {
if (ctField.getType().isPrimitive()) {
ctField.setModifiers(ctField.getModifiers() | Modifier.VOLATILE);
}
}
} else {
CtField ctField = ctClass.getDeclaredField(field);
ctField.setModifiers(ctField.getModifiers() | Modifier.VOLATILE);
}
}
@Patch (
requiredAttributes = "class"
)
public CtClass replace(CtClass clazz, Map<String, String> attributes) throws NotFoundException, CannotCompileException {
Log.info("Replacing " + clazz.getName() + " with " + attributes.get("class"));
String oldName = clazz.getName();
clazz.setName(oldName + "_old");
CtClass newClass = classRegistry.getClass(attributes.get("class"));
newClass.getClassFile2().setSuperclass(null);
newClass.setName(oldName);
newClass.setModifiers(newClass.getModifiers() & ~Modifier.ABSTRACT);
return newClass;
}
@Patch
public void replaceMethod(CtMethod method, Map<String, String> attributes) throws NotFoundException, CannotCompileException, BadBytecode {
String fromClass = attributes.get("fromClass");
String code = attributes.get("code");
if (fromClass != null) {
String fromMethod = attributes.get("fromMethod");
CtMethod replacingMethod = fromMethod == null ?
classRegistry.getClass(fromClass).getDeclaredMethod(method.getName(), method.getParameterTypes())
: MethodDescription.fromString(fromClass, fromMethod).inClass(classRegistry.getClass(fromClass));
replaceMethod(method, replacingMethod);
} else if (code != null) {
Log.info("Replacing " + new MethodDescription(method).getMCPName() + " with " + code);
method.setBody(code);
} else {
Log.severe("Missing required attributes for replaceMethod");
}
}
private void replaceMethod(CtMethod oldMethod, CtMethod newMethod) throws CannotCompileException, BadBytecode {
Log.info("Replacing " + new MethodDescription(oldMethod).getMCPName() + " with " + new MethodDescription(newMethod).getMCPName());
ClassMap classMap = new ClassMap();
classMap.put(newMethod.getDeclaringClass().getName(), oldMethod.getDeclaringClass().getName());
oldMethod.setBody(newMethod, classMap);
oldMethod.getMethodInfo().rebuildStackMap(classRegistry.classes);
oldMethod.getMethodInfo().rebuildStackMapForME(classRegistry.classes);
}
@Patch (
requiredAttributes = "field"
)
public void replaceFieldUsage(CtBehavior ctBehavior, Map<String, String> attributes) throws CannotCompileException {
final String field = attributes.get("field");
final String readCode = attributes.get("readCode");
final String writeCode = attributes.get("writeCode");
if (readCode == null && writeCode == null) {
throw new IllegalArgumentException("readCode or writeCode must be set");
}
ctBehavior.instrument(new ExprEditor() {
@Override
public void edit(FieldAccess fieldAccess) throws CannotCompileException {
if (fieldAccess.getFieldName().equals(field)) {
if (fieldAccess.isWriter() && writeCode != null) {
fieldAccess.replace(writeCode);
} else if (fieldAccess.isReader() && readCode != null) {
fieldAccess.replace(readCode);
}
}
}
});
}
@Patch (
requiredAttributes = "code"
)
public void replaceMethodCall(final CtBehavior ctBehavior, Map<String, String> attributes) throws CannotCompileException {
String method_ = attributes.get("method");
if (method_ == null) {
method_ = "";
}
String className_ = null;
int dotIndex = method_.indexOf('.');
if (dotIndex != -1) {
className_ = method_.substring(0, dotIndex);
method_ = method_.substring(dotIndex + 1);
}
String index_ = attributes.get("index");
if (index_ == null) {
index_ = "-1";
}
final String method = method_;
final String className = className_;
final String code = attributes.get("code");
final int index = Integer.valueOf(index_);
Log.fine("method: " + method + ", class: " + className + ", code" + code + ", index: " + index);
ctBehavior.instrument(new ExprEditor() {
private int currentIndex = 0;
@Override
public void edit(MethodCall methodCall) throws CannotCompileException {
if ((className == null || methodCall.getClassName().equals(className)) && (method.isEmpty() || methodCall.getMethodName().equals(method)) && (index == -1 || currentIndex++ == index)) {
Log.info("Replaced " + methodCall + " from " + ctBehavior);
methodCall.replace(code);
}
}
});
}
@Patch (
requiredAttributes = "code,return,name"
)
public void addMethod(CtClass ctClass, Map<String, String> attributes) throws NotFoundException, CannotCompileException {
String name = attributes.get("name");
String return_ = attributes.get("return");
String code = attributes.get("code");
String parameterNamesList = attributes.get("parameters");
parameterNamesList = parameterNamesList == null ? "" : parameterNamesList;
List<CtClass> parameterList = new ArrayList<CtClass>();
for (String parameterName : Splitter.on(',').trimResults().omitEmptyStrings().split(parameterNamesList)) {
parameterList.add(classRegistry.getClass(parameterName));
}
CtMethod newMethod = new CtMethod(classRegistry.getClass(return_), name, parameterList.toArray(new CtClass[parameterList.size()]), ctClass);
newMethod.setBody('{' + code + '}');
ctClass.addMethod(newMethod);
}
@Patch (
requiredAttributes = "fromClass"
)
public void addAll(CtClass ctClass, Map<String, String> attributes) throws NotFoundException, CannotCompileException, BadBytecode {
String fromClass = attributes.get("fromClass");
CtClass from = classRegistry.getClass(fromClass);
ClassMap classMap = new ClassMap();
classMap.put(fromClass, ctClass.getName());
for (CtField ctField : from.getDeclaredFields()) {
if (!ctField.getName().isEmpty() && ctField.getName().charAt(ctField.getName().length() - 1) == '_') {
ctField.setName(ctField.getName().substring(0, ctField.getName().length() - 1));
}
try {
ctClass.getDeclaredField(ctField.getName());
} catch (NotFoundException ignored) {
Log.info("Added " + ctField);
ctClass.addField(new CtField(ctField, ctClass));
}
}
for (CtMethod newMethod : from.getDeclaredMethods()) {
if ((newMethod.getName().startsWith("construct") || newMethod.getName().startsWith("staticConstruct"))) {
try {
ctClass.getDeclaredMethod(newMethod.getName());
boolean found = true;
int i = 0;
String name = newMethod.getName();
while (found) {
i++;
try {
ctClass.getDeclaredMethod(name + i);
} catch (NotFoundException e2) {
found = false;
}
}
newMethod.setName(name + i);
} catch (NotFoundException ignored) {
// Not found - no need to change the name
}
}
}
for (CtMethod newMethod : from.getDeclaredMethods()) {
try {
CtMethod oldMethod = ctClass.getDeclaredMethod(newMethod.getName(), newMethod.getParameterTypes());
replaceMethod(oldMethod, newMethod);
Log.info("Replaced " + newMethod);
} catch (NotFoundException ignored) {
CtMethod added = CtNewMethod.copy(newMethod, ctClass, classMap);
Log.info("Adding " + added);
ctClass.addMethod(added);
if (added.getName().startsWith("construct")) {
CtMethod runConstructors = null;
try {
runConstructors = ctClass.getDeclaredMethod("runConstructors");
} catch (NotFoundException e) {
runConstructors = CtNewMethod.make("public void runConstructors() { }", ctClass);
ctClass.addMethod(runConstructors);
ctClass.addField(new CtField(classRegistry.getClass("boolean"), "isConstructed", ctClass), CtField.Initializer.constant(false));
for (CtBehavior ctBehavior : ctClass.getDeclaredConstructors()) {
ctBehavior.insertAfter("{ if(!this.isConstructed) { this.isConstructed = true; this.runConstructors(); } }");
}
}
runConstructors.insertAfter(added.getName() + "();");
}
if (added.getName().startsWith("staticConstruct")) {
ctClass.makeClassInitializer().insertAfter("{ " + added.getName() + "(); }");
}
}
}
for (CtClass CtInterface : from.getInterfaces()) {
ctClass.addInterface(CtInterface);
}
}
@Patch (
requiredAttributes = "field,threadLocalField,type"
)
public void threadLocal(CtClass ctClass, Map<String, String> attributes) throws CannotCompileException {
final String field = attributes.get("field");
final String threadLocalField = attributes.get("threadLocalField");
final String type = attributes.get("type");
String setExpression_ = attributes.get("setExpression");
final String setExpression = setExpression_ == null ? '(' + type + ") $1" : setExpression_;
Log.info(field + " -> " + threadLocalField);
ctClass.instrument(new ExprEditor() {
@Override
public void edit(FieldAccess e) throws CannotCompileException {
if (e.getFieldName().equals(field)) {
if (e.isReader()) {
e.replace("{ $_ = (" + type + ") " + threadLocalField + ".get(); }");
} else if (e.isWriter()) {
e.replace("{ " + threadLocalField + ".set(" + setExpression + "); }");
}
}
}
});
}
@Patch (
name = "public",
emptyConstructor = false
)
public void makePublic(Object o, Map<String, String> attributes) throws NotFoundException {
String field = attributes.get("field");
if (field == null) {
CtBehavior ctBehavior = (CtBehavior) o;
ctBehavior.setModifiers(Modifier.setPublic(ctBehavior.getModifiers()));
} else {
CtClass ctClass = (CtClass) o;
CtField ctField = ctClass.getDeclaredField(field);
ctField.setModifiers(Modifier.setPublic(ctField.getModifiers()));
}
}
@Patch (
requiredAttributes = "field"
)
public void newInitializer(CtClass ctClass, Map<String, String> attributes) throws NotFoundException, CannotCompileException, IOException {
String field = attributes.get("field");
String clazz = attributes.get("class");
String initialise = attributes.get("code");
String arraySize = attributes.get("arraySize");
initialise = "{ " + field + " = " + (initialise == null ? ("new " + clazz + (arraySize == null ? "()" : '[' + arraySize + ']')) : initialise) + "; }";
// Return value ignored - just used to cause a NotFoundException if the field doesn't exist.
ctClass.getDeclaredField(field);
for (CtConstructor ctConstructor : ctClass.getConstructors()) {
ctConstructor.insertAfter(initialise);
}
if (clazz != null) {
classRegistry.add(ctClass, clazz);
}
}
@Patch (
requiredAttributes = "field"
)
public void replaceField(CtClass ctClass, Map<String, String> attributes) throws NotFoundException, CannotCompileException, IOException {
String field = attributes.get("field");
String clazz = attributes.get("class");
String type = attributes.get("type");
if (type == null) {
type = clazz;
}
String initialise = attributes.get("code");
String arraySize = attributes.get("arraySize");
initialise = "{ " + field + " = " + (initialise == null ? ("new " + clazz + (arraySize == null ? "()" : '[' + arraySize + ']')) : initialise) + "; }";
CtField oldField = ctClass.getDeclaredField(field);
oldField.setName(oldField.getName() + "_old");
CtField newField = new CtField(classRegistry.getClass(type), field, ctClass);
newField.setModifiers(oldField.getModifiers());
ctClass.addField(newField);
for (CtConstructor ctConstructor : ctClass.getConstructors()) {
ctConstructor.insertAfter(initialise);
}
if (clazz != null) {
classRegistry.add(ctClass, clazz);
}
}
@Patch (
requiredAttributes = "field,class"
)
public void newField(CtClass ctClass, Map<String, String> attributes) throws NotFoundException, CannotCompileException, IOException {
String field = attributes.get("field");
String clazz = attributes.get("class");
String initialise = attributes.get("code");
if (initialise == null) {
initialise = "new " + clazz + "();";
}
CtClass newType = classRegistry.getClass(clazz);
CtField ctField = new CtField(newType, field, ctClass);
if (attributes.get("static") != null) {
ctField.setModifiers(ctField.getModifiers() | Modifier.STATIC | Modifier.PUBLIC);
}
CtField.Initializer initializer = CtField.Initializer.byExpr(initialise);
ctClass.addField(ctField, initializer);
classRegistry.add(ctClass, clazz);
}
@Patch (
requiredAttributes = "code"
)
public void insertBefore(CtBehavior ctBehavior, Map<String, String> attributes) throws NotFoundException, CannotCompileException, IOException {
String field = attributes.get("field");
String code = attributes.get("code");
if (field != null) {
code = code.replace("$field", field);
}
ctBehavior.insertBefore(code);
}
@Patch (
requiredAttributes = "code"
)
public void insertAfter(CtBehavior ctBehavior, Map<String, String> attributes) throws NotFoundException, CannotCompileException, IOException {
String field = attributes.get("field");
String code = attributes.get("code");
if (field != null) {
code = code.replace("$field", field);
}
ctBehavior.insertAfter(code);
}
@Patch
public void insertSuper(CtBehavior ctBehavior) throws CannotCompileException {
ctBehavior.insertBefore("super." + ctBehavior.getName() + "($$);");
}
@Patch (
requiredAttributes = "field"
)
public void lock(CtMethod ctMethod, Map<String, String> attributes) throws NotFoundException, CannotCompileException, IOException {
String field = attributes.get("field");
CtClass ctClass = ctMethod.getDeclaringClass();
CtMethod replacement = CtNewMethod.copy(ctMethod, ctClass, null);
ctMethod.setName(ctMethod.getName() + "_nolock");
replacement.setBody("{ this." + field + ".lock(); try { return " + (attributes.get("methodcall") == null ? "$proceed" : ctMethod.getName()) + "($$); } finally { this." + field + ".unlock(); } }", "this", ctMethod.getName());
ctClass.addMethod(replacement);
}
@Patch (
requiredAttributes = "field"
)
public void lockMethodCall(final CtBehavior ctBehavior, Map<String, String> attributes) throws CannotCompileException {
String method_ = attributes.get("method");
if (method_ == null) {
method_ = "";
}
String className_ = null;
int dotIndex = method_.indexOf('.');
if (dotIndex != -1) {
className_ = method_.substring(0, dotIndex);
method_ = method_.substring(dotIndex + 1);
}
String index_ = attributes.get("index");
if (index_ == null) {
index_ = "-1";
}
final String method = method_;
final String className = className_;
final String field = attributes.get("field");
final int index = Integer.valueOf(index_);
ctBehavior.instrument(new ExprEditor() {
private int currentIndex = 0;
@Override
public void edit(MethodCall methodCall) throws CannotCompileException {
if ((className == null || methodCall.getClassName().equals(className)) && (method.isEmpty() || methodCall.getMethodName().equals(method)) && (index == -1 || currentIndex++ == index)) {
Log.info("Replaced " + methodCall + " from " + ctBehavior);
methodCall.replace("{ " + field + ".lock(); try { $_ = $proceed($$); } finally { " + field + ".unlock(); } }");
}
}
});
}
@Patch (
requiredAttributes = "field"
)
public void synchronizeMethodCall(final CtBehavior ctBehavior, Map<String, String> attributes) throws CannotCompileException {
String method_ = attributes.get("method");
if (method_ == null) {
method_ = "";
}
String className_ = null;
int dotIndex = method_.indexOf('.');
if (dotIndex != -1) {
className_ = method_.substring(0, dotIndex);
method_ = method_.substring(dotIndex + 1);
}
String index_ = attributes.get("index");
if (index_ == null) {
index_ = "-1";
}
final String method = method_;
final String className = className_;
final String field = attributes.get("field");
final int index = Integer.valueOf(index_);
ctBehavior.instrument(new ExprEditor() {
private int currentIndex = 0;
@Override
public void edit(MethodCall methodCall) throws CannotCompileException {
if ((className == null || methodCall.getClassName().equals(className)) && (method.isEmpty() || methodCall.getMethodName().equals(method)) && (index == -1 || currentIndex++ == index)) {
Log.info("Replaced " + methodCall + " from " + ctBehavior);
methodCall.replace("synchronized(" + field + ") { $_ = $0.$proceed($$); }");
}
}
});
}
@Patch (
emptyConstructor = false
)
public void synchronize(Object o, Map<String, String> attributes) throws CannotCompileException {
if (o instanceof CtMethod) {
synchronize((CtMethod) o, attributes.get("field"));
} else {
boolean static_ = attributes.containsKey("static");
for (CtMethod ctMethod : ((CtClass) o).getDeclaredMethods()) {
boolean isStatic = (ctMethod.getModifiers() & Modifier.STATIC) == Modifier.STATIC;
if (isStatic == static_) {
synchronize(ctMethod, attributes.get("field"));
}
}
}
}
private void synchronize(CtMethod ctMethod, String field) throws CannotCompileException {
if (field == null) {
int currentModifiers = ctMethod.getModifiers();
if (Modifier.isSynchronized(currentModifiers)) {
Log.warning("Method: " + ctMethod.getLongName() + " is already synchronized");
} else {
ctMethod.setModifiers(currentModifiers | Modifier.SYNCHRONIZED);
}
} else {
CtClass ctClass = ctMethod.getDeclaringClass();
CtMethod replacement = CtNewMethod.copy(ctMethod, ctClass, null);
ctMethod.setName(ctMethod.getName() + "_nosynchronize");
replacement.setBody("synchronized(" + field + ") { return this." + ctMethod.getName() + "($$); }");
ctClass.addMethod(replacement);
}
}
@Patch
public void ignoreExceptions(CtMethod ctMethod, Map<String, String> attributes) throws CannotCompileException, NotFoundException {
String returnCode = attributes.get("code");
if (returnCode == null) {
returnCode = "return;";
}
String exceptionType = attributes.get("type");
if (exceptionType == null) {
exceptionType = "java.lang.Exception";
}
Log.info("Ignoring " + exceptionType + " in " + ctMethod + ", returning with " + returnCode);
ctMethod.addCatch("{ " + returnCode + '}', classRegistry.getClass(exceptionType));
}
@Patch (
requiredAttributes = "class"
)
public void addClass(CtClass ctClass, Map<String, String> attributes) throws IOException, CannotCompileException, NotFoundException {
classRegistry.add(ctClass, attributes.get("class"));
}
@Patch
public void replaceInstantiations(CtBehavior object, Map<String, String> attributes) {
// TODO: Implement this, change some newInitializer patches to use this
}
public void replaceInstantiationsImplementation(CtBehavior ctBehavior, final Map<String, List<String>> replacementClasses) throws CannotCompileException {
// TODO: Learn to use ASM, javassist isn't nice for some things. :(
final Map<Integer, String> newExprType = new HashMap<Integer, String>();
ctBehavior.instrument(new ExprEditor() {
NewExpr lastNewExpr;
int newPos = 0;
@Override
public void edit(NewExpr e) {
lastNewExpr = null;
newPos++;
if (replacementClasses.containsKey(e.getClassName())) {
lastNewExpr = e;
}
}
@Override
public void edit(FieldAccess e) {
NewExpr myLastNewExpr = lastNewExpr;
lastNewExpr = null;
if (myLastNewExpr != null) {
Log.fine('(' + myLastNewExpr.getSignature() + ") " + myLastNewExpr.getClassName() + " at " + myLastNewExpr.getFileName() + ':' + myLastNewExpr.getLineNumber() + ':' + newPos);
newExprType.put(newPos, classSignatureToName(e.getSignature()));
}
}
@Override
public void edit(MethodCall e) {
lastNewExpr = null;
}
@Override
public void edit(NewArray e) {
lastNewExpr = null;
}
@Override
public void edit(Cast e) {
lastNewExpr = null;
}
@Override
public void edit(Instanceof e) {
lastNewExpr = null;
}
@Override
public void edit(Handler e) {
lastNewExpr = null;
}
@Override
public void edit(ConstructorCall e) {
lastNewExpr = null;
}
});
ctBehavior.instrument(new ExprEditor() {
int newPos = 0;
@Override
public void edit(NewExpr e) throws CannotCompileException {
newPos++;
try {
Log.fine(e.getFileName() + ':' + e.getLineNumber() + ", pos: " + newPos);
if (newExprType.containsKey(newPos)) {
String replacementType = null, assignedType = newExprType.get(newPos);
Log.fine(assignedType + " at " + e.getFileName() + ':' + e.getLineNumber());
Class<?> assignTo = Class.forName(assignedType);
for (String replacementClass : replacementClasses.get(e.getClassName())) {
if (assignTo.isAssignableFrom(Class.forName(replacementClass))) {
replacementType = replacementClass;
break;
}
}
if (replacementType == null) {
return;
}
String block = "{$_=new " + replacementType + "($$);}";
Log.fine("Replaced with " + block + ", " + replacementType.length() + ':' + assignedType.length());
e.replace(block);
}
} catch (ClassNotFoundException el) {
Log.severe("Could not replace instantiation, class not found.", el);
}
}
});
}
private static String classSignatureToName(String signature) {
//noinspection HardcodedFileSeparator
return signature.substring(1, signature.length() - 1).replace("/", ".");
}
}