Skip to content

Commit

Permalink
Version 1.0.6, fix empty records
Browse files Browse the repository at this point in the history
  • Loading branch information
DenWav committed Aug 3, 2023
1 parent ae9326c commit 672c7b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group = io.papermc.codebook
version = 1.0.6-SNAPSHOT
version = 1.0.6
33 changes: 30 additions & 3 deletions src/main/java/io/papermc/codebook/pages/FixJarPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import dev.denwav.hypo.asm.AsmMethodData;
import dev.denwav.hypo.core.HypoContext;
import dev.denwav.hypo.hydrate.generic.HypoHydration;
import dev.denwav.hypo.model.HypoModelUtil;
import dev.denwav.hypo.model.data.ClassData;
import dev.denwav.hypo.model.data.ClassKind;
import dev.denwav.hypo.model.data.FieldData;
Expand Down Expand Up @@ -71,7 +72,11 @@ private void fixJar() throws IOException {
final var tasks = new ArrayList<Future<?>>();
for (final ClassData classData : this.context.getProvider().allClasses()) {
final var task = this.context.getExecutor().submit(() -> {
this.processClass((AsmClassData) classData);
try {
this.processClass((AsmClassData) classData);
} catch (final IOException e) {
throw HypoModelUtil.rethrow(e);
}
});
tasks.add(task);
}
Expand All @@ -87,8 +92,9 @@ private void fixJar() throws IOException {
}
}

private void processClass(final AsmClassData classData) {
private void processClass(final AsmClassData classData) throws IOException {
OverrideAnnotationAdder.addAnnotations(classData);
EmptyRecordFixer.fixClass(classData);
RecordFieldAccessFixer.fixClass(classData);
DeprecatedAnnotationAdder.addAnnotations(classData);
}
Expand Down Expand Up @@ -151,13 +157,34 @@ private static void addAnnotations(final AsmClassData classData) {
}
}

private static final class EmptyRecordFixer {

private EmptyRecordFixer() {}

private static void fixClass(final AsmClassData classData) throws IOException {
if (classData.is(ClassKind.RECORD)) {
return;
}

final @Nullable ClassData superClass = classData.superClass();
if (superClass == null) {
return;
}

if (superClass.name().equals("java/lang/Record")) {
// extends record, but is not marked as such
classData.getNode().access |= Opcodes.ACC_RECORD;
}
}
}

private static final class RecordFieldAccessFixer {
private static final int RESET_ACCESS = ~(Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);

private RecordFieldAccessFixer() {}

private static void fixClass(final AsmClassData classData) {
if (classData.kind() != ClassKind.RECORD) {
if (classData.isNot(ClassKind.RECORD)) {
return;
}

Expand Down

0 comments on commit 672c7b3

Please sign in to comment.