I am developing an application [desktop swing application] which requires me to do refactoring via code. [I know the interface and feature is already provided by the eclipse IDE but I am required to do this via code
the first phase of refactoring that i require to do is move selected package [the option to select is given via checkboxes that displays all the available packages in the workspace using the idea of JDT. I used tutorial at this location: http://www.vogella.de/articles/EclipseJDT/article.html ]
Now that I have selected the packages that I wish to move to another package,
I used this piece of code
233. for (IPackageFragment mypackage : packages) {
234. if ((mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) && (searchifSelected(mypackage.getElementName())==true) ){
235. IJavaElement container = newModule.getPrimaryElement();
236. mypackage.move(container, null, null, true, null);
}
}
searchifSelected(mypackage.getElementName())==true tells me if I have selected this particular package to be moved
IJavaElement container = newModule.getPrimaryElement(); is the container [new package] that will contain the selected packages
mypackage.move(container, null, null, true, null); as far as I read it, this command is supposed to move "mypackage" to "container" as a "child".
however, I am facing this problem:
Java Model Exception: Java Model Status [Invalid destination: 'devFromSupplier [in src [in test]]']
at org.eclipse.jdt.internal.core.MultiOperation.processElements(MultiOperation.java:175)
at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElements(CopyResourceElementsOperation.java:417)
at org.eclipse.jdt.internal.core.MultiOperation.executeOperation(MultiOperation.java:90)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:793)
at org.eclipse.jdt.internal.core.JavaModel.runOperation(JavaModel.java:297)
at org.eclipse.jdt.internal.core.JavaModel.move(JavaModel.java:258)
at org.eclipse.jdt.internal.core.PackageFragment.move(PackageFragment.java:420)
at newmodulewizrd.ui.Integrate.printPackageInfos(Integrate.java:236)
at newmodulewizrd.ui.Integrate.printProjectInfo(Integrate.java:177)
at newmodulewizrd.ui.Integrate.getWorkSpace(Integrate.java:149)
at newmodulewizrd.ui.Integrate.moveToOneModule(Integrate.java:120)
at newmodulewizrd.ui.Integrate$1.actionPerformed(Integrate.java:79)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
which I think means that I am giving the wrong arguments.
can somebody help what should I do about it?
For those who r facing the same problem, i found another way to do it, i.e use rename method and make it work as move function. although, it might/might not be the best option.
i replace above code with this code
for (IPackageFragment mypackage : packages) {
if ((mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) && (searchifSelected(mypackage.getElementName())==true) ){
mypackage.rename(textfield.getText()+"."+mypackage.getElementName(), true, null);
}
}