use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.
the class RenameResourceDescriptor method createRefactoring.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.RefactoringDescriptor#createRefactoring(org.eclipse.ltk.core.refactoring.RefactoringStatus)
*/
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
IPath resourcePath = getResourcePath();
if (resourcePath == null) {
status.addFatalError(RefactoringCoreMessages.RenameResourceDescriptor_error_path_not_set);
return null;
}
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourcePath);
if (resource == null || !resource.exists()) {
status.addFatalError(Messages.format(RefactoringCoreMessages.RenameResourceDescriptor_error_resource_not_existing, BasicElementLabels.getPathLabel(resourcePath, false)));
return null;
}
String newName = getNewName();
if (newName == null || newName.length() == 0) {
status.addFatalError(RefactoringCoreMessages.RenameResourceDescriptor_error_name_not_defined);
return null;
}
RenameResourceProcessor processor = new RenameResourceProcessor(resource);
processor.setNewResourceName(newName);
processor.setUpdateReferences(isUpdateReferences());
return new RenameRefactoring(processor);
}
use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.
the class RenameNonPrivateFieldTest method helper2.
private void helper2(String fieldName, String newFieldName, boolean createDelegates) throws Exception {
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType classA = getType(cu, "A");
IField field = classA.getField(fieldName);
boolean isEnum = JdtFlags.isEnum(field);
String id = isEnum ? IJavaRefactorings.RENAME_ENUM_CONSTANT : IJavaRefactorings.RENAME_FIELD;
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(id);
descriptor.setJavaElement(field);
descriptor.setNewName(newFieldName);
descriptor.setUpdateReferences(fUpdateReferences);
descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
if (!isEnum) {
descriptor.setRenameGetters(fRenameGetter);
descriptor.setRenameSetters(fRenameSetter);
descriptor.setKeepOriginal(createDelegates);
descriptor.setDeprecateDelegate(true);
}
RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();
List elements = new ArrayList();
elements.add(field);
List args = new ArrayList();
args.add(new RenameArguments(newFieldName, fUpdateReferences));
if (fRenameGetter) {
elements.add(processor.getGetter());
args.add(new RenameArguments(processor.getNewGetterName(), fUpdateReferences));
}
if (fRenameSetter) {
elements.add(processor.getSetter());
args.add(new RenameArguments(processor.getNewSetterName(), fUpdateReferences));
}
String[] renameHandles = ParticipantTesting.createHandles(elements.toArray());
RefactoringStatus result = performRefactoring(refactoring);
assertEquals("was supposed to pass", null, result);
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring 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.participants.RenameRefactoring in project che by eclipse.
the class Rename18Test method renameLocalVariable.
private void renameLocalVariable(String newFieldName, boolean updateReferences) throws Exception {
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
ISourceRange selection = getSelection(cu);
IJavaElement[] elements = cu.codeSelect(selection.getOffset(), selection.getLength());
assertEquals(1, elements.length);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
descriptor.setJavaElement(elements[0]);
descriptor.setNewName(newFieldName);
descriptor.setUpdateReferences(updateReferences);
descriptor.setUpdateTextualOccurrences(false);
RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
List list = new ArrayList();
list.add(elements[0]);
List args = new ArrayList();
args.add(new RenameArguments(newFieldName, updateReferences));
String[] renameHandles = ParticipantTesting.createHandles(list.toArray());
RefactoringStatus result = performRefactoring(refactoring);
assertEquals("was supposed to pass", null, result);
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.
the class RenameMethodInInterfaceTest method helper1_not_available.
private void helper1_not_available(String methodName, String[] signatures) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType interfaceI = getType(cu, "I");
RenameProcessor processor = new RenameVirtualMethodProcessor(interfaceI.getMethod(methodName, signatures));
RenameRefactoring ref = new RenameRefactoring(processor);
assertTrue(!ref.isApplicable());
}
Aggregations