mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-26 06:53:06 +00:00
refactor: port multipart mixin factory to Java
Retain Scala method-map ordering and generated class bytecode.
This commit is contained in:
1 parent
13ec2f5547
commit
1ad2b0f513
6 files changed
+358
-263
No files matched your search
@@ -1316,3 +1316,18 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
137 signature/compiler types have identical disassembly. Removing two private parent-traversal closures reduces
|
||||
the packaged inventory from 462 to 460 classes. `multipart/asm/MultipartMixinFactory.scala` is next, with the
|
||||
signature model and compiler algorithms still reserved for later targets.
|
||||
- Ported `MultipartMixinFactory` to a Java facade/companion pair, retaining all ten facade methods, the singleton,
|
||||
both public callback overrides and the two companion-only mangled helpers. No other production source needed an
|
||||
adjustment. The compiler, signature model and stack analyser remain unchanged.
|
||||
- Preserved the non-transient-field snapshot, existing `copyFrom` guard, generated delegate binding/removal,
|
||||
single-implementor gate, inherited-method override precedence, names, logging and registration order. The method
|
||||
collector retains Scala's immutable map and ordered inherited-entry buffer, preserving emitted method order;
|
||||
the public bridge helper still updates its supplied `ObjectRef` before emitting instructions. `onCompiled` keeps
|
||||
the side-safe `MultipartGenerator$.MODULE$` call.
|
||||
- No tests were added, per the current user instruction. Formatting/checkstyle/build passes all 276 existing JVM
|
||||
tests; Java 8 Forge passes all 116 tests, including pass-through delegation/copying and the frozen Scala consumer.
|
||||
Both Java 8 public surfaces match the saved `13ec2f5` reference. All 39 generated dump names and SHA-256 hashes
|
||||
match, and all 185 retained compiler/model/base-factory/generator types have identical disassembly. Only five
|
||||
private closures disappear, reducing the packaged inventory from 460 to 455 classes. The existing ledger row now
|
||||
describes the retained Java forwarders; no new divergence was added. `multipart/asm/ScalaSignature.scala` is next
|
||||
as the remaining parser/nested-model unit, with ASM compiler algorithm changes still deferred.
|
||||
@@ -75,7 +75,7 @@ Other retained `$class` bridges and `MODULE$` companions are not covered by this
|
||||
| `MicroMaterialRegistry` | Static `setupIDMap`, `calcMaxCuttingStrength` and `loadIcons` forwarders |
|
||||
| `PacketScheduler` / `TScheduledPacketPart` | Static `sendScheduled()` on the facade and `readMask(part, packet)` on the interface |
|
||||
| `TileMultipart` | No-op `renderStatic`, `renderDynamic` and `randomDisplayTick` hooks for dispatching generated overrides through a stable superclass |
|
||||
| `MultipartMixinFactory` | Four additional Scala-generated static forwarders: `onCompiled`, `autoCompleteJavaTrait` and the two mangled `ASMMixinFactory` parent helpers. Java must expose the base members at their original public JVM access, so Scala now forwards them too; existing facade entries are unchanged. |
|
||||
| `MultipartMixinFactory` | Four additional static forwarders: `onCompiled`, `autoCompleteJavaTrait` and the two mangled `ASMMixinFactory` parent helpers. Scala emitted them when the base became Java with its original public JVM access; the Java facade retains them. Existing facade entries are unchanged. |
|
||||
|
||||
Previously abstract JVM interface methods now have Java defaults, allowing inheritance without Scala forwarders:
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ what breaks, and what is left. The other documents hold the reasoning.
|
||||
| `JAVA_MIGRATION_MANUAL_CHECKS.md` | What no automated test can cover, and must be checked by hand in a client |
|
||||
| `JAVA_MIGRATION_PROFILE.md` | The focused baseline, first measured result, findings, and exact rerun command |
|
||||
|
||||
Branch: `algent/java`. Base: `master`. 162 commits including the API-cleanup plan, divergence-log cleanup and ports
|
||||
through `ASMMixinFactory`.
|
||||
Branch: `algent/java`. Base: `master`. 163 commits including the API-cleanup plan, divergence-log cleanup and ports
|
||||
through `MultipartMixinFactory`.
|
||||
|
||||
## The one rule that matters
|
||||
|
||||
@@ -278,7 +278,7 @@ across the port. It is also where the two shim constraints in the gotchas list w
|
||||
`rayTraceAll`'s index production is now characterized, closing the gap the read-path cleanup left: the index written
|
||||
into `ExtendedMOP.data` is what `reduceMOP` hands back to every click, activate, harvest and pick block.
|
||||
|
||||
203 Java files, 10 Scala files, 2,170 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
205 Java files, 9 Scala files, 1,933 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -586,17 +586,26 @@ closure disappears, reducing the packaged inventory from 463 to 462 classes. Exi
|
||||
`ASMMixinFactory` is now Java. Its Scala `Seq` boundaries, synchronized construction, copied BitSet cache keys,
|
||||
generated-name sequence, registration order and both trait-registration paths remain. The callbacks declared
|
||||
`protected` in Scala are public in the reference bytecode and remain public, as do both mangled parent helpers.
|
||||
All existing callable surfaces match the reference; the retained Scala `MultipartMixinFactory` emits four additional
|
||||
All existing callable surfaces match the reference; the then-Scala `MultipartMixinFactory` emitted four additional
|
||||
static forwarders, recorded in the ledger. Its companion and five closures, both generator companions and all 137
|
||||
signature/compiler types have identical disassembly. All 39 generated dump names and contents match, and the existing
|
||||
276 JVM / 116 Forge tests pass unchanged. Removing two private parent-traversal closures reduces the packaged
|
||||
inventory from 462 to 460 classes. No tests were added.
|
||||
|
||||
**Next: `multipart/asm/MultipartMixinFactory.scala`.** Port this facade/companion pair before the larger nested
|
||||
signature model. Preserve the current public surface (including the four new static forwarders), constructor,
|
||||
side-safe `onCompiled` callback, non-transient-field `copyFrom` generation and pass-through bytecode. Keep method
|
||||
collection/override order, generated names, missing-interface logging and registration order; compare generated dumps
|
||||
against a saved reference. Leave the signature model and compiler algorithms unchanged.
|
||||
`MultipartMixinFactory` is now a Java facade/companion pair. Both public surfaces remain exact, including the four
|
||||
forwarders added by the previous port and the two companion-only mangled helpers. Non-transient-field copying,
|
||||
existing `copyFrom` detection, inherited-interface precedence and pass-through instruction order remain unchanged.
|
||||
Scala's immutable map still determines method traversal order, and `onCompiled` retains the side-safe generator
|
||||
companion call. All 39 generated dump names and contents match the reference; all 185 retained compiler, signature,
|
||||
stack-analyser, base-factory and generator types have identical disassembly. The existing 276 JVM / 116 Forge tests
|
||||
pass unchanged. Removing five private closures reduces the packaged inventory from 460 to 455 classes. No tests were
|
||||
added, and no new compatibility divergence was introduced.
|
||||
|
||||
**Next: `multipart/asm/ScalaSignature.scala`.** The remaining parser and its nested model form a larger compatibility
|
||||
unit. Preserve nested binary names, case-class/companion surfaces, outer-instance bindings, flags and literal
|
||||
decoding, Scala collections and annotation parsing. Keep ProjectRed's external Scala-trait path working; compare
|
||||
generated dumps against a saved reference. Leave `StackAnalyser` and the ASM compiler algorithms unchanged apart
|
||||
from necessary source-call adjustments.
|
||||
The remaining generated microblock traits still need the Phase 7 abstract-Java-mixin and side-only-member support
|
||||
before their Java mixin inputs are safe; do not bypass those prerequisites by flattening their inheritance.
|
||||
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
package codechicken.multipart.asm;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.ACC_INTERFACE;
|
||||
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
|
||||
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
|
||||
import static org.objectweb.asm.Opcodes.ACC_SUPER;
|
||||
import static org.objectweb.asm.Opcodes.ACC_TRANSIENT;
|
||||
import static org.objectweb.asm.Opcodes.ACONST_NULL;
|
||||
import static org.objectweb.asm.Opcodes.ALOAD;
|
||||
import static org.objectweb.asm.Opcodes.CHECKCAST;
|
||||
import static org.objectweb.asm.Opcodes.F_SAME;
|
||||
import static org.objectweb.asm.Opcodes.GETFIELD;
|
||||
import static org.objectweb.asm.Opcodes.ICONST_0;
|
||||
import static org.objectweb.asm.Opcodes.IFEQ;
|
||||
import static org.objectweb.asm.Opcodes.IFNULL;
|
||||
import static org.objectweb.asm.Opcodes.IF_ACMPNE;
|
||||
import static org.objectweb.asm.Opcodes.ILOAD;
|
||||
import static org.objectweb.asm.Opcodes.INSTANCEOF;
|
||||
import static org.objectweb.asm.Opcodes.INVOKEINTERFACE;
|
||||
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
|
||||
import static org.objectweb.asm.Opcodes.IRETURN;
|
||||
import static org.objectweb.asm.Opcodes.PUTFIELD;
|
||||
import static org.objectweb.asm.Opcodes.RETURN;
|
||||
import static org.objectweb.asm.Opcodes.V1_6;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.lib.asm.CC_ClassWriter;
|
||||
import codechicken.lib.asm.ObfMapping;
|
||||
import codechicken.multipart.MultipartGenerator$;
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import scala.Predef$;
|
||||
import scala.Tuple2;
|
||||
import scala.collection.Iterator;
|
||||
import scala.collection.immutable.Map;
|
||||
import scala.collection.immutable.Map$;
|
||||
import scala.collection.mutable.ArrayBuffer;
|
||||
import scala.runtime.ObjectRef;
|
||||
|
||||
public final class MultipartMixinFactory$ extends ASMMixinFactory<TileMultipart> {
|
||||
|
||||
public static final MultipartMixinFactory$ MODULE$ = new MultipartMixinFactory$();
|
||||
|
||||
private MultipartMixinFactory$() {
|
||||
super(TileMultipart.class, Predef$.MODULE$.wrapRefArray(new Class<?>[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoCompleteJavaTrait(ClassNode cnode) {
|
||||
List<FieldNode> copyFields = new ArrayList<>();
|
||||
for (FieldNode field : cnode.fields) {
|
||||
if ((field.access & ACC_TRANSIENT) == 0) copyFields.add(field);
|
||||
}
|
||||
if (copyFields.isEmpty() || ASMHelper
|
||||
.findMethod(new ObfMapping(cnode.name, "copyFrom", "(Lcodechicken/multipart/TileMultipart;)V"), cnode)
|
||||
!= null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MethodVisitor mv = cnode
|
||||
.visitMethod(ACC_PUBLIC, "copyFrom", "(Lcodechicken/multipart/TileMultipart;)V", null, null);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"copyFrom",
|
||||
"(Lcodechicken/multipart/TileMultipart;)V");
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(INSTANCEOF, cnode.name);
|
||||
Label end = new Label();
|
||||
mv.visitJumpInsn(IFEQ, end);
|
||||
|
||||
for (FieldNode field : copyFields) {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitFieldInsn(GETFIELD, cnode.name, field.name, field.desc);
|
||||
mv.visitFieldInsn(PUTFIELD, cnode.name, field.name, field.desc);
|
||||
}
|
||||
|
||||
mv.visitLabel(end);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
}
|
||||
|
||||
public String generatePassThroughTrait(String s_interface) {
|
||||
String iname = ASMImplicits.nodeName(s_interface);
|
||||
String simpleName = iname.substring(iname.lastIndexOf('/') + 1);
|
||||
if (simpleName.startsWith("I")) simpleName = simpleName.substring(1);
|
||||
String tname = "T" + simpleName + "$$PassThrough";
|
||||
String vname = "impl";
|
||||
String idesc = "L" + iname + ";";
|
||||
|
||||
ClassNode inode = ASMMixinCompiler$.MODULE$.classNode(s_interface);
|
||||
if (inode == null) {
|
||||
ASMHelper.logger.error("Unable to generate pass through trait for: " + s_interface + " class not found.");
|
||||
return null;
|
||||
}
|
||||
if ((inode.access & ACC_INTERFACE) == 0) {
|
||||
throw new IllegalArgumentException(s_interface + " is not an interface.");
|
||||
}
|
||||
|
||||
CC_ClassWriter cw = new CC_ClassWriter(0);
|
||||
cw.visit(
|
||||
V1_6,
|
||||
ACC_PUBLIC | ACC_SUPER,
|
||||
tname,
|
||||
null,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
new String[] { iname });
|
||||
|
||||
FieldVisitor fv = cw.visitField(ACC_PRIVATE, vname, idesc, null, null);
|
||||
fv.visitEnd();
|
||||
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, "codechicken/multipart/TileMultipart", "<init>", "()V");
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
mv.visitEnd();
|
||||
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "bindPart", "(Lcodechicken/multipart/TMultiPart;)V", null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"bindPart",
|
||||
"(Lcodechicken/multipart/TMultiPart;)V");
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(INSTANCEOF, iname);
|
||||
Label bindEnd = new Label();
|
||||
mv.visitJumpInsn(IFEQ, bindEnd);
|
||||
mv.visitLabel(new Label());
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(CHECKCAST, iname);
|
||||
mv.visitFieldInsn(PUTFIELD, tname, vname, idesc);
|
||||
mv.visitLabel(bindEnd);
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "partRemoved", "(Lcodechicken/multipart/TMultiPart;I)V", null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ILOAD, 2);
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"partRemoved",
|
||||
"(Lcodechicken/multipart/TMultiPart;I)V");
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, tname, vname, idesc);
|
||||
Label removeEnd = new Label();
|
||||
mv.visitJumpInsn(IF_ACMPNE, removeEnd);
|
||||
mv.visitLabel(new Label());
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitInsn(ACONST_NULL);
|
||||
mv.visitFieldInsn(PUTFIELD, tname, vname, idesc);
|
||||
mv.visitLabel(removeEnd);
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "canAddPart", "(Lcodechicken/multipart/TMultiPart;)Z", null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, tname, vname, idesc);
|
||||
Label canAdd = new Label();
|
||||
mv.visitJumpInsn(IFNULL, canAdd);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitTypeInsn(INSTANCEOF, iname);
|
||||
mv.visitJumpInsn(IFEQ, canAdd);
|
||||
mv.visitLabel(new Label());
|
||||
mv.visitInsn(ICONST_0);
|
||||
mv.visitInsn(IRETURN);
|
||||
mv.visitLabel(canAdd);
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"canAddPart",
|
||||
"(Lcodechicken/multipart/TMultiPart;)Z");
|
||||
mv.visitInsn(IRETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
|
||||
ObjectRef<MethodVisitor> visitor = ObjectRef.create(mv);
|
||||
Iterator<?> methods = codechicken$multipart$asm$MultipartMixinFactory$$methods$1(inode).values().iterator();
|
||||
while (methods.hasNext()) {
|
||||
codechicken$multipart$asm$MultipartMixinFactory$$generatePassThroughMethod$1(
|
||||
(MethodNode) methods.next(),
|
||||
iname,
|
||||
tname,
|
||||
vname,
|
||||
idesc,
|
||||
cw,
|
||||
visitor);
|
||||
}
|
||||
|
||||
cw.visitEnd();
|
||||
ASMMixinCompiler$.MODULE$.internalDefine(tname, cw.toByteArray());
|
||||
registerTrait(tname);
|
||||
return tname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompiled(Class<? extends TileMultipart> clazz, BitSet traitSet) {
|
||||
MultipartGenerator$.MODULE$.registerTileClass(clazz, traitSet);
|
||||
}
|
||||
|
||||
// Keep Scala's map representation, inherited override precedence and bytecode emission order.
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public final Map codechicken$multipart$asm$MultipartMixinFactory$$methods$1(ClassNode cnode) {
|
||||
Map<String, MethodNode> methods = Map$.MODULE$.empty();
|
||||
for (MethodNode method : cnode.methods) {
|
||||
methods = methods.$plus(new Tuple2<>(method.name + method.desc, method));
|
||||
}
|
||||
if (cnode.interfaces == null) return methods;
|
||||
|
||||
ArrayBuffer<Tuple2<String, MethodNode>> inherited = new ArrayBuffer<>();
|
||||
for (String name : cnode.interfaces) {
|
||||
inherited.$plus$plus$eq(
|
||||
MODULE$.codechicken$multipart$asm$MultipartMixinFactory$$methods$1(
|
||||
ASMMixinCompiler$.MODULE$.classNode(name)));
|
||||
}
|
||||
return methods.$plus$plus(inherited);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public final void codechicken$multipart$asm$MultipartMixinFactory$$generatePassThroughMethod$1(MethodNode method,
|
||||
String iname, String tname, String vname, String idesc, CC_ClassWriter cw, ObjectRef mv) {
|
||||
mv.elem = cw.visitMethod(
|
||||
ACC_PUBLIC,
|
||||
method.name,
|
||||
method.desc,
|
||||
method.signature,
|
||||
method.exceptions.toArray(new String[0]));
|
||||
((MethodVisitor) mv.elem).visitVarInsn(ALOAD, 0);
|
||||
((MethodVisitor) mv.elem).visitFieldInsn(GETFIELD, tname, vname, idesc);
|
||||
ASMMixinCompiler$.MODULE$.finishBridgeCall(
|
||||
(MethodVisitor) mv.elem,
|
||||
method.desc,
|
||||
INVOKEINTERFACE,
|
||||
iname,
|
||||
method.name,
|
||||
method.desc);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package codechicken.multipart.asm;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import codechicken.multipart.TileMultipart;
|
||||
import codechicken.multipart.asm.ASMMixinCompiler.ClassInfo;
|
||||
import scala.collection.Seq;
|
||||
|
||||
public final class MultipartMixinFactory {
|
||||
|
||||
private MultipartMixinFactory() {}
|
||||
|
||||
public static Class<TileMultipart> baseType() {
|
||||
return MultipartMixinFactory$.MODULE$.baseType();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Object construct(BitSet traitSet, Seq args) {
|
||||
return MultipartMixinFactory$.MODULE$.construct(traitSet, args);
|
||||
}
|
||||
|
||||
public static int getId(String trait) {
|
||||
return MultipartMixinFactory$.MODULE$.getId(trait);
|
||||
}
|
||||
|
||||
public static int registerTrait(Class<?> trait) {
|
||||
return MultipartMixinFactory$.MODULE$.registerTrait(trait);
|
||||
}
|
||||
|
||||
public static int registerTrait(String trait) {
|
||||
return MultipartMixinFactory$.MODULE$.registerTrait(trait);
|
||||
}
|
||||
|
||||
public static void onCompiled(Class<? extends TileMultipart> clazz, BitSet traitSet) {
|
||||
MultipartMixinFactory$.MODULE$.onCompiled(clazz, traitSet);
|
||||
}
|
||||
|
||||
public static void autoCompleteJavaTrait(ClassNode cnode) {
|
||||
MultipartMixinFactory$.MODULE$.autoCompleteJavaTrait(cnode);
|
||||
}
|
||||
|
||||
public static String generatePassThroughTrait(String s_interface) {
|
||||
return MultipartMixinFactory$.MODULE$.generatePassThroughTrait(s_interface);
|
||||
}
|
||||
|
||||
public static ClassInfo codechicken$multipart$asm$ASMMixinFactory$$concreteParent$1(ClassInfo info) {
|
||||
return MultipartMixinFactory$.MODULE$.codechicken$multipart$asm$ASMMixinFactory$$concreteParent$1(info);
|
||||
}
|
||||
|
||||
public static boolean codechicken$multipart$asm$ASMMixinFactory$$checkParent$1(ClassInfo info, String parentName) {
|
||||
return MultipartMixinFactory$.MODULE$
|
||||
.codechicken$multipart$asm$ASMMixinFactory$$checkParent$1(info, parentName);
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
package codechicken.multipart.asm
|
||||
|
||||
import ASMMixinCompiler._
|
||||
import codechicken.lib.asm.ASMHelper._
|
||||
import codechicken.lib.asm.{ObfMapping, CC_ClassWriter}
|
||||
import org.objectweb.asm.{Label, FieldVisitor, MethodVisitor}
|
||||
import org.objectweb.asm.Opcodes._
|
||||
import org.objectweb.asm.tree.{MethodNode, ClassNode}
|
||||
import codechicken.multipart.{MultipartGenerator$, TileMultipart}
|
||||
import java.util.BitSet
|
||||
import ASMImplicits._
|
||||
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
object MultipartMixinFactory
|
||||
extends ASMMixinFactory[TileMultipart](
|
||||
classOf[TileMultipart],
|
||||
scala.Predef.wrapRefArray(new Array[Class[_]](0))
|
||||
) {
|
||||
override def autoCompleteJavaTrait(cnode: ClassNode) {
|
||||
val copyFields = cnode.fields.filter(f => (f.access & ACC_TRANSIENT) == 0)
|
||||
if (
|
||||
!copyFields.isEmpty && findMethod(
|
||||
new ObfMapping(
|
||||
cnode.name,
|
||||
"copyFrom",
|
||||
"(Lcodechicken/multipart/TileMultipart;)V"
|
||||
),
|
||||
cnode
|
||||
) == null
|
||||
) {
|
||||
val mv = cnode.visitMethod(
|
||||
ACC_PUBLIC,
|
||||
"copyFrom",
|
||||
"(Lcodechicken/multipart/TileMultipart;)V",
|
||||
null,
|
||||
null
|
||||
)
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"copyFrom",
|
||||
"(Lcodechicken/multipart/TileMultipart;)V"
|
||||
)
|
||||
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitTypeInsn(INSTANCEOF, cnode.name)
|
||||
val end = new Label()
|
||||
mv.visitJumpInsn(IFEQ, end)
|
||||
|
||||
copyFields.foreach { f =>
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitFieldInsn(GETFIELD, cnode.name, f.name, f.desc)
|
||||
mv.visitFieldInsn(PUTFIELD, cnode.name, f.name, f.desc)
|
||||
}
|
||||
|
||||
mv.visitLabel(end)
|
||||
mv.visitInsn(RETURN)
|
||||
mv.visitMaxs(2, 2)
|
||||
}
|
||||
}
|
||||
|
||||
def generatePassThroughTrait(s_interface: String): String = {
|
||||
val iname = nodeName(s_interface)
|
||||
val tname = {
|
||||
var simpleName = iname.substring(iname.lastIndexOf('/') + 1)
|
||||
if (simpleName.startsWith("I")) simpleName = simpleName.substring(1)
|
||||
"T" + simpleName + "$$PassThrough"
|
||||
}
|
||||
val vname = "impl"
|
||||
val idesc = "L" + iname + ";"
|
||||
|
||||
val inode = classNode(s_interface)
|
||||
if (inode == null) {
|
||||
logger.error(
|
||||
"Unable to generate pass through trait for: " + s_interface + " class not found."
|
||||
)
|
||||
return null
|
||||
}
|
||||
if ((inode.access & ACC_INTERFACE) == 0)
|
||||
throw new IllegalArgumentException(s_interface + " is not an interface.")
|
||||
|
||||
val cw = new CC_ClassWriter(0)
|
||||
var mv: MethodVisitor = null
|
||||
var fv: FieldVisitor = null
|
||||
|
||||
cw.visit(
|
||||
V1_6,
|
||||
ACC_PUBLIC | ACC_SUPER,
|
||||
tname,
|
||||
null,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
Array(iname)
|
||||
)
|
||||
|
||||
{
|
||||
fv = cw.visitField(ACC_PRIVATE, vname, idesc, null, null)
|
||||
fv.visitEnd()
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null)
|
||||
mv.visitCode()
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"<init>",
|
||||
"()V"
|
||||
)
|
||||
mv.visitInsn(RETURN)
|
||||
mv.visitMaxs(1, 1)
|
||||
mv.visitEnd()
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(
|
||||
ACC_PUBLIC,
|
||||
"bindPart",
|
||||
"(Lcodechicken/multipart/TMultiPart;)V",
|
||||
null,
|
||||
null
|
||||
)
|
||||
mv.visitCode()
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"bindPart",
|
||||
"(Lcodechicken/multipart/TMultiPart;)V"
|
||||
)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitTypeInsn(INSTANCEOF, iname)
|
||||
val l2 = new Label()
|
||||
mv.visitJumpInsn(IFEQ, l2)
|
||||
val l3 = new Label()
|
||||
mv.visitLabel(l3)
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitTypeInsn(CHECKCAST, iname)
|
||||
mv.visitFieldInsn(PUTFIELD, tname, vname, idesc)
|
||||
mv.visitLabel(l2)
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null)
|
||||
mv.visitInsn(RETURN)
|
||||
mv.visitMaxs(2, 2)
|
||||
mv.visitEnd()
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(
|
||||
ACC_PUBLIC,
|
||||
"partRemoved",
|
||||
"(Lcodechicken/multipart/TMultiPart;I)V",
|
||||
null,
|
||||
null
|
||||
)
|
||||
mv.visitCode()
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitVarInsn(ILOAD, 2)
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"partRemoved",
|
||||
"(Lcodechicken/multipart/TMultiPart;I)V"
|
||||
)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitFieldInsn(GETFIELD, tname, vname, idesc)
|
||||
val l2 = new Label()
|
||||
mv.visitJumpInsn(IF_ACMPNE, l2)
|
||||
val l3 = new Label()
|
||||
mv.visitLabel(l3)
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitInsn(ACONST_NULL)
|
||||
mv.visitFieldInsn(PUTFIELD, tname, vname, idesc)
|
||||
mv.visitLabel(l2)
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null)
|
||||
mv.visitInsn(RETURN)
|
||||
mv.visitMaxs(3, 3)
|
||||
mv.visitEnd()
|
||||
}
|
||||
{
|
||||
mv = cw.visitMethod(
|
||||
ACC_PUBLIC,
|
||||
"canAddPart",
|
||||
"(Lcodechicken/multipart/TMultiPart;)Z",
|
||||
null,
|
||||
null
|
||||
)
|
||||
mv.visitCode()
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitFieldInsn(GETFIELD, tname, vname, idesc)
|
||||
val l1 = new Label()
|
||||
mv.visitJumpInsn(IFNULL, l1)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitTypeInsn(INSTANCEOF, iname)
|
||||
mv.visitJumpInsn(IFEQ, l1)
|
||||
val l2 = new Label()
|
||||
mv.visitLabel(l2)
|
||||
mv.visitInsn(ICONST_0)
|
||||
mv.visitInsn(IRETURN)
|
||||
mv.visitLabel(l1)
|
||||
mv.visitFrame(F_SAME, 0, null, 0, null)
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitVarInsn(ALOAD, 1)
|
||||
mv.visitMethodInsn(
|
||||
INVOKESPECIAL,
|
||||
"codechicken/multipart/TileMultipart",
|
||||
"canAddPart",
|
||||
"(Lcodechicken/multipart/TMultiPart;)Z"
|
||||
)
|
||||
mv.visitInsn(IRETURN)
|
||||
mv.visitMaxs(2, 2)
|
||||
mv.visitEnd()
|
||||
}
|
||||
|
||||
def methods(cnode: ClassNode): Map[String, MethodNode] = {
|
||||
val m = cnode.methods.map(m => (m.name + m.desc, m)).toMap
|
||||
if (cnode.interfaces != null)
|
||||
m ++ cnode.interfaces.flatMap(i => methods(classNode(i)))
|
||||
else
|
||||
m
|
||||
}
|
||||
|
||||
def generatePassThroughMethod(m: MethodNode) {
|
||||
mv = cw.visitMethod(
|
||||
ACC_PUBLIC,
|
||||
m.name,
|
||||
m.desc,
|
||||
m.signature,
|
||||
Array(m.exceptions: _*)
|
||||
)
|
||||
mv.visitVarInsn(ALOAD, 0)
|
||||
mv.visitFieldInsn(GETFIELD, tname, vname, idesc)
|
||||
finishBridgeCall(mv, m.desc, INVOKEINTERFACE, iname, m.name, m.desc)
|
||||
}
|
||||
|
||||
methods(inode).values.foreach(generatePassThroughMethod)
|
||||
|
||||
cw.visitEnd()
|
||||
internalDefine(tname, cw.toByteArray)
|
||||
registerTrait(tname)
|
||||
return tname
|
||||
}
|
||||
|
||||
override def onCompiled(
|
||||
clazz: Class[_ <: TileMultipart],
|
||||
traitSet: BitSet
|
||||
) =
|
||||
MultipartGenerator$.MODULE$.registerTileClass(clazz, traitSet)
|
||||
}
|
||||
Reference in new issue
Block a user