2011-11-29 59 views
3

我正在開發一個應用程序[桌面擺動應用程序],它需要我通過代碼進行重構。 [我知道的界面和功能已經由Eclipse IDE 提供,但我通過代碼來做到這一點需要如何在java中使用代碼將一個或多個包正確地移動到另一個包中

重構的第一階段,我需要做的是移動選擇套裝[選擇給出選項通過複選框使用JDT的想法顯示工作區中的所有可用軟件包。我在此位置使用教程:http://www.vogella.de/articles/EclipseJDT/article.html]

現在,我已經選擇了我想移動到另一個包的包,

我用這段代碼

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告訴我是否選擇了要移動的特定程序包

IJavaElement container = newModule.getPrimaryE字元素();是包含所選包的容器[新包]

mypackage.move(container,null,null,true,null);就我看來,這個命令應該把「mypackage」移動到「container」作爲「孩子」。

不過,我面臨這個問題:

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) 

,我認爲我給了錯誤的論據手段。

有人可以幫我應該怎麼做嗎?

+0

可以包括行號到您的代碼段.. – rana

+0

我很抱歉,我沒有得到烏爾點? – user

+0

@ rana,我已添加行號 – user

回答

0

對於那些誰[R面臨同樣的問題,我發現了另一種方式來做到這一點,即使用重命名方法,並使其發揮作用作爲移動功能。儘管它可能/可能不是最好的選擇。

我替換上面的代碼,此代碼

 for (IPackageFragment mypackage : packages) { 
       if ((mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) && (searchifSelected(mypackage.getElementName())==true)){ 
        mypackage.rename(textfield.getText()+"."+mypackage.getElementName(), true, null); 
       } 
      } 
1

我在eclipse論壇[我正在使用的IDE]上發佈了這個問題,然後發現問題/ bug在循環中不起作用。你將不得不一一明確地調用這個函數。類似的bug已經在這個環節也被報道:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=240286 [WRT刪除方法]

相關問題