use of org.eclipse.ltk.core.refactoring.IResourceMapper in project che by eclipse.
the class RenamePackageTest method testPackageRenameWithResource1.
@Test
public void testPackageRenameWithResource1() throws Exception {
IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
StringBuffer buf = new StringBuffer();
buf.append("package org.test;\n");
buf.append("public class MyClass {\n");
buf.append(" org.test.MyClass me;\n");
buf.append("}\n");
fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
IFile file = ((IFolder) getRoot().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);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
descriptor.setJavaElement(fragment);
descriptor.setNewName("org.test2");
descriptor.setUpdateReferences(true);
descriptor.setUpdateQualifiedNames(true);
descriptor.setFileNamePatterns("*.properties");
Refactoring refactoring = createRefactoring(descriptor);
RefactoringStatus status = performRefactoring(refactoring);
if (status != null)
assertTrue(status.toString(), status.isOK());
RefactoringProcessor processor = ((RenameRefactoring) refactoring).getProcessor();
IResourceMapper rm = (IResourceMapper) processor.getAdapter(IResourceMapper.class);
IJavaElementMapper jm = (IJavaElementMapper) processor.getAdapter(IJavaElementMapper.class);
checkMappingUnchanged(jm, rm, new Object[] { getRoot().getJavaProject(), getRoot(), file });
IFile newFile = ((IContainer) getRoot().getResource()).getFile(new Path("x.properties"));
assertEquals("This is about 'org.test2' and more", getContents(newFile));
checkMappingChanged(jm, rm, new Object[][] { { fragment, getRoot().getPackageFragment("org.test2") } });
}
use of org.eclipse.ltk.core.refactoring.IResourceMapper in project che by eclipse.
the class RenamePackageTest method test1.
//-------
@Test
public void test1() throws Exception {
fIsPreDeltaTest = true;
RenamePackageProcessor proc = helper2(new String[] { "r" }, new String[][] { { "A" } }, "p1");
IJavaElementMapper jm = (IJavaElementMapper) proc.getAdapter(IJavaElementMapper.class);
IResourceMapper rm = (IResourceMapper) proc.getAdapter(IResourceMapper.class);
IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
IJavaProject project = getRoot().getJavaProject();
IFile _project = project.getProject().getFile(".project");
checkMappingUnchanged(jm, rm, new Object[] { project, _project, getRoot(), getPackageP(), getRoot().getPackageFragment("inexistent"), getRoot().getPackageFragment("r.inexistent"), getRoot().getPackageFragment("p1.inexistent") });
IPackageFragment r = getRoot().getPackageFragment("p1");
ICompilationUnit r_A = r.getCompilationUnit("A.java");
IType r_A_A = r_A.getType("A");
IField r_A_A_a = r_A_A.getField("a");
IPackageFragment p1 = getRoot().getPackageFragment("p1");
ICompilationUnit p1_A = p1.getCompilationUnit("A.java");
IType p1_A_A = p1_A.getType("A");
IField p1_A_A_a = p1_A_A.getField("a");
checkMappingChanged(jm, rm, new Object[][] { { r, p1 }, { r_A, p1_A }, { r_A_A, p1_A_A }, { r_A_A_a, p1_A_A_a } });
}
use of org.eclipse.ltk.core.refactoring.IResourceMapper in project che by eclipse.
the class RenamePackageTest method testPackageRenameWithResource2.
// ---------- tests -------------
@Test
public void testPackageRenameWithResource2() throws Exception {
IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
StringBuffer buf = new StringBuffer();
buf.append("package org.test;\n");
buf.append("public class MyClass {\n");
buf.append("}\n");
fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
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);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
descriptor.setJavaElement(fragment);
descriptor.setNewName("org.test2");
descriptor.setUpdateReferences(true);
descriptor.setUpdateHierarchy(true);
descriptor.setUpdateQualifiedNames(true);
descriptor.setFileNamePatterns("*.properties");
Refactoring refactoring = createRefactoring(descriptor);
RefactoringStatus status = performRefactoring(refactoring);
if (status != null)
assertTrue(status.toString(), status.isOK());
RefactoringProcessor processor = ((RenameRefactoring) refactoring).getProcessor();
IResourceMapper rm = (IResourceMapper) processor.getAdapter(IResourceMapper.class);
IJavaElementMapper jm = (IJavaElementMapper) processor.getAdapter(IJavaElementMapper.class);
checkMappingUnchanged(jm, rm, new Object[] { getRoot().getJavaProject(), getRoot() });
IPackageFragment newFragment = getRoot().getPackageFragment("org.test2");
IFile newFile = ((IContainer) newFragment.getResource()).getFile(new Path("x.properties"));
assertEquals("This is about 'org.test2' and more", getContents(newFile));
checkMappingChanged(jm, rm, new Object[][] { { file, newFile } });
}
Aggregations