Search in sources :

Example 46 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.

the class ValidateEditTests method testPackageRename1.

@Test
public void testPackageRename1() throws Exception {
    IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package org.test;\n");
    buf.append("class A {\n");
    buf.append("}\n");
    ICompilationUnit cu1 = fragment.createCompilationUnit("A.java", buf.toString(), true, null);
    setReadOnly(cu1);
    buf = new StringBuilder();
    buf.append("package org.test;\n");
    buf.append("class B {\n");
    buf.append("}\n");
    ICompilationUnit cu2 = fragment.createCompilationUnit("B.java", buf.toString(), true, null);
    setReadOnly(cu2);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setJavaElement(fragment);
    descriptor.setNewName("org.test2");
    descriptor.setUpdateReferences(true);
    RefactoringStatus status = performRefactoring(descriptor);
    if (status != null)
        assertTrue(status.toString(), status.isOK());
    Collection<IPath> validatedEditPaths = RefactoringTestRepositoryProvider.getValidatedEditPaths(getRoot().getJavaProject().getProject());
    assertEquals(2, validatedEditPaths.size());
    assertTrue(validatedEditPaths.contains(cu1.getPath()));
    assertTrue(validatedEditPaths.contains(cu2.getPath()));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPath(org.eclipse.core.runtime.IPath) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Test(org.junit.Test)

Example 47 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.

the class ValidateEditTests method testPackageRenameWithResource2.

@Test
public void testPackageRenameWithResource2() throws Exception {
    // MyClass readonly and moved, x.properties readonly moved
    IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package org.test;\n");
    buf.append("public class MyClass {\n");
    buf.append("}\n");
    ICompilationUnit cu1 = fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
    setReadOnly(cu1);
    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);
    setReadOnly(file);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setJavaElement(fragment);
    descriptor.setNewName("org.test2");
    descriptor.setUpdateReferences(true);
    descriptor.setUpdateQualifiedNames(true);
    descriptor.setFileNamePatterns("*.properties");
    RefactoringStatus status = performRefactoring(descriptor);
    if (status != null)
        assertTrue(status.toString(), status.isOK());
    Collection<IPath> validatedEditPaths = RefactoringTestRepositoryProvider.getValidatedEditPaths(getRoot().getJavaProject().getProject());
    assertEquals(2, validatedEditPaths.size());
    assertTrue(validatedEditPaths.contains(cu1.getPath()));
    assertTrue(validatedEditPaths.contains(file.getFullPath()));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 48 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.

the class ValidateEditTests method testTypeRename.

@Test
public void testTypeRename() throws Exception {
    IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
    StringBuilder buf = new StringBuilder();
    buf.append("package org.test;\n");
    buf.append("public class MyClass {\n");
    buf.append("}\n");
    ICompilationUnit cu1 = fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
    setReadOnly(cu1);
    buf = new StringBuilder();
    buf.append("package org.test;\n");
    buf.append("public class C extends MyClass {\n");
    buf.append("}\n");
    ICompilationUnit cu2 = fragment.createCompilationUnit("C.java", buf.toString(), true, null);
    setReadOnly(cu2);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE);
    descriptor.setJavaElement(cu1.findPrimaryType());
    descriptor.setNewName("MyClass2");
    descriptor.setUpdateReferences(true);
    RefactoringStatus status = performRefactoring(descriptor);
    if (status != null)
        assertTrue(status.toString(), status.isOK());
    Collection<IPath> validatedEditPaths = RefactoringTestRepositoryProvider.getValidatedEditPaths(getRoot().getJavaProject().getProject());
    assertEquals(2, validatedEditPaths.size());
    assertTrue(validatedEditPaths.contains(cu1.getPath()));
    assertTrue(validatedEditPaths.contains(cu2.getPath()));
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IPath(org.eclipse.core.runtime.IPath) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Test(org.junit.Test)

Example 49 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.

the class RenameTypeTests 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;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IType(org.eclipse.jdt.core.IType)

Example 50 with RenameJavaElementDescriptor

use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project eclipse.jdt.ui by eclipse-jdt.

the class RenameTypeTests method helperWithTextual.

private String[] helperWithTextual(String oldCuName, String oldName, String newName, String newCUName, boolean updateReferences, boolean updateTextualMatches) throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldCuName);
    IType classA = getType(cu, oldName);
    IJavaElement[] classAMembers = classA.getChildren();
    IPackageFragment pack = (IPackageFragment) cu.getParent();
    String[] renameHandles = null;
    if (classA.getDeclaringType() == null && cu.getElementName().startsWith(classA.getElementName())) {
        renameHandles = ParticipantTesting.createHandles(classA, cu, cu.getResource());
    } else {
        renameHandles = ParticipantTesting.createHandles(classA);
    }
    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, newName);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setUpdateTextualOccurrences(updateTextualMatches);
    Refactoring refactoring = createRefactoring(descriptor);
    assertNull("was supposed to pass", performRefactoring(refactoring));
    ICompilationUnit newcu = pack.getCompilationUnit(newCUName + ".java");
    assertTrue("cu " + newcu.getElementName() + " does not exist", newcu.exists());
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName(newCUName)), newcu.getSource());
    INameUpdating nameUpdating = refactoring.getAdapter(INameUpdating.class);
    IType newElement = (IType) nameUpdating.getNewElement();
    assertTrue("new element does not exist:\n" + newElement.toString(), newElement.exists());
    checkMappers(refactoring, classA, newCUName + ".java", classAMembers);
    return renameHandles;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) INameUpdating(org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IType(org.eclipse.jdt.core.IType)

Aggregations

RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)120 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 IType (org.eclipse.jdt.core.IType)55 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)55 Test (org.junit.Test)33 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)29 IMethod (org.eclipse.jdt.core.IMethod)28 JDTRefactoringDescriptorComment (org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)26 IJavaProject (org.eclipse.jdt.core.IJavaProject)25 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)25 IField (org.eclipse.jdt.core.IField)24 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)23 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22 DynamicValidationRefactoringChange (org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange)21 ArrayList (java.util.ArrayList)19 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)19 JavaModelException (org.eclipse.jdt.core.JavaModelException)15 IPath (org.eclipse.core.runtime.IPath)12 TextChange (org.eclipse.ltk.core.refactoring.TextChange)10 IFile (org.eclipse.core.resources.IFile)9