Reputation: 1878
I'm trying to write a Java plugin that does a custom refactoring that involves inserting new assignment statements, and I'm not sure how to create a PsiAssignmentExpression
.
I have a PsiElementFactory
, but while I see PsiElementFactory#createIdentifier
and PsiElementFactory#createVariableDeclarationStatement
, I don't see how to do an assignment.
I tried looking for the extract variable refactoring in the base source code to try and find an example but wasn't able to find it yet.
P.S. I looked at IntelliJ IDEA plugin development: how to modify the Psi tree?, which recommended creating PsiElements by creating a PsiFile
and then extracting the element from it back in, but I am wondering if that's specific to creating a custom language that doesn't have the Java api.
Upvotes: 0
Views: 141
Reputation: 26597
Use PsiElementFactory#createExpressionFromText
and pass in the text of the assignment you want to create. For example "s = \"Hello World\""
.
Upvotes: 1