From 80057312203d346faf6e4e572c7441bd27e3a73d Mon Sep 17 00:00:00 2001 From: shartte Date: Sat, 30 Dec 2023 15:55:13 +0100 Subject: [PATCH] Do not rename parameters for record constructors (#4) --- api/src/main/java/net/neoforged/jst/api/PsiHelper.java | 5 +++++ .../neoforged/jst/parchment/GatherReplacementsVisitor.java | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/neoforged/jst/api/PsiHelper.java b/api/src/main/java/net/neoforged/jst/api/PsiHelper.java index e6f5563..38c6261 100644 --- a/api/src/main/java/net/neoforged/jst/api/PsiHelper.java +++ b/api/src/main/java/net/neoforged/jst/api/PsiHelper.java @@ -137,4 +137,9 @@ public static int getBinaryIndex(PsiParameter psiParameter, int index) { return -1; } } + + public static boolean isRecordConstructor(PsiMethod psiMethod) { + var containingClass = psiMethod.getContainingClass(); + return containingClass != null && containingClass.isRecord() && psiMethod.isConstructor(); + } } diff --git a/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java b/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java index d6c7755..effed26 100644 --- a/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java +++ b/parchment/src/main/java/net/neoforged/jst/parchment/GatherReplacementsVisitor.java @@ -93,8 +93,9 @@ public void visitElement(@NotNull PsiElement element) { var jvmIndex = PsiHelper.getBinaryIndex(psiParameter, i); var paramData = methodData.getParameter(jvmIndex); - // Optionally replace the parameter name - if (paramData != null && paramData.getName() != null) { + // Optionally replace the parameter name, but skip record constructors, since those could have + // implications for the field names. + if (paramData != null && paramData.getName() != null && !PsiHelper.isRecordConstructor(psiMethod)) { // Replace parameters within the method body activeParameters.put(psiParameter, paramData);