use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class ConfigurationsTest method testRenameMethod.
@Test
public void testRenameMethod() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final String className = psiClass.getName();
final TestNGConfiguration configuration = createConfiguration(project);
final PsiMethod method = findTestMethod(psiClass);
configuration.beMethodConfiguration(new PsiLocation<>(project, method));
final String newMethodName = "renamedTest";
final RenameRefactoring renameMethod = RefactoringFactory.getInstance(project).createRename(method, newMethodName);
renameMethod.setSearchInComments(false);
renameMethod.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameMethod.run();
}
}.execute();
Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
final PsiMethod notATestMethod = findNotATestMethod(psiClass);
final RenameRefactoring renameNotATestMethod1 = RefactoringFactory.getInstance(project).createRename(notATestMethod, "bbbbb");
renameNotATestMethod1.setSearchInComments(false);
renameNotATestMethod1.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameNotATestMethod1.run();
}
}.execute();
Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class ConfigurationsTest method testClassRename.
@Test
public void testClassRename() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final TestNGConfiguration configuration = createConfiguration(project);
configuration.beClassConfiguration(psiClass);
final String newName = "Testt1";
final RenameRefactoring renameClass = RefactoringFactory.getInstance(project).createRename(psiClass, newName);
renameClass.setSearchInComments(false);
renameClass.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameClass.run();
}
}.execute();
Assert.assertEquals(newName, configuration.getPersistantData().getMainClassName());
final PsiMethod notATestMethod = findNotATestMethod(psiClass);
final RenameRefactoring renameNotATestMethod = RefactoringFactory.getInstance(project).createRename(notATestMethod, "aaaa");
renameNotATestMethod.setSearchInComments(false);
renameNotATestMethod.setSearchInNonJavaFiles(false);
new WriteCommandAction(project) {
protected void run(@NotNull final Result result) throws Throwable {
renameNotATestMethod.run();
}
}.execute();
Assert.assertEquals(configuration.getPersistantData().getMainClassName(), newName);
Assert.assertEquals(configuration.getPersistantData().getMethodName(), "");
Assert.assertEquals(configuration.getPersistantData().TEST_OBJECT, TestType.CLASS.getType());
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class JavaFXRenameTest method testStaticPropertyMethod.
public void testStaticPropertyMethod() throws Exception {
final String className = "container.MyCustomContainer";
final String methodName = "setStaticProp";
final String newName = "setNewMethodName";
myFixture.configureByFiles(getTestName(true) + ".fxml", className.replace('.', '/') + ".java");
final PsiClass psiClass = myFixture.findClass(className);
assertNotNull(psiClass);
final PsiMethod[] methods = psiClass.findMethodsByName(methodName, false);
assertEquals(1, methods.length);
final PsiMethod method = methods[0];
final RenameRefactoring rename = new JavaRenameRefactoringImpl(getProject(), method, newName, false, false);
rename.run();
myFixture.checkResultByFile(getTestName(true) + "_after.fxml");
assertMethodExists(psiClass, newName);
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class JavaFxPropertyRenameHandler method doRename.
private static void doRename(JavaFxPropertyReference reference, String newName, final boolean searchInComments, boolean isPreview) {
final PsiElement psiElement = JavaFxPropertyElement.fromReference(reference);
if (psiElement == null)
return;
final RenameRefactoring rename = new JavaRenameRefactoringImpl(psiElement.getProject(), psiElement, newName, searchInComments, false);
rename.setPreviewUsages(isPreview);
final Map<PsiElement, String> elementsToRename = getElementsToRename(reference, newName);
elementsToRename.forEach(rename::addElement);
rename.run();
}
use of com.intellij.refactoring.RenameRefactoring in project intellij-community by JetBrains.
the class RncRenameTest method testRenameIncludedFile.
public void testRenameIncludedFile() throws Throwable {
myTestFixture.copyFileToProject("rename-in-include-ref.rnc");
final Project project = myTestFixture.getProject();
final RefactoringFactory factory = RefactoringFactory.getInstance(project);
String fullPath = myTestFixture.getTempDirPath() + "/" + "rename-in-include-ref.rnc";
final VirtualFile copy = LocalFileSystem.getInstance().refreshAndFindFileByPath(fullPath.replace(File.separatorChar, '/'));
assert copy != null : "file " + fullPath + " not found";
final PsiFile file = PsiManager.getInstance(project).findFile(copy);
assertNotNull(file);
myTestFixture.configureByFile("rename-in-include.rnc");
final RenameRefactoring refactoring = factory.createRename(file, "rename-after.rnc");
refactoring.setPreviewUsages(false);
refactoring.setSearchInComments(false);
refactoring.setSearchInNonJavaFiles(true);
refactoring.run();
myTestFixture.checkResultByFile("rename-in-include_after.rnc");
assertEquals("rename-after.rnc", file.getName());
}
Aggregations