-
Notifications
You must be signed in to change notification settings - Fork 18
/
MappingFormat.java
340 lines (312 loc) · 13.3 KB
/
MappingFormat.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
* Copyright (c) 2021 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.mappingio.format;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.mappingio.format.FeatureSet.ElementCommentSupport;
import net.fabricmc.mappingio.format.FeatureSet.FeaturePresence;
import net.fabricmc.mappingio.format.FeatureSet.MetadataSupport;
/**
* Represents a supported mapping format. Every format can be assumed to have an associated reader available.
*
* <p>A feature comparison table can be found <a href="https://fabricmc.net/wiki/documentation:mapping_formats">here</a>.
*/
// Format order is determined by importance to Fabric tooling, format family and release order therein (synced with the table linked above).
public enum MappingFormat {
/**
* The {@code Tiny} mapping format, as specified <a href="https://fabricmc.net/wiki/documentation:tiny">here</a>.
*
* <h2>Implementation notes</h2>
* File metadata only has limited support as of now, and is hardcoded to intermediary counters.
*/
TINY_FILE("Tiny file", "tiny", true, FeatureSetBuilder.create()
.withNamespaces(true)
.withFileMetadata(MetadataSupport.FIXED) // TODO: change this to ARBITRARY once https://github.com/FabricMC/mapping-io/pull/29 is merged
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL))
.withFields(f -> f
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL)
.withSrcDescs(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL)
.withSrcDescs(FeaturePresence.REQUIRED))
.withFileComments(true)),
/**
* The {@code Tiny v2} mapping format, as specified <a href="https://fabricmc.net/wiki/documentation:tiny2">here</a>.
*/
TINY_2_FILE("Tiny v2 file", "tiny", true, FeatureSetBuilder.create()
.withNamespaces(true)
.withFileMetadata(MetadataSupport.ARBITRARY)
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL))
.withFields(f -> f
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL)
.withSrcDescs(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL)
.withSrcDescs(FeaturePresence.REQUIRED))
.withArgs(a -> a
.withLvIndices(FeaturePresence.REQUIRED)
.withSrcNames(FeaturePresence.OPTIONAL)
.withDstNames(FeaturePresence.OPTIONAL))
.withVars(v -> v
.withLvIndices(FeaturePresence.REQUIRED)
.withLvtRowIndices(FeaturePresence.OPTIONAL)
.withStartOpIndices(FeaturePresence.REQUIRED)
.withSrcNames(FeaturePresence.OPTIONAL)
.withDstNames(FeaturePresence.OPTIONAL))
.withElementComments(ElementCommentSupport.SHARED)
.withFileComments(true)), // only in reserved places
/**
* Enigma's mapping format, as specified <a href="https://fabricmc.net/wiki/documentation:enigma_mappings">here</a>.
*
* <h2>Implementation notes</h2>
* Access modifiers are currently not supported.
*/
ENIGMA_FILE("Enigma file", "mapping", true, FeatureSetBuilder.create()
.withElementMetadata(MetadataSupport.FIXED) // access modifiers
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL))
.withFields(f -> f
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL)
.withSrcDescs(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL)
.withSrcDescs(FeaturePresence.REQUIRED))
.withArgs(a -> a
.withLvIndices(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.OPTIONAL))
.withElementComments(ElementCommentSupport.SHARED)
.withFileComments(true)),
/**
* Enigma's mapping format (in directory form), as specified <a href="https://fabricmc.net/wiki/documentation:enigma_mappings">here</a>.
*
* <h2>Implementation notes</h2>
* Access modifiers are currently not supported.
*/
ENIGMA_DIR("Enigma directory", null, true, FeatureSetBuilder.createFrom(ENIGMA_FILE.features)),
/**
* The {@code SRG} ("Searge RetroGuard") mapping format, as specified <a href="https://github.com/MinecraftForge/SrgUtils/blob/67f30647ece29f18256ca89a23cda6216d6bd21e/src/main/java/net/minecraftforge/srgutils/InternalUtils.java#L69-L81">here</a>.
*
* <h2>Implementation notes</h2>
* Package mappings are currently not supported.
*/
SRG_FILE("SRG file", "srg", true, FeatureSetBuilder.create()
.withPackages(p -> p
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withFields(f -> f
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.REQUIRED)
.withDstDescs(FeaturePresence.REQUIRED))
.withFileComments(true)),
/**
* The {@code XSRG} ("Extended SRG") mapping format, as specified <a href="https://github.com/MinecraftForge/SrgUtils/blob/67f30647ece29f18256ca89a23cda6216d6bd21e/src/main/java/net/minecraftforge/srgutils/InternalUtils.java#L69-L84">here</a>.
*
* <p>Same as SRG, but with field descriptors.
*
* <h2>Implementation notes</h2>
* Package mappings are currently not supported.
*/
XSRG_FILE("XSRG file", "xsrg", true, FeatureSetBuilder.createFrom(SRG_FILE.features)
.withFields(f -> f
.withSrcDescs(FeaturePresence.REQUIRED)
.withDstDescs(FeaturePresence.REQUIRED))),
/**
* The {@code JAM} ("Java Associated Mapping"; formerly {@code SRGX}) mapping format, as specified <a href="https://github.com/caseif/JAM">here</a>.
*/
JAM_FILE("JAM file", "jam", true, FeatureSetBuilder.createFrom(SRG_FILE.features)
.withPackages(p -> p
.withSrcNames(FeaturePresence.ABSENT)
.withDstNames(FeaturePresence.ABSENT))
.withFields(f -> f
.withSrcDescs(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withDstDescs(FeaturePresence.ABSENT))
.withArgs(a -> a
.withPositions(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.OPTIONAL)
.withDstNames(FeaturePresence.REQUIRED))),
/**
* The {@code CSRG} ("Compact SRG", since it saves disk space over SRG) mapping format, as specified <a href="https://github.com/MinecraftForge/SrgUtils/blob/67f30647ece29f18256ca89a23cda6216d6bd21e/src/main/java/net/minecraftforge/srgutils/InternalUtils.java#L196-L207">here</a>.
*
* <h2>Implementation notes</h2>
* Package mappings are currently not supported.
*/
CSRG_FILE("CSRG file", "csrg", true, FeatureSetBuilder.createFrom(SRG_FILE.features)
.withMethods(m -> m
.withDstDescs(FeaturePresence.ABSENT))),
/**
* The {@code TSRG} ("Tiny SRG", since it saves disk space over SRG) mapping format, as specified <a href="https://github.com/MinecraftForge/SrgUtils/blob/67f30647ece29f18256ca89a23cda6216d6bd21e/src/main/java/net/minecraftforge/srgutils/InternalUtils.java#L196-L213">here</a>.
*
* <p>Same as CSRG, but hierarchical instead of flat.
*
* <h2>Implementation notes</h2>
* Package mappings are currently not supported.
*/
TSRG_FILE("TSRG file", "tsrg", true, FeatureSetBuilder.createFrom(CSRG_FILE.features)),
/**
* The {@code TSRG v2} mapping format, as specified <a href="https://github.com/MinecraftForge/SrgUtils/blob/67f30647ece29f18256ca89a23cda6216d6bd21e/src/main/java/net/minecraftforge/srgutils/InternalUtils.java#L262-L285">here</a>.
*
* <h2>Implementation notes</h2>
* Package mappings and static markers for methods are currently not supported.
*/
TSRG_2_FILE("TSRG v2 file", "tsrg", true, FeatureSetBuilder.createFrom(TSRG_FILE.features)
.withNamespaces(true)
.withElementMetadata(MetadataSupport.FIXED) // static info for methods
.withFields(f -> f
.withSrcDescs(FeaturePresence.OPTIONAL))
.withArgs(a -> a
.withLvIndices(FeaturePresence.REQUIRED)
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))),
/**
* ProGuard's mapping format, as specified <a href="https://www.guardsquare.com/manual/tools/retrace">here</a>.
*
* <h2>Implementation notes</h2>
* Line numbers are currently not supported.
*/
PROGUARD_FILE("ProGuard file", "txt", true, FeatureSetBuilder.create()
.withElementMetadata(MetadataSupport.FIXED) // line numbers
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withFields(f -> f
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.REQUIRED))
.withFileComments(true)),
/**
* The IntelliJ IDEA migration map format, as implemented <a href="https://github.com/JetBrains/intellij-community/tree/5b6191dd34e05de8897f5da68757146395a260cc/java/java-impl-refactorings/src/com/intellij/refactoring/migration">here</a>.
*/
INTELLIJ_MIGRATION_MAP_FILE("IntelliJ migration map file", "xml", true, FeatureSetBuilder.create()
.withFileMetadata(MetadataSupport.FIXED) // migration map name and description
.withPackages(p -> p
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withFileComments(true)),
/**
* Recaf's {@code Simple} mapping format, as specified <a href="https://github.com/Col-E/Recaf/blob/e9765d4e02991a9dd48e67c9572a063c14552e7c/src/main/java/me/coley/recaf/mapping/SimpleMappings.java#L14-L23">here</a>.
*/
RECAF_SIMPLE_FILE("Recaf Simple file", "txt", true, FeatureSetBuilder.create()
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withFields(f -> f
.withSrcNames(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.OPTIONAL)
.withDstNames(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.REQUIRED))
.withFileComments(true)),
/**
* The {@code JOBF} mapping format, as specified <a href="https://github.com/skylot/jadx/blob/2d5c0fda4a0c5d16207a5f48edb72e6efa7d5bbd/jadx-core/src/main/java/jadx/core/deobf/DeobfPresets.java">here</a>.
*
* <h2>Implementation notes</h2>
* Package mappings are currently not supported.
*/
JOBF_FILE("JOBF file", "jobf", true, FeatureSetBuilder.create()
.withPackages(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withClasses(c -> c
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED))
.withFields(f -> f
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.REQUIRED))
.withMethods(m -> m
.withSrcNames(FeaturePresence.REQUIRED)
.withDstNames(FeaturePresence.REQUIRED)
.withSrcDescs(FeaturePresence.REQUIRED))
.withFileComments(true));
MappingFormat(String name, @Nullable String fileExt, boolean hasWriter, FeatureSetBuilder featureBuilder) {
this.name = name;
this.fileExt = fileExt;
this.hasWriter = hasWriter;
this.features = featureBuilder.build();
this.hasNamespaces = features.hasNamespaces();
this.hasFieldDescriptors = features.fields().srcDescs() != FeaturePresence.ABSENT || features.fields().dstDescs() != FeaturePresence.ABSENT;
this.supportsComments = features.elementComments() != ElementCommentSupport.NONE;
this.supportsArgs = features.supportsArgs();
this.supportsLocals = features.supportsVars();
}
public FeatureSet features() {
return features;
}
public boolean hasSingleFile() {
return fileExt != null;
}
public String getGlobPattern() {
if (fileExt == null) throw new UnsupportedOperationException("not applicable to dir based format");
return "*."+fileExt;
}
private final FeatureSet features;
public final String name;
public final boolean hasWriter;
@Nullable
public final String fileExt;
/**
* @deprecated Use {@link #features()} instead.
*/
@Deprecated
public final boolean hasNamespaces;
/**
* @deprecated Use {@link #features()} instead.
*/
@Deprecated
public final boolean hasFieldDescriptors;
/**
* @deprecated Use {@link #features()} instead.
*/
@Deprecated
public final boolean supportsComments;
/**
* @deprecated Use {@link #features()} instead.
*/
@Deprecated
public final boolean supportsArgs;
/**
* @deprecated Use {@link #features()} instead.
*/
@Deprecated
public final boolean supportsLocals;
}