From 672c7b36f092d3c632b2582a54a33c0cb8893800 Mon Sep 17 00:00:00 2001 From: Kyle Wood Date: Wed, 2 Aug 2023 23:21:26 -0500 Subject: [PATCH] Version 1.0.6, fix empty records --- gradle.properties | 2 +- .../io/papermc/codebook/pages/FixJarPage.java | 33 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index ba72939..8e86f5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group = io.papermc.codebook -version = 1.0.6-SNAPSHOT +version = 1.0.6 diff --git a/src/main/java/io/papermc/codebook/pages/FixJarPage.java b/src/main/java/io/papermc/codebook/pages/FixJarPage.java index a800768..e3e05df 100644 --- a/src/main/java/io/papermc/codebook/pages/FixJarPage.java +++ b/src/main/java/io/papermc/codebook/pages/FixJarPage.java @@ -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; @@ -71,7 +72,11 @@ private void fixJar() throws IOException { final var tasks = new ArrayList>(); 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); } @@ -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); } @@ -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; }