Help with a project's plugin
I'm working on my IDEA IntelliJ Plugin with gradle and I am trying to create a button that adds a function to the current class, or a given class. I saw an example in Eclipse but couldn't find the equivalent libraries.
I've tried to seek for an equivalent library to ICompilationUnit in Eclipse but couldn't find anything
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.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);
My main goal is to add a button that once it's clicked it opens a text box, than it adds a function with the given text to the current class. Error if nothing has been typed.
Thank you very much in advanced.
请先登录再写评论。
There is zero overlap between Eclipse and IntelliJ Platform API. Please follow "Getting started" trail in SDK Docs http://www.jetbrains.org/intellij/sdk/docs/basics.html to create your plugin.
Hey, I read the documentation, but still there isnt much about what im asking.. I understand that tgeres zero overlap, bit I guess someone can help with my problem..
If you want to simply add some text, see http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/documents.html. Otherwise PSI will allow you to modify (existing) code on semantic level http://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi.html