Search in sources :

Example 6 with RefactoringProcessor

use of org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor 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 } });
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IResourceMapper(org.eclipse.ltk.core.refactoring.IResourceMapper) ByteArrayInputStream(java.io.ByteArrayInputStream) RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) IJavaElementMapper(org.eclipse.jdt.core.refactoring.IJavaElementMapper) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IContainer(org.eclipse.core.resources.IContainer) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

RefactoringProcessor (org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor)6 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 ArrayList (java.util.ArrayList)3 IContainer (org.eclipse.core.resources.IContainer)3 IFolder (org.eclipse.core.resources.IFolder)3 IPath (org.eclipse.core.runtime.IPath)3 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)3 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)3 ProcessorBasedRefactoring (org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring)3 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 IJavaElementMapper (org.eclipse.jdt.core.refactoring.IJavaElementMapper)2 IResourceMapper (org.eclipse.ltk.core.refactoring.IResourceMapper)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 List (java.util.List)1