• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.jf.smalidea;
2 
3 import com.intellij.openapi.roots.JavaProjectRootsUtil;
4 import com.intellij.openapi.vfs.VirtualFile;
5 import com.intellij.psi.PsiClass;
6 import com.intellij.psi.search.GlobalSearchScope;
7 import com.intellij.refactoring.MultiFileTestCase;
8 import com.intellij.refactoring.PackageWrapper;
9 import com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination;
10 import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor;
11 import org.jetbrains.annotations.NotNull;
12 
13 import java.util.List;
14 
15 public class ClassMoveTest extends MultiFileTestCase {
16     @Override
getTestDataPath()17     protected String getTestDataPath() {
18         return "testData";
19     }
20 
21     @NotNull
22     @Override
getTestRoot()23     protected String getTestRoot() {
24         return "/classMove/";
25     }
26 
testBasicFromNoPackage()27     public void testBasicFromNoPackage() {
28         doTest("blah", "my");
29     }
30 
testBasicToNoPackage()31     public void testBasicToNoPackage() {
32         doTest("my.blah", "");
33     }
34 
doTest(@otNull final String oldQualifiedName, @NotNull final String newPackage)35     private void doTest(@NotNull final String oldQualifiedName, @NotNull final String newPackage) {
36         doTest(new PerformAction() {
37             @Override
38             public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
39                 doMove(oldQualifiedName, newPackage);
40             }
41         });
42     }
43 
doMove(String oldQualifiedName, final String newPackage)44     private void doMove(String oldQualifiedName, final String newPackage) throws Exception {
45         final PsiClass testClass = myJavaFacade.findClass(oldQualifiedName, GlobalSearchScope.allScope(getProject()));
46 
47         final List<VirtualFile> contentSourceRoots =
48                 JavaProjectRootsUtil.getSuitableDestinationSourceRoots(getProject());
49 
50         new MoveClassesOrPackagesProcessor(getProject(), new PsiClass[] {testClass},
51                 new AutocreatingSingleSourceRootMoveDestination(new PackageWrapper(getPsiManager(), newPackage),
52                         contentSourceRoots.get(0)), false, false, null).run();
53     }
54 
55 }
56