Permalink
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
2 parents 5b3ec6e + 2b6a350 commit 4370db0c0b19ea0d2a8635f95149d30ad859db4e @Lugzan Lugzan committed Oct 3, 2012
Showing 508 changed files with 0 additions and 3,856 deletions.
@@ -1,115 +0,0 @@
-package org.jetbrains.plugins.scala.lang.refactoring;
-
-import com.intellij.codeInsight.CodeInsightTestCase;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
-import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
-import com.intellij.openapi.vfs.LocalFileSystem;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.*;
-import com.intellij.psi.impl.source.PostprocessReformattingAspect;
-import com.intellij.psi.search.ProjectScope;
-import com.intellij.refactoring.copy.CopyClassesHandler;
-import com.intellij.testFramework.PlatformTestUtil;
-import com.intellij.testFramework.PsiTestUtil;
-import com.intellij.util.IncorrectOperationException;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-
-/**
- * @author yole
- */
-public class CopyClassTest extends CodeInsightTestCase {
- private VirtualFile myRootDir;
-
- public void testReplaceAllOccurrences() throws Exception {
- doTest("Foo", "Bar");
- }
-
- // TODO
-// public void testLibraryClass() throws Exception { // IDEADEV-28791
-// doTest("java.util.ArrayList", "Bar");
-// }
-
- private void doTest(final String oldName, final String copyName) throws Exception {
- String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/" + getTestName(true);
-
- PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("java 1.5"));
- myRootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
-
- PsiElement element = performAction(oldName, copyName);
-
- myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
- FileDocumentManager.getInstance().saveAllDocuments();
-
- VirtualFile fileAfter = myRootDir.findChild(copyName + ".java");
- VirtualFile fileExpected = myRootDir.findChild(copyName + ".expected.java");
-
- PlatformTestUtil.assertFilesEqual(fileExpected, fileAfter);
- }
-
- private PsiElement performAction(final String oldName, final String copyName) throws IncorrectOperationException {
- PsiClass oldClass = JavaPsiFacade.getInstance(myProject).findClass(oldName, ProjectScope.getAllScope(myProject));
- return CopyClassesHandler.doCopyClasses(Collections.singletonMap(oldClass.getNavigationElement().getContainingFile(), new PsiClass[]{oldClass}), copyName, myPsiManager.findDirectory(myRootDir),
- myProject);
- }
-
- public void testPackageLocalClasses() throws Exception {
- doMultifileTest();
- }
-
- public void testPackageLocalMethods() throws Exception {
- doMultifileTest();
- }
-
- //copy all classes from p1 -> p2
- private void doMultifileTest() throws Exception {
- String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
- String rootBefore = root + "/before";
- PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
- VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
-
- final HashMap<PsiFile, PsiClass[]> map = new HashMap<PsiFile, PsiClass[]>();
- final VirtualFile sourceDir = rootDir.findChild("p1");
- for (VirtualFile file : sourceDir.getChildren()) {
- final PsiFile psiFile = myPsiManager.findFile(file);
- if (psiFile instanceof PsiJavaFile) {
- map.put(psiFile, ((PsiJavaFile)psiFile).getClasses());
- }
- }
-
- final VirtualFile targetVDir = rootDir.findChild("p2");
- CopyClassesHandler.doCopyClasses(map, null, myPsiManager.findDirectory(targetVDir), myProject);
-
- String rootAfter = root + "/after";
- VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
- myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
- PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir, PlatformTestUtil.CVS_FILE_FILTER);
- }
-
- public void testPackageHierarchy() throws Exception {
- doPackageCopy();
- }
-
- public void testPackageOneLevelHierarchy() throws Exception {
- doPackageCopy();
- }
-
- private void doPackageCopy() throws Exception {
- String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/copyClass/multifile/" + getTestName(true);
- String rootBefore = root + "/before";
- PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
- VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
-
- final VirtualFile targetVDir = rootDir.findChild("p2");
- final PsiDirectory sourceP1Dir = myPsiManager.findDirectory(rootDir.findChild("p1"));
- final PsiDirectory targetP2Dir = myPsiManager.findDirectory(targetVDir);
- new CopyClassesHandler().doCopy(new PsiElement[]{sourceP1Dir}, targetP2Dir);
-
- String rootAfter = root + "/after";
- VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
- myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
- PlatformTestUtil.assertDirectoriesEqual(rootDir2, rootDir, PlatformTestUtil.CVS_FILE_FILTER);
- }
-}
@@ -1,95 +0,0 @@
-/*
- * Copyright 2000-2011 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.scala.lang.refactoring;
-
-import com.intellij.codeInsight.CodeInsightTestCase;
-import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.*;
-import com.intellij.refactoring.copy.CopyHandler;
-import com.intellij.testFramework.PlatformTestUtil;
-import com.intellij.testFramework.PsiTestUtil;
-
-public class CopyTest extends CodeInsightTestCase {
-
- private String getRoot() {
- return JavaTestUtil.getJavaTestDataPath() + "/refactoring/copy/multifile/" + getTestName(true);
- }
-
- public void testCopyAvailable() throws Exception {
- doTest();
- }
-
- public void testJavaAndTxt() throws Exception {
- doTest();
- }
-
- private void doTest() throws Exception {
- String rootBefore = getRoot();
- PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
- PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
- PsiPackage pack1 = myJavaFacade.findPackage("pack1");
- PsiPackage pack2 = myJavaFacade.findPackage("pack2");
- assertTrue(CopyHandler.canCopy(new PsiElement[]{pack1.getDirectories()[0], pack2.getDirectories()[0]}));
- }
-
- public void testMultipleClasses() throws Exception {
- String rootBefore = getRoot();
- PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
- final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
- final PsiClass aClass = myJavaFacade.findClass("pack1.Klass");
- assertNotNull(aClass);
-
- final PsiFile containingFile = aClass.getContainingFile();
-
- assertTrue(CopyHandler.canCopy(new PsiElement[]{containingFile}));
- assertFalse(CopyHandler.canClone(new PsiElement[]{containingFile}));
-
- PsiPackage pack2 = myJavaFacade.findPackage("pack2");
- final PsiDirectory targetDirectory = pack2.getDirectories()[0];
- CopyHandler.doCopy(new PsiElement[]{containingFile}, targetDirectory);
-
- VirtualFile fileAfter = root.findFileByRelativePath("pack2/Klass.java");
- VirtualFile fileExpected = root.findFileByRelativePath("pack2/Klass.expected.java");
-
- PlatformTestUtil.assertFilesEqual(fileExpected, fileAfter);
- }
-
- public void testMultipleFiles() throws Exception {
- String rootBefore = getRoot();
- PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
- final VirtualFile root = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
-
- final VirtualFile first = root.findFileByRelativePath("from/1.txt");
- assertNotNull(first);
- final VirtualFile second = root.findFileByRelativePath("from/2.txt");
- assertNotNull(second);
-
- final PsiFile firstPsi = myPsiManager.findFile(first);
- final PsiFile secondPsi = myPsiManager.findFile(second);
-
- assertTrue(CopyHandler.canCopy(new PsiElement[]{firstPsi, secondPsi}));
-
- final VirtualFile toDir = root.findChild("to");
- assertNotNull(toDir);
- final PsiDirectory targetDirectory = myPsiManager.findDirectory(toDir);
-
- CopyHandler.doCopy(new PsiElement[]{firstPsi, secondPsi}, targetDirectory);
-
- assertNotNull(root.findFileByRelativePath("to/1.txt"));
- assertNotNull(root.findFileByRelativePath("to/2.txt"));
- }
-}
@@ -1,56 +0,0 @@
-package org.jetbrains.plugins.scala.lang.refactoring;
-
-import com.intellij.codeInsight.CodeInsightTestCase;
-import com.intellij.openapi.util.Computable;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiDirectory;
-import com.intellij.psi.PsiDocumentManager;
-import com.intellij.psi.PsiElement;
-import com.intellij.refactoring.move.MoveHandler;
-import com.intellij.testFramework.PsiTestUtil;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * User: anna
- * Date: Aug 31, 2010
- */
-public class DndMoveTest extends CodeInsightTestCase {
- @Override
- protected String getTestRoot() {
- return "/refactoring/dndMove/";
- }
-
- public void testPublicJavaClass() throws Exception {
- doTest("d", new Computable<PsiElement>() {
- @Nullable
- @Override
- public PsiElement compute() {
- return JavaPsiFacade.getInstance(getProject()).findClass("d.MyClass");
- }
- }, true);
- }
-
- public void testSecondJavaClass() throws Exception {
- doTest("d", new Computable<PsiElement>() {
- @Nullable
- @Override
- public PsiElement compute() {
- return JavaPsiFacade.getInstance(getProject()).findClass("d.Second");
- }
- }, false);
- }
-
-
- private void doTest(final String targetDirName, final Computable<PsiElement> source, final boolean expected) throws Exception {
- String testName = getTestName(true);
- String root = JavaTestUtil.getJavaTestDataPath() + getTestRoot() + testName;
- VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete, false);
- PsiTestUtil.addSourceContentToRoots(myModule, rootDir);
- PsiDocumentManager.getInstance(myProject).commitAllDocuments();
- final VirtualFile child1 = rootDir.findChild(targetDirName);
- assertNotNull("File " + targetDirName + " not found", child1);
- final PsiDirectory targetDirectory = myPsiManager.findDirectory(child1);
- assertEquals(expected, MoveHandler.isMoveRedundant(source.compute(), targetDirectory));
- }
-}
@@ -1,11 +0,0 @@
-package org.jetbrains.plugins.scala.lang.refactoring;
-
-import org.jetbrains.plugins.scala.util.TestUtils;
-
-import java.io.File;
-
-public class JavaTestUtil {
- static String getJavaTestDataPath() {
- return TestUtils.getTestDataPath();
- }
-}
@@ -1,84 +0,0 @@
-/*
- * Copyright 2000-2010 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.scala.lang.refactoring;
-
-/**
- * User: anna
- * Date: Aug 31, 2010
- */
-
-import com.intellij.openapi.fileEditor.FileDocumentManager;
-import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
-import com.intellij.openapi.vfs.LocalFileSystem;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.*;
-import com.intellij.psi.impl.source.PostprocessReformattingAspect;
-import com.intellij.psi.search.GlobalSearchScope;
-import com.intellij.refactoring.move.moveFilesOrDirectories.JavaMoveFilesOrDirectoriesHandler;
-import com.intellij.testFramework.IdeaTestUtil;
-import com.intellij.testFramework.PsiTestUtil;
-
-import java.io.File;
-
-public class MoveClassAndFileTest extends RefactoringTestCase {
-
- public void testAllClassesInFile() throws Exception {
- doTest("allClassesInFile", "t", "txt2move.txt", "s.MyClass", "s.MyOneMoreClass");
- }
-
- public void testOnlyPackageLocalClass() throws Exception {
- doTest("onlyPackageLocalClass", "t", "txt2move.txt", "s.MyLocal");
- }
-
- public void testLeavePackageLocalClass() throws Exception {
- doTest("leavePackageLocalClass", "t", "txt2move.txt", "s.MyClass");
- }
-
- private void doTest(String testName, String newPackageName, String fileNameNearFirstClass, String... classNames) throws Exception {
- String root = JavaTestUtil.getJavaTestDataPath() + "/refactoring/moveClassAndFile/" + testName;
-
- String rootBefore = root + "/before";
- PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
- VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete);
-
- performAction(newPackageName, fileNameNearFirstClass, classNames);
-
- String rootAfter = root + "/after";
- VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
- myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
- IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER);
- }
-
- private void performAction(String newPackageName, String fileName, String... classNames) throws Exception{
- final PsiElement[] elements = new PsiElement[classNames.length + 1];
- for(int i = 0; i < classNames.length; i++){
- String className = classNames[i];
- elements[i] = myJavaFacade.findClass(className, GlobalSearchScope.projectScope(getProject()));
- assertNotNull("Class " + className + " not found", elements[i]);
- }
- elements[classNames.length] = elements[0].getContainingFile().getContainingDirectory().findFile(fileName);
-
- PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(newPackageName);
- assertNotNull("Package " + newPackageName + " not found", aPackage);
- final PsiDirectory[] dirs = aPackage.getDirectories();
- assertEquals(dirs.length, 1);
-
- new JavaMoveFilesOrDirectoriesHandler().doMove(getProject(), elements, dirs[0], null);
- PsiDocumentManager.getInstance(myProject).commitAllDocuments();
- FileDocumentManager.getInstance().saveAllDocuments();
- }
-}
-
Oops, something went wrong.

0 comments on commit 4370db0

Please sign in to comment.