3 ms·
What is the advantage compared to established AOP libraries, such as AspectJ or BytecodeBuddy?
by ddimitrov 2y ago
What is the advantage compared to established AOP libraries, such as AspectJ or BytecodeBuddy?
- sgolestane 2y agoBoth of these use ASM under the hood
- gabizou 2y agoA primary advantage of Mixin is using Java as a DSL to apply various kinds of bytecode transformation with some examples here: - Changing a constant within a target method https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9edda29d7de58c036b49db3d0928/src/mixins/java/org/spongepowered/common/mixin/movementcheck/server/network/ServerGamePacketListenerImplMixin_MovementCheck.java#L42-L54 https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9ed... - Replacing a method call within a specific method https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9edda29d7de58c036b49db3d0928/src/mixins/java/org/spongepowered/common/mixin/tracker/server/level/ServerLevelMixin_Tracker.java#L175-L180 https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9ed... - Adding an interface and its implementation to the target class (in this case net.minecraft.world.entity.Entity will now implement org.spongepowered.api.entity.Entity and its methods) https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9edda29d7de58c036b49db3d0928/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/entity/EntityMixin_API.java#L81 https://github.com/SpongePowered/Sponge/blob/06ebd1d3479b9ed... There's a fair bit more that is possible that would otherwise require a fair bit more code wrangling with AspectJ or BytecodeBuddy to achieve the same effects.