Creating a record from PsiClass/PsiRecordHeader/PsiRecordComponent
Answered
I am trying to create a duplicate of a class and transfer the fields into a new record class. I already have the fields I want to add as a list of PsiFieldMembers from another class, i.e. name:String, age:Integer, id:UUID etc. I've created the record using psiElementFactory.createRecord(recordName) and now I'm trying to add the fields or parameters for the constructor but I can't seem to modify the PsiRecordHeader (or record.getRecordHeader().getRecordComponents() array) to add PsiRecordComponents, how do I go about this or is there something I'm missing with this line of attack?
Please sign in to leave a comment.
Please show your code. Ref: https://plugins.jetbrains.com/docs/intellij/modifying-psi.html
I've also tried to create an array of PsiRecordComponents and substitute the PsiRecordHeader array but that doesn't seem to work.
Unfortunately, there is no way for now to modify records. You may create the whole file with record using `PsiFileFactory` as, for example, it is done in `com.intellij.codeInspection.classCanBeRecord.RecordBuilder` (github)