| 16 | import org.quiltmc.chasm.lang.api.eval.Resolver; |
| 17 | |
| 18 | public class ClassNode extends MapNode { |
| 19 | private final ClassReader reader; |
| 20 | |
| 21 | public ClassNode(ClassReader reader, Context context, int index) { |
| 22 | super(new LazyMap<>(getStaticEntries(reader), |
| 23 | () -> getLazyEntries(reader, context, index))); |
| 24 | this.reader = reader; |
| 25 | |
| 26 | PathMetadata root = new PathMetadata(null, index); |
| 27 | PathInitializer.initialize(this, root); |
| 28 | } |
| 29 | |
| 30 | // NOTE: Ensure parity with ChasmClassVisitor |
| 31 | private static Map<String, Node> getStaticEntries(ClassReader reader) { |
| 32 | Map<String, Node> entries = new LinkedHashMap<>(); |
| 33 | |
| 34 | entries.put(NodeConstants.ACCESS, Ast.literal(reader.getAccess())); |
| 35 | entries.put(NodeConstants.NAME, Ast.literal(reader.getClassName())); |
| 36 | entries.put(NodeConstants.SUPER, Ast.nullableString(reader.getSuperName())); |
| 37 | entries.put(NodeConstants.INTERFACES, Ast.list((Object[]) reader.getInterfaces())); |
| 38 | |
| 39 | return entries; |
| 40 | } |
| 41 | |
| 42 | public Map<String, Node> getStaticEntries() { |
| 43 | return ((LazyMap<String, Node>) getEntries()).getStaticEntries(); |
| 44 | } |
| 45 | |
| 46 | public Map<String, Node> getLazyEntries() { |
| 47 | return ((LazyMap<String, Node>) getEntries()).getLazyEntries(); |
| 48 | } |
| 49 | |
| 50 | private static Map<String, Node> getLazyEntries(ClassReader reader, Context context, |
| 51 | int index) { |
| 52 | ChasmClassVisitor visitor = new ChasmClassVisitor(context); |
| 53 | reader.accept(visitor, 0); |
| 54 | Map<String, Node> entries = visitor.getClassNode().getEntries(); |
| 55 | |
| 56 | PathMetadata root = new PathMetadata(null, index); |
| 57 | for (Map.Entry<String, Node> entry : entries.entrySet()) { |
| 58 | PathMetadata path = new PathMetadata(root, entry.getKey()); |
| 59 | PathInitializer.initialize(entry.getValue(), path); |
| 60 | } |
| 61 | |
| 62 | return entries; |
| 63 | } |
| 64 | |
| 65 | public ClassReader getClassReader() { |
| 66 | return reader; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void resolve(Resolver resolver) { |
| 71 | // Class node can't contain references |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public Node evaluate(Evaluator evaluator) { |
nothing calls this directly
no outgoing calls
no test coverage detected