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);
}
}
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());
}
}
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();
}
}
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);
}
}
Aggregations