Skip to content

Commit

Permalink
Merge pull request #444 from liuzhengyang/enum-field-change
Browse files Browse the repository at this point in the history
Fix enum field update
  • Loading branch information
skybber authored Oct 11, 2022
2 parents 4471aaa + f4d0660 commit 159ff08
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ public void edit(FieldAccess f) throws CannotCompileException {
reinitializeStatics[0] = true;
}
if (originalField != null) {
// ENUM$VALUES is last in enumeration
if (originalClass.isEnum() && "ENUM$VALUES".equals(f.getFieldName())) {
// Enum class contains an array field, in javac it's name starts with $VALUES,
// in eclipse compiler starts with ENUM$VALUES
if (originalClass.isEnum() && f.getSignature().startsWith("[L")
&& (f.getFieldName().startsWith("$VALUES")
|| f.getFieldName().startsWith("ENUM$VALUES"))) {
if (reinitializeStatics[0]) {
LOGGER.debug("New field will be initialized {}", f.getFieldName());
} else {
Expand Down Expand Up @@ -149,7 +152,7 @@ private static boolean checkOldEnumValues(CtClass ctClass, Class<?> originalClas
try {
CtField existing = ctClass.getDeclaredField(en.toString());
} catch (NotFoundException e) {
LOGGER.debug("Enum field deleted. ENUM$VALUES will be reinitialized {}", en.toString());
LOGGER.debug("Enum field deleted. $VALUES will be reinitialized {}", en.toString());
return true;
}
}
Expand Down

0 comments on commit 159ff08

Please sign in to comment.