Skip to content

Commit

Permalink
Do not rename parameters for record constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 30, 2023
1 parent 7c8d016 commit b43f353
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/src/main/java/net/neoforged/jst/api/PsiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b43f353

Please sign in to comment.