Search in sources :

Example 1 with RenameSourceFolderChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange in project eclipse.jdt.ui by eclipse-jdt.

the class RenameSourceFolderChangeTests method test0.

@Test
public void test0() throws Exception {
    String oldName = "oldName";
    String newName = "newName";
    try {
        IJavaProject testProject = rts.getProject();
        IPackageFragmentRoot oldRoot = JavaProjectHelper.addSourceContainer(rts.getProject(), oldName);
        assertTrue("old folder should exist here", oldRoot.exists());
        RenameSourceFolderChange change = new RenameSourceFolderChange(oldRoot, newName);
        change.initializeValidationData(new NullProgressMonitor());
        performChange(change);
        assertFalse("old folder should not exist", oldRoot.exists());
        assertEquals("expected 3 pfr's", 3, testProject.getPackageFragmentRoots().length);
        IPackageFragmentRoot[] newRoots = testProject.getPackageFragmentRoots();
        for (int i = 0; i < newRoots.length; i++) {
            assertTrue("should exist " + i, newRoots[i].exists());
        }
    } finally {
        JavaProjectHelper.removeSourceContainer(rts.getProject(), newName);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameSourceFolderChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 2 with RenameSourceFolderChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange in project eclipse.jdt.ui by eclipse-jdt.

the class RenameSourceFolderChangeTests method testBug129991.

@Test
public void testBug129991() throws Exception {
    IJavaProject project = JavaProjectHelper.createJavaProject("RenameSourceFolder", "bin");
    try {
        IPath projectPath = project.getPath();
        IPath[] exclusion = new IPath[] { new Path("src/") };
        JavaProjectHelper.addToClasspath(project, JavaCore.newSourceEntry(projectPath, exclusion));
        IPackageFragmentRoot src = JavaProjectHelper.addSourceContainer(project, "src");
        RenameSourceFolderChange change = new RenameSourceFolderChange(src, "src2");
        change.initializeValidationData(new NullProgressMonitor());
        performChange(change);
        assertFalse("src should not exist", src.exists());
        assertEquals("expected 2 pfr's", 2, project.getPackageFragmentRoots().length);
        IClasspathEntry[] rawClasspath = project.getRawClasspath();
        assertEquals(projectPath, rawClasspath[0].getPath());
        assertEquals("src2/", rawClasspath[0].getExclusionPatterns()[0].toString());
        assertEquals(projectPath.append("src2/"), rawClasspath[1].getPath());
    } finally {
        JavaProjectHelper.delete(project.getProject());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameSourceFolderChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Example 3 with RenameSourceFolderChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange in project eclipse.jdt.ui by eclipse-jdt.

the class RenameSourceFolderProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 1);
    try {
        final IResource resource = fSourceFolder.getResource();
        final String project = resource.getProject().getName();
        final String newName = getNewElementName();
        final String description = Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description_short, JavaElementLabels.getElementLabel(fSourceFolder, JavaElementLabels.ALL_DEFAULT));
        final String header = Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getJavaElementName(newName) });
        final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
        final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_SOURCE_FOLDER);
        descriptor.setProject(project);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(RefactoringDescriptor.NONE);
        descriptor.setJavaElement(fSourceFolder);
        descriptor.setNewName(newName);
        return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameSourceFolderRefactoring_rename, new Change[] { new RenameSourceFolderChange(fSourceFolder, newName) });
    } finally {
        monitor.done();
    }
}
Also used : RenameSourceFolderChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IResource(org.eclipse.core.resources.IResource) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 4 with RenameSourceFolderChange

use of org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange in project eclipse.jdt.ui by eclipse-jdt.

the class RenameSourceFolderChangeTests method test1.

@Test
public void test1() throws Exception {
    String oldName1 = "oldName1";
    String oldName2 = "oldName2";
    String newName1 = "newName";
    try {
        IJavaProject testProject = rts.getProject();
        IPackageFragmentRoot oldRoot1 = JavaProjectHelper.addSourceContainer(rts.getProject(), oldName1);
        IPackageFragmentRoot oldRoot2 = JavaProjectHelper.addSourceContainer(rts.getProject(), oldName2);
        assertTrue("old folder should exist here", oldRoot1.exists());
        assertTrue("old folder 2 should exist here", oldRoot2.exists());
        RenameSourceFolderChange change = new RenameSourceFolderChange(oldRoot1, newName1);
        change.initializeValidationData(new NullProgressMonitor());
        performChange(change);
        assertFalse("old folder should not exist", oldRoot1.exists());
        assertEquals("expected 4 pfr's", 4, testProject.getPackageFragmentRoots().length);
        IPackageFragmentRoot[] newRoots = testProject.getPackageFragmentRoots();
        for (int i = 0; i < newRoots.length; i++) {
            // DebugUtils.dump(newRoots[i].getElementName());
            assertTrue("should exist " + i, newRoots[i].exists());
            if (i == 2)
                assertEquals("3rd position should be:" + newName1, newName1, newRoots[i].getElementName());
        }
    } finally {
        JavaProjectHelper.removeSourceContainer(rts.getProject(), newName1);
        JavaProjectHelper.removeSourceContainer(rts.getProject(), oldName2);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameSourceFolderChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Test(org.junit.Test)

Aggregations

RenameSourceFolderChange (org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)3 Test (org.junit.Test)3 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)1 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)1 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)1