Skip to content

Commit 371bf32

Browse files
committed
Don't propose enum names that match the existing field.
1 parent 13d4b41 commit 371bf32

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

filament/src/main/java/net/fabricmc/filament/nameproposal/FieldNameFinder.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Map;
2525
import java.util.Set;
2626

27-
import org.objectweb.asm.ClassReader;
2827
import org.objectweb.asm.Opcodes;
2928
import org.objectweb.asm.tree.AbstractInsnNode;
3029
import org.objectweb.asm.tree.FieldInsnNode;
@@ -39,19 +38,6 @@
3938
import org.objectweb.asm.tree.analysis.SourceValue;
4039

4140
public class FieldNameFinder {
42-
public Map<MappingEntry, String> findNames(Iterable<byte[]> classes) throws Exception {
43-
Map<String, List<MethodNode>> methods = new HashMap<>();
44-
Map<String, Set<String>> enumFields = new HashMap<>();
45-
46-
for (byte[] data : classes) {
47-
ClassReader reader = new ClassReader(data);
48-
NameFinderVisitor vClass = new NameFinderVisitor(Constants.ASM_VERSION, enumFields, methods);
49-
reader.accept(vClass, ClassReader.SKIP_FRAMES);
50-
}
51-
52-
return findNames(enumFields, methods);
53-
}
54-
5541
public Map<MappingEntry, String> findNames(Map<String, Set<String>> allEnumFields, Map<String, List<MethodNode>> classes) {
5642
Analyzer<SourceValue> analyzer = new Analyzer<>(new SourceInterpreter());
5743
Map<MappingEntry, String> fieldNames = new HashMap<>();
@@ -151,6 +137,11 @@ public Map<MappingEntry, String> findNames(Map<String, Set<String>> allEnumField
151137
}
152138

153139
if (usedNames.contains(s)) {
140+
if (s.equals(((FieldInsnNode) instr2).name)) {
141+
// No need to map names that are already named what we want to name it.
142+
continue;
143+
}
144+
154145
fieldNames.put(new MappingEntry(((FieldInsnNode) instr2).owner, ((FieldInsnNode) instr2).name, ((FieldInsnNode) instr2).desc), s);
155146
}
156147
}

0 commit comments

Comments
 (0)