Context dependent method creation Follow
In IntelliJ IDEA, If I try to call the method that doesn't exist:
MyClass myClass = new MyClass();
String arg1 = "";
int arg2 = 0;
int c = myClass.nonExistentMethod(arg1, arg2);
the editor offers to create the method with required signature and returning value:
class MyClass{
...
public int nonExistentMethod(String arg1, int arg2){
return 0;
}
}
I badly need to extend this functionality to be able to generate not only the method declaration but, in case when MyClass extends particular interface, to generate the body of the method and to do some other work.
Unfortunately, I don't have any idea even how to approach to that task. So I'd appreciate any help, references to articles on the subject, code snippets etc.
Please sign in to leave a comment.
Hello Eugeny,
There is no way to extend the standard quickfix but you can provide your
own intention action that will be displayed next to the standard quickfix
and generate the extra code that you need. Intention actions implement the
IntentionAction interface; you can find plenty of examples of those in the
Community Edition source code and user plugins.
The standard "create method from usage" implementation is in CreateMethodFromUsageFix
in the Community Edition source code.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Thank you very much. That is exactly what I need.
By the way, could you please provide me with the link where I can download community edition source code :)
Hello Eugeny,
http://www.jetbrains.org/
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"