Я работаю над своим IDEA IntelliJ Plugin с Gradle и пытаюсь создать кнопку, которая добавляет функцию к текущему классу или заданному классу.Я видел пример в Eclipse, но не смог найти эквивалентные библиотеки.
Я пытался найти эквивалентную библиотеку для ICompilationUnit в Eclipse, но не смог найти ничего
ICompilationUnit unit =compilationUnit (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);
Моя главная цель - добавить кнопку, которая при нажатии открывает текстовое поле, а затем добавляет функцию с заданным текстом в текущий класс.Ошибка, если ничего не было введено.
Большое спасибо за продвинутый уровень.