Skip to content

Commit 769ef0d

Browse files
Fix 201 (#298)
* report no type instead of wrong type for un-indexed method params * show <unknown> for unknown param types * use obf local entry to lookup descriptor instead of deobf (which is not in index)
1 parent 5c66c48 commit 769ef0d

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/IdentifierPanel.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.quiltmc.enigma.gui.panel;
22

3+
import org.quiltmc.enigma.api.EnigmaProject;
34
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
4-
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
5-
import org.quiltmc.enigma.api.translation.representation.AccessFlags;
6-
import org.quiltmc.enigma.api.translation.representation.ArgumentDescriptor;
75
import org.quiltmc.enigma.api.translation.representation.TypeDescriptor;
6+
import org.quiltmc.enigma.api.translation.representation.entry.LocalVariableDefEntry;
87
import org.quiltmc.enigma.gui.EditableType;
98
import org.quiltmc.enigma.gui.Gui;
109
import org.quiltmc.enigma.gui.config.Config;
@@ -27,6 +26,7 @@
2726
import java.awt.GridBagConstraints;
2827
import java.awt.GridBagLayout;
2928
import java.awt.event.MouseEvent;
29+
import javax.annotation.Nullable;
3030
import javax.swing.BorderFactory;
3131
import javax.swing.JLabel;
3232
import javax.swing.JPanel;
@@ -77,7 +77,8 @@ public boolean startRenaming(String text) {
7777
}
7878

7979
public void refreshReference() {
80-
this.deobfEntry = this.entry == null ? null : this.gui.getController().getProject().getRemapper().deobfuscate(this.entry);
80+
final EnigmaProject project = this.gui.getController().getProject();
81+
this.deobfEntry = this.entry == null ? null : project.getRemapper().deobfuscate(this.entry);
8182

8283
// Prevent IdentifierPanel from being rebuilt if you didn't click off.
8384
if (this.lastEntry == this.entry && this.nameField != null) {
@@ -144,40 +145,35 @@ public void refreshReference() {
144145

145146
th.addCopiableStringRow(I18n.translate("info_panel.identifier.obfuscated"), this.entry.getName());
146147
th.addCopiableStringRow(I18n.translate("info_panel.identifier.method_descriptor"), me.getDesc().toString());
147-
} else if (this.deobfEntry instanceof LocalVariableEntry lve) {
148+
} else if (this.deobfEntry instanceof LocalVariableEntry local) {
148149
EditableType type;
149150

150-
if (lve.isArgument()) {
151+
if (local.isArgument()) {
151152
type = EditableType.PARAMETER;
152153
} else {
153154
type = EditableType.LOCAL_VARIABLE;
154155
}
155156

156-
this.nameField = th.addRenameTextField(type, lve.getName());
157-
th.addStringRow(I18n.translate("info_panel.identifier.class"), lve.getContainingClass().getFullName());
158-
th.addCopiableStringRow(I18n.translate("info_panel.identifier.method"), lve.getParent().getName());
159-
th.addStringRow(I18n.translate("info_panel.identifier.index"), Integer.toString(lve.getIndex()));
157+
this.nameField = th.addRenameTextField(type, local.getName());
158+
th.addStringRow(I18n.translate("info_panel.identifier.class"), local.getContainingClass().getFullName());
159+
th.addCopiableStringRow(I18n.translate("info_panel.identifier.method"), local.getParent().getName());
160+
th.addStringRow(I18n.translate("info_panel.identifier.index"), Integer.toString(local.getIndex()));
160161

161162
// type
162-
JarIndex index = this.gui.getController().getProject().getJarIndex();
163-
AccessFlags access = index.getIndex(EntryIndex.class).getMethodAccess(lve.getParent());
164-
int i = access != null && access.isStatic() ? 0 : 1;
165-
var args = lve.getParent().getDesc().getArgumentDescs();
166-
167-
for (ArgumentDescriptor arg : args) {
168-
if (i == lve.getIndex()) {
169-
th.addCopiableStringRow(I18n.translate("info_panel.identifier.type"), toReadableType(arg));
170-
break;
171-
}
172-
173-
var primitive = TypeDescriptor.Primitive.get(arg.toString().charAt(0));
174-
i += primitive == null ? 1 : primitive.getSize();
175-
}
163+
EntryIndex index = project.getJarIndex().getIndex(EntryIndex.class);
164+
// EntryIndex only contains obf entries, so use the obf entry to look up the local's descriptor
165+
@Nullable
166+
final LocalVariableDefEntry obfLocal = index.getDefinition((LocalVariableEntry) this.entry);
167+
final String localDesc = obfLocal == null
168+
? I18n.translate("info_panel.identifier.type.unknown")
169+
: toReadableType(project.getRemapper().deobfuscate(obfLocal.getDesc()));
170+
171+
th.addCopiableStringRow(I18n.translate("info_panel.identifier.type"), localDesc);
176172
} else {
177173
throw new IllegalStateException("unreachable");
178174
}
179175

180-
var mapping = this.gui.getController().getProject().getRemapper().getMapping(this.entry);
176+
var mapping = project.getRemapper().getMapping(this.entry);
181177
if (Config.main().development.showMappingSourcePlugin.value() && mapping.tokenType().isProposed()) {
182178
th.addStringRow(I18n.translate("dev.source_plugin"), mapping.sourcePluginId());
183179
}

enigma/src/main/resources/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
"info_panel.identifier.outer_class": "Outer class",
162162
"info_panel.identifier.obfuscated": "Obfuscated Name",
163163
"info_panel.identifier.type": "Type",
164+
"info_panel.identifier.type.unknown": "<unknown>",
164165
"info_panel.identifier.method_descriptor": "Method Descriptor",
165166
"info_panel.identifier.index": "Index",
166167
"info_panel.editor.class.decompiling": "(decompiling...)",

0 commit comments

Comments
 (0)