Skip to content

Commit 8edc7a3

Browse files
committed
Cleanup keywords list a bit more
1 parent 146b4d5 commit 8edc7a3

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

recaf-core/src/main/java/software/coley/recaf/services/mapping/gen/filter/IncludeKeywordNameFilter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public boolean shouldMapMethod(@Nonnull ClassInfo owner, @Nonnull MethodMember i
5151

5252
@Override
5353
public boolean shouldMapLocalVariable(@Nonnull ClassInfo owner, @Nonnull MethodMember declaringMethod, @Nonnull LocalVariable variable) {
54+
// Edge case: 'this' is allowed only as local variable slot 0 on non-static methods.
55+
if (!declaringMethod.hasStaticModifier() && variable.getIndex() == 0 && "this".equals(variable.getName()))
56+
return false;
5457
if (containsKeyword(variable.getName()))
5558
return true;
5659
return super.shouldMapLocalVariable(owner, declaringMethod, variable);

recaf-core/src/main/java/software/coley/recaf/util/Keywords.java

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ public static Set<String> getKeywords() {
2323
return Collections.unmodifiableSet(keywords);
2424
}
2525

26+
// Commented out items are 'keywords' but can be used as names.
2627
static {
27-
// Commented out items are 'keywords' but can be used as names.
28-
keywords.addAll(Arrays.asList("abstract",
28+
// Misc language constructs
29+
keywords.addAll(Arrays.asList(
2930
"assert",
3031
"break",
3132
// "bridge",
3233
"case",
3334
"catch",
3435
"class",
35-
"const",
3636
"continue",
3737
"default",
3838
"do",
3939
"else",
4040
"enum",
4141
"extends",
42-
"final",
4342
"finally",
4443
"while",
4544
"for",
@@ -51,29 +50,39 @@ public static Set<String> getKeywords() {
5150
"interface",
5251
// "mandated",
5352
// "module",
54-
"native",
5553
"new",
5654
// "open",
55+
"package",
56+
"record",
57+
"return",
58+
"super",
59+
"try",
60+
"this",
61+
"throw",
62+
"throws"
63+
// "var",
64+
// "varargs",
65+
// "yield"
66+
));
67+
68+
// Modifiers
69+
keywords.addAll(Arrays.asList(
70+
"abstract",
71+
"const",
72+
"final",
73+
"native",
5774
"private",
5875
"protected",
5976
"public",
60-
"record",
61-
"return",
6277
"static",
6378
"strictfp",
64-
"super",
6579
"synchronized",
6680
// "synthetic",
6781
"transient",
68-
"try",
69-
"throw",
70-
"throws",
7182
// "transitive",
72-
// "var",
73-
// "varargs",
74-
"volatile",
75-
"yield"
83+
"volatile"
7684
));
85+
7786
// Primitive types
7887
keywords.addAll(Arrays.asList(
7988
"boolean",
@@ -84,7 +93,13 @@ public static Set<String> getKeywords() {
8493
"long",
8594
"float",
8695
"double",
87-
"void",
96+
"void"
97+
));
98+
99+
// Primitive values
100+
keywords.addAll(Arrays.asList(
101+
"true",
102+
"false",
88103
"null"
89104
));
90105
}

0 commit comments

Comments
 (0)