-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
TransformerUtil.java
62 lines (58 loc) · 2.65 KB
/
TransformerUtil.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
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.turboasm;
import com.falsepattern.lib.internal.Tags;
import lombok.val;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
public class TransformerUtil {
private static final boolean DEBUG_VERBOSE_TRANSFORMERS = Boolean.parseBoolean(System.getProperty(Tags.MODID + ".debug.verboseTransformers", "false"));
private static final Logger LOG = LogManager.getLogger("ASM");
public static boolean executeTransformers(String transformedName, ClassNodeHandle handle, List<TurboClassTransformer> transformers) {
boolean modified = false;
for (val transformer: transformers) {
try {
if (transformer.shouldTransformClass(transformedName, handle)) {
if (DEBUG_VERBOSE_TRANSFORMERS)
LOG.trace("Transforming {} with {}, owner: {}", transformedName, transformer.name(), transformer.owner());
if (transformer.transformClass(transformedName, handle)) {
if (DEBUG_VERBOSE_TRANSFORMERS)
LOG.trace("Transformed.");
modified = true;
} else {
if (DEBUG_VERBOSE_TRANSFORMERS)
LOG.trace("No change.");
}
}
} catch (Exception e) {
LOG.error("Failed to transform class {} with {}, owner: {}", transformedName, transformer.name(), transformer.owner());
LOG.error("Exception stacktrace:", e);
}
}
if (DEBUG_VERBOSE_TRANSFORMERS && modified) {
LOG.trace("Transformed class {}", transformedName);
}
return modified;
}
}