Skip to content

Commit d16a1ac

Browse files
committed
Merge remote-tracking branch 'upstream/master' into next
# Conflicts: # build.gradle
2 parents a70d7e5 + bbb4677 commit d16a1ac

11 files changed

+116
-50
lines changed

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
sourceCompatibility = JavaVersion.VERSION_1_8
1010
targetCompatibility = JavaVersion.VERSION_1_8
1111

12-
version = '1.9.' + (System.getenv("GITHUB_RUN_NUMBER") ?: "9999")
12+
version = '1.10.' + (System.getenv("GITHUB_RUN_NUMBER") ?: "9999")
1313

1414
def ENV = System.getenv()
1515

@@ -21,10 +21,10 @@ repositories {
2121
}
2222

2323
dependencies {
24-
api 'org.ow2.asm:asm:9.3'
25-
api 'org.ow2.asm:asm-commons:9.3'
26-
implementation 'org.ow2.asm:asm-tree:9.3'
27-
implementation 'org.ow2.asm:asm-util:9.3'
24+
api 'org.ow2.asm:asm:9.6'
25+
api 'org.ow2.asm:asm-commons:9.6'
26+
implementation 'org.ow2.asm:asm-tree:9.6'
27+
implementation 'org.ow2.asm:asm-util:9.6'
2828

2929
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
3030
}

src/main/java/net/fabricmc/tinyremapper/TinyRemapper.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ public interface Extension {
291291

292292
public interface AnalyzeVisitorProvider {
293293
ClassVisitor insertAnalyzeVisitor(int mrjVersion, String className, ClassVisitor next);
294+
295+
default ClassVisitor insertAnalyzeVisitor(int mrjVersion, String className, ClassVisitor next, /* @Nullable */ InputTag[] inputTags) {
296+
return insertAnalyzeVisitor(mrjVersion, className, next);
297+
}
294298
}
295299

296300
public interface StateProcessor {
@@ -299,6 +303,10 @@ public interface StateProcessor {
299303

300304
public interface ApplyVisitorProvider {
301305
ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next);
306+
307+
default ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next, /* @Nullable */ InputTag[] inputTags) {
308+
return insertApplyVisitor(cls, next);
309+
}
302310
}
303311

304312
private TinyRemapper(Set<IMappingProvider> mappingProviders, boolean ignoreFieldDesc,
@@ -767,7 +775,7 @@ public FieldVisitor visitField(int access, String name, String desc, String sign
767775
};
768776

769777
for (int i = analyzeVisitors.size() - 1; i >= 0; i--) {
770-
cv = analyzeVisitors.get(i).insertAnalyzeVisitor(mrjVersion, name, cv);
778+
cv = analyzeVisitors.get(i).insertAnalyzeVisitor(mrjVersion, name, cv, tags);
771779
}
772780

773781
reader.accept(cv, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE);
@@ -1354,14 +1362,14 @@ private byte[] apply(final ClassInstance cls) {
13541362
}
13551363

13561364
for (int i = postApplyVisitors.size() - 1; i >= 0; i--) {
1357-
visitor = postApplyVisitors.get(i).insertApplyVisitor(cls, visitor);
1365+
visitor = postApplyVisitors.get(i).insertApplyVisitor(cls, visitor, cls.getInputTags());
13581366
}
13591367

13601368
visitor = new AsmClassRemapper(visitor, cls.getContext().remapper, rebuildSourceFilenames,
13611369
checkPackageAccess, skipLocalMapping, renameInvalidLocals, invalidLvNamePattern, inferNameFromSameLvIndex);
13621370

13631371
for (int i = preApplyVisitors.size() - 1; i >= 0; i--) {
1364-
visitor = preApplyVisitors.get(i).insertApplyVisitor(cls, visitor);
1372+
visitor = preApplyVisitors.get(i).insertApplyVisitor(cls, visitor, cls.getInputTags());
13651373
}
13661374

13671375
reader.accept(visitor, flags);

src/main/java/net/fabricmc/tinyremapper/extension/mixin/MixinExtension.java

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2016, 2018, Player, asie
3-
* Copyright (c) 2021, FabricMC
3+
* Copyright (c) 2021, 2023, FabricMC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -18,16 +18,19 @@
1818

1919
package net.fabricmc.tinyremapper.extension.mixin;
2020

21-
import java.util.ArrayList;
21+
import java.util.Collection;
22+
import java.util.Collections;
2223
import java.util.EnumSet;
23-
import java.util.HashMap;
24-
import java.util.List;
2524
import java.util.Map;
2625
import java.util.Set;
26+
import java.util.concurrent.ConcurrentHashMap;
27+
import java.util.concurrent.ConcurrentLinkedQueue;
2728
import java.util.function.Consumer;
29+
import java.util.function.Predicate;
2830

2931
import org.objectweb.asm.ClassVisitor;
3032

33+
import net.fabricmc.tinyremapper.InputTag;
3134
import net.fabricmc.tinyremapper.TinyRemapper;
3235
import net.fabricmc.tinyremapper.TinyRemapper.Builder;
3336
import net.fabricmc.tinyremapper.api.TrClass;
@@ -40,11 +43,19 @@
4043

4144
/**
4245
* A extension for remapping mixin annotation.
46+
*
47+
* <h2>Input filtering</h2>
48+
*
49+
* <p>The mixin extension can be applied to specific input tags by providing an input tag filter in the constructor.
50+
* An input with nonnull input tags is only processed if it has a tag matching the filter.
51+
*
52+
* <p>If the filter is null, all inputs will be processed.
4353
*/
4454
public class MixinExtension implements TinyRemapper.Extension {
4555
private final Logger logger;
46-
private final Map<Integer, List<Consumer<CommonData>>> tasks;
56+
private final Map<Integer, Collection<Consumer<CommonData>>> tasks;
4757
private final Set<AnnotationTarget> targets;
58+
private final /* @Nullable */ Predicate<InputTag> inputTagFilter;
4859

4960
public enum AnnotationTarget {
5061
/**
@@ -74,35 +85,36 @@ public MixinExtension(Set<AnnotationTarget> targets) {
7485
this(targets, Level.WARN);
7586
}
7687

88+
public MixinExtension(/* @Nullable */ Predicate<InputTag> inputTagFilter) {
89+
this(EnumSet.allOf(AnnotationTarget.class), Level.WARN, inputTagFilter);
90+
}
91+
7792
public MixinExtension(Set<AnnotationTarget> targets, Logger.Level logLevel) {
93+
this(targets, logLevel, null);
94+
}
95+
96+
public MixinExtension(Set<AnnotationTarget> targets, Logger.Level logLevel, /* @Nullable */ Predicate<InputTag> inputTagFilter) {
7897
this.logger = new Logger(logLevel);
79-
this.tasks = new HashMap<>();
98+
this.tasks = new ConcurrentHashMap<>();
8099
this.targets = targets;
100+
this.inputTagFilter = inputTagFilter;
81101
}
82102

83103
@Override
84104
public void attach(Builder builder) {
85105
if (targets.contains(AnnotationTarget.HARD)) {
86-
builder.extraAnalyzeVisitor(this::analyzeVisitor).extraStateProcessor(this::stateProcessor);
106+
builder.extraAnalyzeVisitor(new AnalyzeVisitorProvider()).extraStateProcessor(this::stateProcessor);
87107
}
88108

89109
if (targets.contains(AnnotationTarget.SOFT)) {
90-
builder.extraPreApplyVisitor(this::preApplyVisitor);
110+
builder.extraPreApplyVisitor(new PreApplyVisitorProvider());
91111
}
92112
}
93113

94-
/**
95-
* Hard-target: Shadow, Overwrite, Accessor, Invoker, Implements.
96-
*/
97-
private ClassVisitor analyzeVisitor(int mrjVersion, String className, ClassVisitor next) {
98-
tasks.putIfAbsent(mrjVersion, new ArrayList<>());
99-
return new HardTargetMixinClassVisitor(tasks.get(mrjVersion), next);
100-
}
101-
102114
private void stateProcessor(TrEnvironment environment) {
103115
CommonData data = new CommonData(environment, logger);
104116

105-
for (Consumer<CommonData> task : tasks.get(environment.getMrjVersion())) {
117+
for (Consumer<CommonData> task : tasks.getOrDefault(environment.getMrjVersion(), Collections.emptyList())) {
106118
try {
107119
task.accept(data);
108120
} catch (RuntimeException e) {
@@ -111,11 +123,54 @@ private void stateProcessor(TrEnvironment environment) {
111123
}
112124
}
113125

126+
/**
127+
* Hard-target: Shadow, Overwrite, Accessor, Invoker, Implements.
128+
*/
129+
private final class AnalyzeVisitorProvider implements TinyRemapper.AnalyzeVisitorProvider {
130+
@Override
131+
public ClassVisitor insertAnalyzeVisitor(int mrjVersion, String className, ClassVisitor next) {
132+
return new HardTargetMixinClassVisitor(tasks.computeIfAbsent(mrjVersion, k -> new ConcurrentLinkedQueue<>()), next);
133+
}
134+
135+
@Override
136+
public ClassVisitor insertAnalyzeVisitor(int mrjVersion, String className, ClassVisitor next, InputTag[] inputTags) {
137+
if (inputTagFilter == null || inputTags == null) {
138+
return insertAnalyzeVisitor(mrjVersion, className, next);
139+
} else {
140+
for (InputTag tag : inputTags) {
141+
if (inputTagFilter.test(tag)) {
142+
return insertAnalyzeVisitor(mrjVersion, className, next);
143+
}
144+
}
145+
146+
return next;
147+
}
148+
}
149+
}
150+
114151
/**
115152
* Soft-target: Mixin, Invoker, Accessor, Inject, ModifyArg, ModifyArgs, Redirect, ModifyVariable, ModifyConstant, At, Slice.
116153
*/
117-
public ClassVisitor preApplyVisitor(TrClass cls, ClassVisitor next) {
118-
return new SoftTargetMixinClassVisitor(new CommonData(cls.getEnvironment(), logger), next);
154+
private final class PreApplyVisitorProvider implements TinyRemapper.ApplyVisitorProvider {
155+
@Override
156+
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) {
157+
return new SoftTargetMixinClassVisitor(new CommonData(cls.getEnvironment(), logger), next);
158+
}
159+
160+
@Override
161+
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next, InputTag[] inputTags) {
162+
if (inputTagFilter == null || inputTags == null) {
163+
return insertApplyVisitor(cls, next);
164+
} else {
165+
for (InputTag tag : inputTags) {
166+
if (inputTagFilter.test(tag)) {
167+
return insertApplyVisitor(cls, next);
168+
}
169+
}
170+
171+
return next;
172+
}
173+
}
119174
}
120175
}
121176

src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/HardTargetMixinClassVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2016, 2018, Player, asie
3-
* Copyright (c) 2021, FabricMC
3+
* Copyright (c) 2021, 2023, FabricMC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -19,6 +19,7 @@
1919
package net.fabricmc.tinyremapper.extension.mixin.hard;
2020

2121
import java.util.ArrayList;
22+
import java.util.Collection;
2223
import java.util.Collections;
2324
import java.util.List;
2425
import java.util.Objects;
@@ -41,7 +42,7 @@
4142
import net.fabricmc.tinyremapper.extension.mixin.hard.data.SoftInterface;
4243

4344
public class HardTargetMixinClassVisitor extends ClassVisitor {
44-
private final List<Consumer<CommonData>> tasks;
45+
private final Collection<Consumer<CommonData>> tasks;
4546
private MxClass _class;
4647

4748
// @Mixin
@@ -51,7 +52,7 @@ public class HardTargetMixinClassVisitor extends ClassVisitor {
5152
// @Implements
5253
private final List<SoftInterface> interfaces = new ArrayList<>();
5354

54-
public HardTargetMixinClassVisitor(List<Consumer<CommonData>> tasks, ClassVisitor delegate) {
55+
public HardTargetMixinClassVisitor(Collection<Consumer<CommonData>> tasks, ClassVisitor delegate) {
5556
super(Constant.ASM_VERSION, delegate);
5657
this.tasks = Objects.requireNonNull(tasks);
5758
}

src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/HardTargetMixinFieldVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2016, 2018, Player, asie
3-
* Copyright (c) 2021, FabricMC
3+
* Copyright (c) 2021, 2023, FabricMC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -18,6 +18,7 @@
1818

1919
package net.fabricmc.tinyremapper.extension.mixin.hard;
2020

21+
import java.util.Collection;
2122
import java.util.List;
2223
import java.util.Objects;
2324
import java.util.function.Consumer;
@@ -32,13 +33,13 @@
3233
import net.fabricmc.tinyremapper.extension.mixin.hard.annotation.ShadowAnnotationVisitor;
3334

3435
class HardTargetMixinFieldVisitor extends FieldVisitor {
35-
private final List<Consumer<CommonData>> tasks;
36+
private final Collection<Consumer<CommonData>> tasks;
3637
private final MxMember field;
3738

3839
private final boolean remap;
3940
private final List<String> targets;
4041

41-
HardTargetMixinFieldVisitor(List<Consumer<CommonData>> tasks, FieldVisitor delegate, MxMember field,
42+
HardTargetMixinFieldVisitor(Collection<Consumer<CommonData>> tasks, FieldVisitor delegate, MxMember field,
4243
boolean remap, List<String> targets) {
4344
super(Constant.ASM_VERSION, delegate);
4445
this.tasks = Objects.requireNonNull(tasks);

src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/HardTargetMixinMethodVisitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2016, 2018, Player, asie
3-
* Copyright (c) 2021, FabricMC
3+
* Copyright (c) 2021, 2023, FabricMC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -18,6 +18,7 @@
1818

1919
package net.fabricmc.tinyremapper.extension.mixin.hard;
2020

21+
import java.util.Collection;
2122
import java.util.List;
2223
import java.util.Objects;
2324
import java.util.function.Consumer;
@@ -35,13 +36,13 @@
3536
import net.fabricmc.tinyremapper.extension.mixin.hard.annotation.ShadowAnnotationVisitor;
3637

3738
class HardTargetMixinMethodVisitor extends MethodVisitor {
38-
private final List<Consumer<CommonData>> data;
39+
private final Collection<Consumer<CommonData>> data;
3940
private final MxMember method;
4041

4142
private final boolean remap;
4243
private final List<String> targets;
4344

44-
HardTargetMixinMethodVisitor(List<Consumer<CommonData>> data, MethodVisitor delegate, MxMember method, boolean remap, List<String> targets) {
45+
HardTargetMixinMethodVisitor(Collection<Consumer<CommonData>> data, MethodVisitor delegate, MxMember method, boolean remap, List<String> targets) {
4546
super(Constant.ASM_VERSION, delegate);
4647
this.data = Objects.requireNonNull(data);
4748
this.method = Objects.requireNonNull(method);

src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/annotation/AccessorAnnotationVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2016, 2018, Player, asie
3-
* Copyright (c) 2021, FabricMC
3+
* Copyright (c) 2021, 2023, FabricMC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -42,14 +42,14 @@
4242
* do not lower the first character of the remaining part.
4343
*/
4444
public class AccessorAnnotationVisitor extends AnnotationVisitor {
45-
private final List<Consumer<CommonData>> tasks;
45+
private final Collection<Consumer<CommonData>> tasks;
4646
private final MxMember method;
4747
private final List<String> targets;
4848

4949
private boolean remap;
5050
private boolean isSoftTarget;
5151

52-
public AccessorAnnotationVisitor(List<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
52+
public AccessorAnnotationVisitor(Collection<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
5353
super(Constant.ASM_VERSION, delegate);
5454

5555
this.tasks = Objects.requireNonNull(tasks);

src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/annotation/ImplementsAnnotationVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2016, 2018, Player, asie
3-
* Copyright (c) 2021, FabricMC
3+
* Copyright (c) 2021, 2023, FabricMC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -81,7 +81,7 @@ public AnnotationVisitor visitAnnotation(String name, String descriptor) {
8181
}
8282
}
8383

84-
public static void visitMethod(List<Consumer<CommonData>> tasks, MxMember method, List<SoftInterface> interfaces) {
84+
public static void visitMethod(Collection<Consumer<CommonData>> tasks, MxMember method, List<SoftInterface> interfaces) {
8585
tasks.add(data -> new SoftImplementsMappable(data, method, interfaces).result());
8686
}
8787

src/main/java/net/fabricmc/tinyremapper/extension/mixin/hard/annotation/InvokerAnnotationVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2016, 2018, Player, asie
3-
* Copyright (c) 2021, FabricMC
3+
* Copyright (c) 2021, 2023, FabricMC
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -40,14 +40,14 @@
4040
* do not lower the first character of the remaining part.
4141
*/
4242
public class InvokerAnnotationVisitor extends AnnotationVisitor {
43-
private final List<Consumer<CommonData>> tasks;
43+
private final Collection<Consumer<CommonData>> tasks;
4444
private final MxMember method;
4545
private final List<String> targets;
4646

4747
private boolean remap;
4848
private boolean isSoftTarget;
4949

50-
public InvokerAnnotationVisitor(List<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
50+
public InvokerAnnotationVisitor(Collection<Consumer<CommonData>> tasks, AnnotationVisitor delegate, MxMember method, boolean remap, List<String> targets) {
5151
super(Constant.ASM_VERSION, delegate);
5252

5353
this.tasks = Objects.requireNonNull(tasks);

0 commit comments

Comments
 (0)