问题
I want to create a simple statement using codemodel like :-
String text = element.getText();
I don't want to assign it to any block for now, rather just return it because I would be needing the name of the variable to refer later. How can I create such a statement and in which type of variable to store it? Would it be a JStatement? If yes then how?
回答1:
It looks like the codemodel api doesn't allow you to create an assigment without a Block
. The JAssignment
object is created via the JBlock
.assign()
method, and the constructor for JAssignment
is package private. That being said, you can always make an object of your own to hold the various parts of the assignment and defer the building of the assignment until you have a block to add it to.
来源:https://stackoverflow.com/questions/56323876/how-can-i-create-a-simple-assignment-statement-in-codemodel