11/*
2- * Copyright (C) 2009-2021 The Project Lombok Authors.
2+ * Copyright (C) 2009-2025 The Project Lombok Authors.
33 *
44 * Permission is hereby granted, free of charge, to any person obtaining a copy
55 * of this software and associated documentation files (the "Software"), to deal
4040import org .eclipse .jdt .internal .compiler .CompilationResult ;
4141import org .eclipse .jdt .internal .compiler .ast .ASTNode ;
4242import org .eclipse .jdt .internal .compiler .ast .AbstractMethodDeclaration ;
43+ import org .eclipse .jdt .internal .compiler .ast .AbstractVariableDeclaration ;
4344import org .eclipse .jdt .internal .compiler .ast .Annotation ;
4445import org .eclipse .jdt .internal .compiler .ast .Argument ;
4546import org .eclipse .jdt .internal .compiler .ast .CompilationUnitDeclaration ;
@@ -354,7 +355,7 @@ public static boolean isComplete(CompilationUnitDeclaration unit) {
354355case TYPE :
355356return buildType ((TypeDeclaration ) node );
356357case FIELD :
357- return buildField ((FieldDeclaration ) node , null );
358+ return buildField ((FieldDeclaration ) node );
358359case INITIALIZER :
359360return buildInitializer ((Initializer ) node );
360361case METHOD :
@@ -393,17 +394,38 @@ private List<EclipseNode> buildTypes(TypeDeclaration[] children) {
393394private EclipseNode buildType (TypeDeclaration type ) {
394395if (setAndGetAsHandled (type )) return null ;
395396List <EclipseNode > childNodes = new ArrayList <EclipseNode >();
396- childNodes .addAll (buildFields (type .fields , getRecordFieldAnnotations (type )));
397+ childNodes .addAll (buildRecordComponents (getRecordComponents (type )));
398+ childNodes .addAll (buildFields (type .fields ));
397399childNodes .addAll (buildTypes (type .memberTypes ));
398400childNodes .addAll (buildMethods (type .methods ));
399401childNodes .addAll (buildAnnotations (type .annotations , false ));
400402return putInMap (new EclipseNode (this , type , childNodes , Kind .TYPE ));
401403}
402404
403- private Collection <EclipseNode > buildFields ( FieldDeclaration [] children , Annotation [][] annotations ) {
405+ private Collection <EclipseNode > buildRecordComponents ( AbstractVariableDeclaration [] children ) {
404406List <EclipseNode > childNodes = new ArrayList <EclipseNode >();
405407if (children != null ) for (int i = 0 ; i < children .length ; i ++) {
406- addIfNotNull (childNodes , buildField (children [i ], annotations [i ]));
408+ addIfNotNull (childNodes , buildRecordComponent (children [i ]));
409+ }
410+ return childNodes ;
411+ }
412+
413+ private EclipseNode buildRecordComponent (AbstractVariableDeclaration field ) {
414+ List <EclipseNode > childNodes = new ArrayList <EclipseNode >();
415+ addIfNotNull (childNodes , buildTypeUse (field .type ));
416+ addIfNotNull (childNodes , buildStatement (field .initialization ));
417+ childNodes .addAll (buildAnnotations (field .annotations , true ));
418+ FieldDeclaration fieldDeclaration = new FieldDeclaration (field .name , field .sourceStart , field .sourceEnd );
419+ fieldDeclaration .type = field .type ;
420+ fieldDeclaration .modifiers = field .modifiers | Eclipse .AccRecord ;
421+ fieldDeclaration .annotations = field .annotations ;
422+ return putInMap (new EclipseNode (this , fieldDeclaration , childNodes , Kind .FIELD ));
423+ }
424+
425+ private Collection <EclipseNode > buildFields (FieldDeclaration [] children ) {
426+ List <EclipseNode > childNodes = new ArrayList <EclipseNode >();
427+ if (children != null ) for (int i = 0 ; i < children .length ; i ++) {
428+ addIfNotNull (childNodes , buildField (children [i ]));
407429}
408430return childNodes ;
409431}
@@ -414,13 +436,14 @@ private static <T> List<T> singleton(T item) {
414436return list ;
415437}
416438
417- private EclipseNode buildField (FieldDeclaration field , Annotation [] annotations ) {
439+ private EclipseNode buildField (FieldDeclaration field ) {
418440if (field instanceof Initializer ) return buildInitializer ((Initializer ) field );
419441if (setAndGetAsHandled (field )) return null ;
442+ if (isRecordField (field )) return null ;
420443List <EclipseNode > childNodes = new ArrayList <EclipseNode >();
421444addIfNotNull (childNodes , buildTypeUse (field .type ));
422445addIfNotNull (childNodes , buildStatement (field .initialization ));
423- childNodes .addAll (buildAnnotations (annotations != null ? annotations : field .annotations , true ));
446+ childNodes .addAll (buildAnnotations (field .annotations , true ));
424447return putInMap (new EclipseNode (this , field , childNodes , Kind .FIELD ));
425448}
426449
0 commit comments