1

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?

Simar Singh
  • 415
  • 1
  • 7
  • 14

1 Answers1

0

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.

John Ericksen
  • 10,995
  • 4
  • 45
  • 75
  • Even I have changed the way of adding assignments to a block. Rather than returning I'm passing the block itself as a parameter to which the assignment has to be added. Let's see if there is any workaround to it. – Simar Singh May 28 '19 at 06:56