Skip to content

Commit 0a635dd

Browse files
committed
add test proposer for fallback
- fix highlighting - only propose names for the first parameter of each method in test:parameters
1 parent 71880f2 commit 0a635dd

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,22 @@ public void setHighlightedTokens(TokenStore tokenStore, Map<TokenType, ? extends
498498
this.editor.getHighlighter().removeAllHighlights();
499499

500500
for (TokenType type : tokens.keySet()) {
501-
BoxHighlightPainter tokenPainter = switch (type) {
501+
BoxHighlightPainter typePainter = switch (type) {
502502
case OBFUSCATED -> this.obfuscatedPainter;
503503
case DEOBFUSCATED -> this.deobfuscatedPainter;
504504
case DEBUG -> this.debugPainter;
505505
case JAR_PROPOSED, DYNAMIC_PROPOSED -> this.proposedPainter;
506506
};
507507

508508
for (Token token : tokens.get(type)) {
509+
BoxHighlightPainter tokenPainter = typePainter;
509510
EntryReference<Entry<?>, Entry<?>> reference = this.getReference(token);
510511

511512
if (reference != null) {
512513
EditableType t = EditableType.fromEntry(reference.entry);
513514
boolean editable = t == null || this.gui.isEditable(t);
514515
boolean fallback = tokenStore.isFallback(token);
515-
tokenPainter = editable ? (fallback ? this.fallbackPainter : tokenPainter) : this.proposedPainter;
516+
tokenPainter = editable ? (fallback ? this.fallbackPainter : typePainter) : this.proposedPainter;
516517
}
517518

518519
this.addHighlightedToken(token, tokenPainter);

enigma/src/testFixtures/java/org/quiltmc/enigma/test/plugin/TestEnigmaPlugin.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,50 @@ public class TestEnigmaPlugin implements EnigmaPlugin {
1818
@Override
1919
public void init(EnigmaPluginContext ctx) {
2020
this.registerParameterNamingService(ctx);
21+
this.registerFieldNamingService(ctx);
2122
}
2223

2324
private void registerParameterNamingService(EnigmaPluginContext ctx) {
2425
ctx.registerService(NameProposalService.TYPE, ctx1 -> new ParameterNameProposalService());
2526
}
2627

28+
private void registerFieldNamingService(EnigmaPluginContext ctx) {
29+
ctx.registerService(NameProposalService.TYPE, ctx2 -> new StringFieldNameProposalService());
30+
}
31+
32+
public static class StringFieldNameProposalService implements NameProposalService {
33+
@Override
34+
public String getId() {
35+
return "test:strings";
36+
}
37+
38+
@Override
39+
public Map<Entry<?>, EntryMapping> getProposedNames(JarIndex index) {
40+
EntryIndex entryIndex = index.getIndex(EntryIndex.class);
41+
Map<Entry<?>, EntryMapping> names = new HashMap<>();
42+
43+
int fieldIndex = 0;
44+
for (var field : entryIndex.getFields()) {
45+
if (field.getDesc().toString().equals("Ljava/lang/String;")) {
46+
names.put(field, this.createMapping("string" + fieldIndex, TokenType.JAR_PROPOSED));
47+
fieldIndex++;
48+
}
49+
}
50+
51+
return names;
52+
}
53+
54+
@Override
55+
public boolean isFallback() {
56+
return true;
57+
}
58+
59+
@Override
60+
public Map<Entry<?>, EntryMapping> getDynamicProposedNames(EntryRemapper remapper, Entry<?> obfEntry, EntryMapping oldMapping, EntryMapping newMapping) {
61+
return null;
62+
}
63+
}
64+
2765
public static class ParameterNameProposalService implements NameProposalService {
2866
private static final MethodDescriptor EQUALS_DESC = new MethodDescriptor("(Ljava/lang/Object;)Z");
2967

@@ -41,7 +79,9 @@ public Map<Entry<?>, EntryMapping> getProposedNames(JarIndex index) {
4179
var param = method.getParameters(entryIndex).get(0);
4280
names.put(param, this.createMapping("o", TokenType.JAR_PROPOSED));
4381
} else {
44-
for (var param : method.getParameters(entryIndex)) {
82+
// only propose a name for the first parameter
83+
if (!method.getParameters(index.getIndex(EntryIndex.class)).isEmpty()) {
84+
var param = method.getParameters(entryIndex).get(0);
4585
names.put(param, this.createMapping("param" + param.getIndex(), TokenType.JAR_PROPOSED));
4686
}
4787
}

enigma/src/testFixtures/resources/profile.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
{
2222
"id": "test:parameters"
2323
},
24+
{
25+
"id": "test:strings"
26+
},
2427
{
2528
"id": "enigma:record_component_proposer"
2629
}

0 commit comments

Comments
 (0)