How can I create a simple assignment statement in codemodel?

ぃ、小莉子 提交于 2019-12-08 05:09:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!