gradle - Intellij IDEA Plugin Gradle 开发 - 为现有类生成代码
问题描述
我正在使用 gradle 开发我的 IDEA IntelliJ 插件,我正在尝试创建一个按钮,将函数添加到当前类或给定类。我在 Eclipse 中看到了一个示例,但找不到等效的库。
我试图在 Eclipse 中寻找与 ICompilationUnit 等效的库,但找不到任何东西
ICompilationUnit 单元 = 编译单元(activeEditor());
final String messageName = inputBox("Create New Message",
"Message Name");
if (messageName == null)
return null;
String camel = camelCase(messageName);
final String methodName = "handle" + camel;
IType type = null;
try {
unit.createImport(Global.WHEN_RECEIVED_CLASS_NAME.<String>data(), null, null);
type = unit.getType(drop(unit.getElementName(), 4));
if (!type.getSuperclassName().equals("SimpleAgent")) {
msgbox("cannot create message - unrecognized agent type");
return null;
}
IMethod mtd = method(type, methodName);
if (mtd == null) {
mtd = type
.createMethod(
"@WhenReceived(\""
+ messageName
+ "\")\npublic void "
+ methodName
+ "(){\n\t//TODO: Add Message Handling Code Here.\n\t"
+ "//you can add any parameters to the method in order to receive them within the message.\n}\n",
null, false, null);
}
CompilationUnitEditor editor = activeCompilationUnitEditor();
editor.setSelection(mtd);
我的主要目标是添加一个按钮,一旦单击它就会打开一个文本框,而不是将给定文本的函数添加到当前类。如果没有输入任何内容,则会出错。
非常感谢您。
解决方案
推荐阅读
- css - 没有 CSS 关键帧动画(Mozilla Firefox)
- dataframe - Pyspark 中的动态 window.partitionBy 列
- docker - Dockerized nginx 无法加载证书
- flutter - 如何在 Flutter 中绘制可展开和可折叠的侧边栏菜单?
- sql - 具有重复值的 H2 SQL 序列计数
- python - 在 cassandra 中写入 Spark Streaming 中的数据丢失
- c# - 无法从 C# 和图形资源管理器中的 Sharepoint 图形获取驱动器项目和驱动器文件夹
- c# - 将 winform 停靠到屏幕侧并调整屏幕 WorkingArea 的大小
- python - 将元组添加到列表中而不加引号?
- css - 内部 flexbox 覆盖外部 flexbox 上的 flex-grow