MCPcopy Create free account
hub / github.com/QuiltMC/chasm / ChasmProcessor

Class ChasmProcessor

chasm/src/main/java/org/quiltmc/chasm/api/ChasmProcessor.java:34–165  ·  view source on GitHub ↗

Transforms the added classes using the added Transformers.

Source from the content-addressed store, hash-verified

32 * Transforms the added classes using the added {@link Transformer}s.
33 */
34public class ChasmProcessor {
35 private static final Logger LOGGER = LoggerFactory.getLogger(ChasmProcessor.class);
36
37 private final Context context;
38
39 private final List<Transformer> transformers = new ArrayList<>();
40
41 private final List<ClassData> classes = new ArrayList<>();
42
43 /**
44 * Creates a new {@link ChasmProcessor} that uses the given {@link Context}.
45 *
46 * @param context A {@code Context} to supply parents of classes that are not being
47 * transformed.
48 */
49 public ChasmProcessor(Context context) {
50 this.context = context;
51 }
52
53 /**
54 * Adds the passed {@link Transformer} to this {@link ChasmProcessor}'s
55 * list of {@code Transformer}s.
56 *
57 * @param transformer A {@code Transformer} to add to this {@code ChasmProcessor}'s
58 * list of {@code Transformer}s to transform classes with.
59 */
60 public void addTransformer(Transformer transformer) {
61 transformers.add(transformer);
62 }
63
64 /**
65 * Adds the passed class data to this {@link ChasmProcessor}'s
66 * list of classes to transform.
67 *
68 * @param classBytes The bytes of the class.
69 * @param metadata The metadata associated with the class.
70 */
71 public void addClass(byte @NotNull [] classBytes, @NotNull Metadata metadata) {
72 this.classes.add(new ClassData(classBytes, metadata));
73 }
74
75 /**
76 * Transforms the {@link ClassData} passed via {@link #addClass} using
77 * the {@link Transformer Transformers} passed via {@link #addTransformer}.
78 *
79 * @return The transformed {@link ClassData}, wrapped in {@link ClassResult}.
80 */
81 public List<ClassResult> process() {
82 LOGGER.info("Processing {} classes...", classes.size());
83
84 ListNode classes = Ast.emptyList();
85 Context context = new ChasmContext(this.context, classes);
86 Map<String, ClassData> nameToData = new HashMap<>();
87 for (ClassData classData : this.classes) {
88 ClassReader classReader = new ClassReader(classData.getClassBytes());
89 ClassNode classNode = new ClassNode(classReader, context, classes.size());
90 classNode.getMetadata().putAll(classData.getMetadata());
91 classes.add(classNode);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected