Use of the extract method operation programatically

Hello,

I try to use the refactoring operation programatically but I receive always the followinf exception:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[  17535]  ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(330,54),absolute(785,78),button=1,modifiers=Button1,clickCount=1] on frame0
java.lang.NullPointerException  at com.intellij.refactoring.extractMethod.ExtractMethodProcessor.doRefactoring(ExtractMethodProcessor.java:525)

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


The code I defined to perform this operation is:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

PsiElement[] elements = method.getBody().getStatements()[0].getChildren();// method is the method from which I like to extract the new method.

ExtractMethodProcessor extractMethodProcessor = new ExtractMethodProcessor(project, editor,elements,null,"accept",method.getName(),HelpID.EXTRACT_METHOD);

extractMethodProcessor.doRefactoring();


--------------------------------------------------------------------------------------------------------------------------------------------------------


Is there one who could know what is wrong here or is there a person who used this operation before?


Thanks

3 comments
Comment actions Permalink

Please specify the exact version number of IntelliJ IDEA that you're using.

0
Comment actions Permalink

I am using the version 11.0

0
Comment actions Permalink

You have not called the prepare() method on ExtractMethodProcessor. As I already mentioned, you can find examples of using the refactoring API correctly in the refactoring tests in the IntelliJ IDEA Community Edition codebase.

0

Please sign in to leave a comment.