use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor 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 } });
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameStaticMethodTest method helper2_0.
private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean updateReferences, boolean createDelegate) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType classA = getType(cu, "A");
IMethod method = classA.getMethod(methodName, signatures);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setUpdateReferences(updateReferences);
descriptor.setJavaElement(method);
descriptor.setNewName(newMethodName);
descriptor.setKeepOriginal(createDelegate);
descriptor.setDeprecateDelegate(true);
assertEquals("was supposed to pass", null, performRefactoring(descriptor));
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameStaticMethodTest method test11.
@Test
public void test11() throws Exception {
// printTestDisabledMessage("bug 40452");
// if (true) return;
IPackageFragment packageA = getRoot().createPackageFragment("a", false, new NullProgressMonitor());
IPackageFragment packageB = getRoot().createPackageFragment("b", false, new NullProgressMonitor());
ICompilationUnit cuA = createCUfromTestFile(packageA, "A");
ICompilationUnit cuB = createCUfromTestFile(packageB, "B");
IType classA = getType(cuA, "A");
IMethod method = classA.getMethod("method2", new String[0]);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setUpdateReferences(true);
descriptor.setJavaElement(method);
descriptor.setNewName("fred");
assertEquals("was supposed to pass", null, performRefactoring(descriptor));
assertEqualLines("invalid renaming in A", getFileContents(getOutputTestFileName("A")), cuA.getSource());
assertEqualLines("invalid renaming in B", getFileContents(getOutputTestFileName("B")), cuB.getSource());
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameTypeTest method initWithAllOptions.
private RefactoringDescriptor initWithAllOptions(String oldName, String innerOldName, String innerNewName, boolean updateReferences, boolean updateTextualMatches, boolean updateSimilar, String nonJavaFiles, int matchStrategy) throws Exception, JavaModelException, CoreException {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldName);
IType classA = getType(cu, innerOldName);
RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, innerNewName);
setTheOptions(descriptor, updateReferences, updateTextualMatches, updateSimilar, nonJavaFiles, matchStrategy);
return descriptor;
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class Rename18Test method renameMethod.
private void renameMethod(String methodName, String newMethodName, String[] signatures, boolean shouldPass, boolean updateReferences, boolean createDelegate) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType typeI = getType(cu, "I");
IMethod method = typeI.getMethod(methodName, signatures);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setJavaElement(method);
descriptor.setUpdateReferences(updateReferences);
descriptor.setNewName(newMethodName);
descriptor.setKeepOriginal(createDelegate);
descriptor.setDeprecateDelegate(true);
assertEquals("was supposed to pass", null, performRefactoring(descriptor));
if (!shouldPass) {
assertTrue("incorrect renaming because of a java model bug", !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
return;
}
assertEqualLines("incorrect renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
Aggregations