diff --git a/java/java-tests/testSrc/com/intellij/refactoring/FixMethodJavadocTest.java b/java/java-tests/testSrc/com/intellij/refactoring/FixMethodJavadocTest.java new file mode 100644 index 000000000000..0a8937f7bcb0 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/refactoring/FixMethodJavadocTest.java @@ -0,0 +1,58 @@ +package com.intellij.refactoring; + +import com.intellij.FileSetTestCase; +import com.intellij.psi.*; +import com.intellij.refactoring.util.RefactoringUtil; +import com.intellij.util.containers.HashSet; +import junit.framework.Test; + +import java.io.File; +import java.net.URL; +import java.util.Arrays; +import java.util.Set; + +/** + * @author dsl + */ +public abstract class FixMethodJavadocTest extends FileSetTestCase { + FixMethodJavadocTest() { + super(findPath()); + } + + private static String findPath() { + final URL res = FixMethodJavadocTest.class.getResource("/" + FixMethodJavadocTest.class.getName().replace('.', '/') + ".class"); + File f = new File(res.getFile()); + String result = f.getParent() + File.separatorChar + "methodJavaDocData"; + result = result.replaceAll("classes", ""); + return result; + } + + @Override + public String transform(String testName, String[] data) throws Exception { + final PsiManager manager = PsiManager.getInstance(myProject); + final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); + final PsiMethod method = factory.createMethodFromText(data[0], null); + final HashSet newParameters = new HashSet(); + if (data.length == 2) { + final String[] strings = data[1].split("\\s+"); + collectNewParameters(method, strings, newParameters); + } + RefactoringUtil.fixJavadocsForParams(method, newParameters); + return method.getText(); + } + + private void collectNewParameters(PsiMethod method, String[] names, Set newParameters) { + Set newNames = new HashSet(Arrays.asList(names)); + final PsiParameter[] parameters = method.getParameterList().getParameters(); + for (int i = 0; i < parameters.length; i++) { + PsiParameter parameter = parameters[i]; + if (newNames.contains(parameter.getName())) { + newParameters.add(parameter); + } + } + } + + public static Test suite() { + return new FixMethodJavadocTest(){}; + } +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/RenamePackageTest.java b/java/java-tests/testSrc/com/intellij/refactoring/RenamePackageTest.java new file mode 100644 index 000000000000..c3782af2980e --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/refactoring/RenamePackageTest.java @@ -0,0 +1,63 @@ +package com.intellij.refactoring; + +import com.intellij.codeInsight.CodeInsightTestCase; +import com.intellij.openapi.application.ex.PathManagerEx; +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.JavaPsiFacade; +import com.intellij.psi.PsiPackage; +import com.intellij.refactoring.rename.RenameProcessor; +import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.testFramework.PsiTestUtil; + +import java.io.File; + +public class RenamePackageTest extends CodeInsightTestCase { + public void testJspImport() throws Exception { + doTest("jspImport", "pack1", "pack2"); + } + + public void testNonJava() throws Exception { + doTest("nonJava", "com.foo", "fooNew"); + } + + public void testInBrokenXml() throws Exception { + doTest("inBrokenXml", "somepckg", "somepckg1"); + } + + + public void testJsp() throws Exception { + doTest("jsp", "pack1", "pack2"); + } + + private void doTest(String testName, String packageName, String newPackageName) throws Exception { + String root = PathManagerEx.getTestDataPath()+ "/refactoring/renamePackage/" + testName; + + String rootBefore = root + "/before"; + PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17()); + VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, rootBefore, myFilesToDelete); + + performAction(packageName, newPackageName); + + String rootAfter = root + "/after"; + VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/')); + IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir, IdeaTestUtil.CVS_FILE_FILTER); + } + + private void performAction(String packageName, String newPackageName) throws Exception { + PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage(packageName); + assertNotNull("Package " + packageName + " not found", aPackage); + + //PsiDirectory dir = aPackage.getDirectories()[0]; + //it is now impossible to rename dir without renaming corresponding package via rename processor - move processor would be used instead + new RenameProcessor(myProject, aPackage, newPackageName, true, true).run(); + FileDocumentManager.getInstance().saveAllDocuments(); + } + + @Override + protected boolean isRunInWriteAction() { + return false; + } +}