how PsiAugmentProvider return psiClass ?

Answered

 

I want to implement lombok builder. I have tried many ways, but I have no clue

I have implemented adding fields

I don't know LightPsiClassBuilder  if it can be realized


override fun <Psi : PsiElement> getAugments(
psiElement: PsiElement,
type: Class<Psi>,
nameHint: String?
): MutableList<Psi> {
var emptyResult = ArrayList<Psi>();

if (!PsiField::class.java.isAssignableFrom(type)) {
return emptyResult;
}

if ((psiElement is PsiClass) == false) {
return emptyResult;
}
var psiClass = psiElement as PsiClass;

// create field. it's ok
val psiField: PsiField = MyFieldUtils.createCacheField(psiClass, "hello")
val psiElementList: MutableList<PsiElement> = ArrayList()
psiElementList.add(psiField)

var desginName = psiClass.name + "Desgin"
// TODO How to add ?
var javaFile: PsiFile = PsiFileFactory.getInstance(psiElement.project)
.createFileFromText(
"${desginName}.java", JavaFileType.INSTANCE, """
package com.youtube.geekific
class ${desginName}{
public String name(){
return "";
}
}
""".trimIndent()
)
return (psiElementList as MutableList<Psi>);
}

 

 

 

2 comments
Comment actions Permalink

Hi,

Why are you trying to implement Lombok functionality which is bundled in IntelliJ IDEA Community, which is free? Duplicating existing plugins and functionalities without a strong reason should be avoided.

If you still are interested in implementing it for some reason, you can get some inspiration from:

1
Comment actions Permalink

 

Thank you for your answer @Karol Lewandowski

I've looked at the lombok source code, but I think it's already very complicated, making it hard for me to understand

I have a really cool idea, but I need to know the lombok builder implementation so I can finish it


have a nice day

0

Please sign in to leave a comment.