mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
compilation fix after community/ultimate tests refactorings
This commit is contained in:
@@ -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<PsiParameter> newParameters = new HashSet<PsiParameter>();
|
||||
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<PsiParameter> newParameters) {
|
||||
Set<String> newNames = new HashSet<String>(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(){};
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user