Skip to content

Commit 44d86ea

Browse files
authored
add identifier panel variable types (#177)
* show parameter type in info panel * use full name of parent
1 parent bb35239 commit 44d86ea

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.quiltmc.enigma.gui.panel;
22

3+
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;
7+
import org.quiltmc.enigma.api.translation.representation.TypeDescriptor;
38
import org.quiltmc.enigma.gui.EditableType;
49
import org.quiltmc.enigma.gui.Gui;
510
import org.quiltmc.enigma.gui.config.Config;
@@ -118,7 +123,7 @@ public void refreshReference() {
118123
th.addCopiableStringRow(I18n.translate("info_panel.identifier.obfuscated"), this.entry.getName());
119124

120125
if (ce.getParent() != null) {
121-
th.addCopiableStringRow(I18n.translate("info_panel.identifier.superclass"), ce.getParent().getName());
126+
th.addCopiableStringRow(I18n.translate("info_panel.identifier.superclass"), ce.getParent().getFullName());
122127
}
123128
} else if (this.deobfEntry instanceof FieldEntry fe) {
124129
this.nameField = th.addRenameTextField(EditableType.FIELD, fe.getName());
@@ -152,6 +157,41 @@ public void refreshReference() {
152157
th.addStringRow(I18n.translate("info_panel.identifier.class"), lve.getContainingClass().getFullName());
153158
th.addCopiableStringRow(I18n.translate("info_panel.identifier.method"), lve.getParent().getName());
154159
th.addStringRow(I18n.translate("info_panel.identifier.index"), Integer.toString(lve.getIndex()));
160+
161+
// 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+
var primitive = TypeDescriptor.Primitive.get(arg.toString().charAt(0));
169+
170+
if (i == lve.getIndex()) {
171+
String niceType;
172+
if (primitive != null) {
173+
niceType = arg + " (" + primitive.getKeyword() + ")";
174+
} else {
175+
// type will look like "LClassName;", with an optional [ at the start to denote an array
176+
String raw = arg.toString();
177+
// strip semicolon (;) from the end
178+
raw = raw.substring(0, raw.length() - 1);
179+
// handle arrays: add "[]" to the end and strip "["
180+
while (raw.startsWith("[")) {
181+
raw = raw.substring(1) + "[]";
182+
}
183+
184+
// strip "L"
185+
raw = raw.substring(1);
186+
niceType = raw;
187+
}
188+
189+
th.addCopiableStringRow(I18n.translate("info_panel.identifier.type"), niceType);
190+
break;
191+
}
192+
193+
i += primitive == null ? 1 : primitive.getSize();
194+
}
155195
} else {
156196
throw new IllegalStateException("unreachable");
157197
}

enigma/src/main/java/org/quiltmc/enigma/api/translation/representation/TypeDescriptor.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ public TranslateResult<TypeDescriptor> extendedTranslate(Translator translator,
224224
}
225225

226226
public enum Primitive {
227-
BYTE('B', "byte"),
228-
CHARACTER('C', "char"),
229-
SHORT('S', "short"),
230-
INTEGER('I', "int"),
231-
LONG('J', "long"),
232-
FLOAT('F', "float"),
233-
DOUBLE('D', "double"),
234-
BOOLEAN('Z', "boolean");
227+
BYTE('B', "byte", 1),
228+
CHARACTER('C', "char", 1),
229+
SHORT('S', "short", 1),
230+
INTEGER('I', "int", 1),
231+
LONG('J', "long", 2),
232+
FLOAT('F', "float", 1),
233+
DOUBLE('D', "double", 2),
234+
BOOLEAN('Z', "boolean", 1);
235235

236236
private static final Map<Character, Primitive> lookup;
237237

@@ -244,10 +244,12 @@ public enum Primitive {
244244

245245
private final char code;
246246
private final String keyword;
247+
private final int size;
247248

248-
Primitive(char code, String keyword) {
249+
Primitive(char code, String keyword, int size) {
249250
this.code = code;
250251
this.keyword = keyword;
252+
this.size = size;
251253
}
252254

253255
public static Primitive get(char code) {
@@ -258,6 +260,13 @@ public char getCode() {
258260
return this.code;
259261
}
260262

263+
/**
264+
* @return the amount the primitive will increment parameter indices
265+
*/
266+
public int getSize() {
267+
return this.size;
268+
}
269+
261270
/**
262271
* Returns the Java keyword corresponding to this primitive.
263272
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
"info_panel.identifier.class": "Class",
142142
"info_panel.identifier.superclass": "Superclass",
143143
"info_panel.identifier.obfuscated": "Obfuscated Name",
144+
"info_panel.identifier.type": "Type",
144145
"info_panel.identifier.type_descriptor": "Type Descriptor",
145146
"info_panel.identifier.method_descriptor": "Method Descriptor",
146147
"info_panel.identifier.index": "Index",

enigma/src/test/java/org/quiltmc/enigma/input/bridge/BaseClass.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public BaseClass baz(int xz) {
6262
return new BaseClass(xz, 0, xz);
6363
}
6464

65+
public BaseClass whee(long xyz, int q, int w) {
66+
return new BaseClass((int) xyz, (int) xyz, (int) xyz);
67+
}
68+
6569
// b(II)La;
6670
public BaseClass baz(int xz, int y) {
6771
if (y == 0) {

0 commit comments

Comments
 (0)