|
| 1 | +/* |
| 2 | + * Copyright (c) 2016, 2018, Player, asie |
| 3 | + * Copyright (c) 2025, FabricMC |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +package net.fabricmc.tinyremapper.extension.mixin.soft.annotation.injection; |
| 20 | + |
| 21 | +import java.util.Objects; |
| 22 | + |
| 23 | +import org.objectweb.asm.AnnotationVisitor; |
| 24 | + |
| 25 | +import net.fabricmc.tinyremapper.extension.mixin.common.data.AnnotationElement; |
| 26 | +import net.fabricmc.tinyremapper.extension.mixin.common.data.CommonData; |
| 27 | +import net.fabricmc.tinyremapper.extension.mixin.common.data.Constant; |
| 28 | +import net.fabricmc.tinyremapper.extension.mixin.soft.data.MemberInfo; |
| 29 | + |
| 30 | +public class DefinitionAnnotationVisitor extends AnnotationVisitor { |
| 31 | + private final CommonData data; |
| 32 | + |
| 33 | + public DefinitionAnnotationVisitor(CommonData data, AnnotationVisitor delegate) { |
| 34 | + super(Constant.ASM_VERSION, Objects.requireNonNull(delegate)); |
| 35 | + |
| 36 | + this.data = Objects.requireNonNull(data); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public AnnotationVisitor visitArray(String name) { |
| 41 | + AnnotationVisitor av = super.visitArray(name); |
| 42 | + switch (name) { |
| 43 | + case AnnotationElement.DEFINITION_METHOD: |
| 44 | + case AnnotationElement.DEFINITION_FIELD: |
| 45 | + return new MemberRemappingVisitor(data, av); |
| 46 | + } |
| 47 | + |
| 48 | + return av; |
| 49 | + } |
| 50 | + |
| 51 | + private static class MemberRemappingVisitor extends AnnotationVisitor { |
| 52 | + private final CommonData data; |
| 53 | + |
| 54 | + MemberRemappingVisitor(CommonData data, AnnotationVisitor delegate) { |
| 55 | + super(Constant.ASM_VERSION, Objects.requireNonNull(delegate)); |
| 56 | + |
| 57 | + this.data = Objects.requireNonNull(data); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public void visit(String name, Object value) { |
| 62 | + MemberInfo info = MemberInfo.parse(Objects.requireNonNull((String) value)); |
| 63 | + |
| 64 | + if (info != null) { |
| 65 | + value = new AtMemberMappable(data, info).result().toString(); |
| 66 | + } |
| 67 | + |
| 68 | + super.visit(name, value); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments