Skip to content

Commit 140befc

Browse files
authored
Add option to disable generation of abstract param file (#27)
1 parent c0c284a commit 140befc

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

src/main/java/net/minecraftforge/fart/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static void main(String[] args) throws IOException {
4343
OptionSpec<Integer> threadsO = parser.accepts("threads", "Number of threads to use, defaults to processor count.").withRequiredArg().ofType(Integer.class).defaultsTo(Runtime.getRuntime().availableProcessors());
4444
OptionSpec<File> ffLinesO = parser.accepts("ff-line-numbers", "Applies line number corrections from Fernflower.").withRequiredArg().ofType(File.class);
4545
OptionSpec<Void> reverseO = parser.accepts("reverse", "Reverse provided mapping file before applying");
46+
OptionSpec<Void> disableAbstractParam = parser.accepts("disable-abstract-param", "Disables collection of names of parameters of abstract methods for FernFlower");
4647
OptionSet options;
4748
try {
4849
options = parser.parse(expandArgs(args));
@@ -105,7 +106,7 @@ public static void main(String[] args) throws IOException {
105106
mappings = mappings.reverse();
106107
}
107108

108-
builder.add(Transformer.renamerFactory(mappings));
109+
builder.add(Transformer.renamerFactory(mappings, !options.has(disableAbstractParam)));
109110
} else {
110111
log.accept("Names: null");
111112
}

src/main/java/net/minecraftforge/fart/api/Renamer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ public interface Builder {
114114
*/
115115
Builder debug(Consumer<String> debug);
116116

117+
/**
118+
* Sets whether to collect parameter names of abstract methods for FernFlower. Defaults to {@code true}.
119+
* @param collectAbstractParams whether to collect parameter names of abstract methods for FernFlower
120+
* @return this builder
121+
*/
122+
Builder setCollectAbstractParams(boolean collectAbstractParams);
123+
117124
/**
118125
* Builds the {@link Renamer} instance based on this configured builder.
119126
* The built Renamer is guaranteed to be reusable for multiple runs.

src/main/java/net/minecraftforge/fart/api/Transformer.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,24 @@ default Collection<? extends Entry> getExtras() {
7070
* Create a transformer that applies mappings as a transformation.
7171
*
7272
* @param map the mapping information to remap with
73+
* @param collectAbstractParams whether to collect abstract parameter names for FernFlower
7374
* @return a factory for a renaming transformer
7475
*/
75-
public static Factory renamerFactory(IMappingFile map) {
76-
return ctx -> new RenamingTransformer(ctx.getClassProvider(), map, ctx.getLog());
76+
static Factory renamerFactory(IMappingFile map, boolean collectAbstractParams) {
77+
return ctx -> new RenamingTransformer(ctx.getClassProvider(), map, ctx.getLog(), collectAbstractParams);
78+
}
79+
80+
/**
81+
* Create a transformer that applies mappings as a transformation.
82+
*
83+
* @param map the mapping information to remap with
84+
* @return a factory for a renaming transformer
85+
*
86+
* @deprecated use {@link #renamerFactory(IMappingFile, boolean)} insteead
87+
*/
88+
@Deprecated
89+
static Factory renamerFactory(IMappingFile map) {
90+
return renamerFactory(map, true);
7791
}
7892

7993
/**

src/main/java/net/minecraftforge/fart/internal/RenamerBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class RenamerBuilder implements Builder {
2727
private boolean withJvmClasspath = false;
2828
private Consumer<String> logger = System.out::println;
2929
private Consumer<String> debug = s -> {};
30+
private boolean collectAbstractParams = true;
3031

3132
@Override
3233
public Builder lib(File value) {
@@ -37,7 +38,7 @@ public Builder lib(File value) {
3738
@Override
3839
public Builder map(File value) {
3940
try {
40-
add(Transformer.renamerFactory(IMappingFile.load(value)));
41+
add(Transformer.renamerFactory(IMappingFile.load(value), collectAbstractParams));
4142
} catch (IOException e) {
4243
throw new RuntimeException("Could not map file: " + value.getAbsolutePath(), e);
4344
}
@@ -87,6 +88,12 @@ public Builder debug(Consumer<String> debug) {
8788
return this;
8889
}
8990

91+
@Override
92+
public Builder setCollectAbstractParams(boolean collectAbstractParams) {
93+
this.collectAbstractParams = collectAbstractParams;
94+
return this;
95+
}
96+
9097
@Override
9198
public Renamer build() {
9299
List<ClassProvider> classProviders = new ArrayList<>(this.classProviders);

src/main/java/net/minecraftforge/fart/internal/RenamingTransformer.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ public class RenamingTransformer implements Transformer {
2626
private static final String ABSTRACT_FILE = "fernflower_abstract_parameter_names.txt";
2727
private final EnhancedRemapper remapper;
2828
private final Set<String> abstractParams = ConcurrentHashMap.newKeySet();
29+
private final boolean collectAbstractParams;
2930

3031
public RenamingTransformer(ClassProvider classProvider, IMappingFile map, Consumer<String> log) {
32+
this(classProvider, map, log, true);
33+
}
34+
35+
public RenamingTransformer(ClassProvider classProvider, IMappingFile map, Consumer<String> log, boolean collectAbstractParams) {
36+
this.collectAbstractParams = collectAbstractParams;
3137
this.remapper = new EnhancedRemapper(classProvider, map, log);
3238
}
3339

@@ -57,10 +63,10 @@ public ResourceEntry process(ResourceEntry entry) {
5763

5864
@Override
5965
public Collection<? extends Entry> getExtras() {
60-
if (abstractParams.isEmpty())
66+
if (abstractParams.isEmpty() || !collectAbstractParams)
6167
return Collections.emptyList();
6268
byte[] data = abstractParams.stream().sorted().collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8);
63-
return Arrays.asList(ResourceEntry.create(ABSTRACT_FILE, Entry.STABLE_TIMESTAMP, data));
69+
return Collections.singletonList(ResourceEntry.create(ABSTRACT_FILE, Entry.STABLE_TIMESTAMP, data));
6470
}
6571

6672
void storeNames(String className, String methodName, String methodDescriptor, Collection<String> paramNames) {

0 commit comments

Comments
 (0)