use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class ValidateEditTests method testPackageRename1.
@Test
public void testPackageRename1() throws Exception {
IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
StringBuilder buf = new StringBuilder();
buf.append("package org.test;\n");
buf.append("class A {\n");
buf.append("}\n");
ICompilationUnit cu1 = fragment.createCompilationUnit("A.java", buf.toString(), true, null);
setReadOnly(cu1);
buf = new StringBuilder();
buf.append("package org.test;\n");
buf.append("class B {\n");
buf.append("}\n");
ICompilationUnit cu2 = fragment.createCompilationUnit("B.java", buf.toString(), true, null);
setReadOnly(cu2);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
descriptor.setJavaElement(fragment);
descriptor.setNewName("org.test2");
descriptor.setUpdateReferences(true);
RefactoringStatus status = performRefactoring(descriptor);
if (status != null)
assertTrue(status.toString(), status.isOK());
Collection<IPath> validatedEditPaths = RefactoringTestRepositoryProvider.getValidatedEditPaths(getRoot().getJavaProject().getProject());
assertEquals(2, validatedEditPaths.size());
assertTrue(validatedEditPaths.contains(cu1.getPath()));
assertTrue(validatedEditPaths.contains(cu2.getPath()));
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class ValidateEditTests method testPackageRenameWithResource2.
@Test
public void testPackageRenameWithResource2() throws Exception {
// MyClass readonly and moved, x.properties readonly moved
IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
StringBuilder buf = new StringBuilder();
buf.append("package org.test;\n");
buf.append("public class MyClass {\n");
buf.append("}\n");
ICompilationUnit cu1 = fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
setReadOnly(cu1);
IFile file = ((IFolder) fragment.getResource()).getFile("x.properties");
byte[] content = "This is about 'org.test' and more".getBytes();
file.create(new ByteArrayInputStream(content), true, null);
file.refreshLocal(IResource.DEPTH_ONE, null);
setReadOnly(file);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
descriptor.setJavaElement(fragment);
descriptor.setNewName("org.test2");
descriptor.setUpdateReferences(true);
descriptor.setUpdateQualifiedNames(true);
descriptor.setFileNamePatterns("*.properties");
RefactoringStatus status = performRefactoring(descriptor);
if (status != null)
assertTrue(status.toString(), status.isOK());
Collection<IPath> validatedEditPaths = RefactoringTestRepositoryProvider.getValidatedEditPaths(getRoot().getJavaProject().getProject());
assertEquals(2, validatedEditPaths.size());
assertTrue(validatedEditPaths.contains(cu1.getPath()));
assertTrue(validatedEditPaths.contains(file.getFullPath()));
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class ValidateEditTests method testTypeRename.
@Test
public void testTypeRename() throws Exception {
IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
StringBuilder buf = new StringBuilder();
buf.append("package org.test;\n");
buf.append("public class MyClass {\n");
buf.append("}\n");
ICompilationUnit cu1 = fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
setReadOnly(cu1);
buf = new StringBuilder();
buf.append("package org.test;\n");
buf.append("public class C extends MyClass {\n");
buf.append("}\n");
ICompilationUnit cu2 = fragment.createCompilationUnit("C.java", buf.toString(), true, null);
setReadOnly(cu2);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
descriptor.setJavaElement(cu1.findPrimaryType());
descriptor.setNewName("MyClass2");
descriptor.setUpdateReferences(true);
RefactoringStatus status = performRefactoring(descriptor);
if (status != null)
assertTrue(status.toString(), status.isOK());
Collection<IPath> validatedEditPaths = RefactoringTestRepositoryProvider.getValidatedEditPaths(getRoot().getJavaProject().getProject());
assertEquals(2, validatedEditPaths.size());
assertTrue(validatedEditPaths.contains(cu1.getPath()));
assertTrue(validatedEditPaths.contains(cu2.getPath()));
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class RenameTypeTests method initWithAllOptions.
private RefactoringDescriptor initWithAllOptions(String oldName, String innerOldName, String innerNewName, boolean updateReferences, boolean updateTextualMatches, boolean updateSimilar, String nonJavaFiles, int matchStrategy) throws Exception, JavaModelException, CoreException {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldName);
IType classA = getType(cu, innerOldName);
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, innerNewName);
setTheOptions(descriptor, updateReferences, updateTextualMatches, updateSimilar, nonJavaFiles, matchStrategy);
return descriptor;
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.
the class RenameTypeTests method helperWithTextual.
private String[] helperWithTextual(String oldCuName, String oldName, String newName, String newCUName, boolean updateReferences, boolean updateTextualMatches) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldCuName);
IType classA = getType(cu, oldName);
IJavaElement[] classAMembers = classA.getChildren();
IPackageFragment pack = (IPackageFragment) cu.getParent();
String[] renameHandles = null;
if (classA.getDeclaringType() == null && cu.getElementName().startsWith(classA.getElementName())) {
renameHandles = ParticipantTesting.createHandles(classA, cu, cu.getResource());
} else {
renameHandles = ParticipantTesting.createHandles(classA);
}
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, newName);
descriptor.setUpdateReferences(updateReferences);
descriptor.setUpdateTextualOccurrences(updateTextualMatches);
Refactoring refactoring = createRefactoring(descriptor);
assertNull("was supposed to pass", performRefactoring(refactoring));
ICompilationUnit newcu = pack.getCompilationUnit(newCUName + ".java");
assertTrue("cu " + newcu.getElementName() + " does not exist", newcu.exists());
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName(newCUName)), newcu.getSource());
INameUpdating nameUpdating = refactoring.getAdapter(INameUpdating.class);
IType newElement = (IType) nameUpdating.getNewElement();
assertTrue("new element does not exist:\n" + newElement.toString(), newElement.exists());
checkMappers(refactoring, classA, newCUName + ".java", classAMembers);
return renameHandles;
}
Aggregations