如何在代码模型中创建简单的赋值语句? [英] How can I create a simple assignment statement in codemodel?

查看:99
本文介绍了如何在代码模型中创建简单的赋值语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用像:-

String text = element.getText();

我现在不想将其分配给任何块,而只是将其返回,因为我以后需要引用变量的名称.如何创建这样的语句以及将其存储在哪种类型的变量中?会是JStatement吗?如果是,那怎么办?

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?

推荐答案

代码模型api不允许您在没有Block的情况下创建分配. JAssignment对象是通过JBlock .assign()方法创建的,并且JAssignment的构造函数是程序包私有的.话虽如此,您始终可以创建自己的对象来保存分配的各个部分,并推迟分配的构建,直到您将其添加到一个块中为止.

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.

这篇关于如何在代码模型中创建简单的赋值语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆