Search in sources :

Example 1 with RenameTypeProcessor

use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor in project che by eclipse.

the class RenameTypeTest method checkMappedSimilarElementsExist.

private void checkMappedSimilarElementsExist(Refactoring ref) {
    RenameTypeProcessor rtp = (RenameTypeProcessor) ((RenameRefactoring) ref).getProcessor();
    IJavaElementMapper mapper = (IJavaElementMapper) rtp.getAdapter(IJavaElementMapper.class);
    IJavaElement[] similarElements = rtp.getSimilarElements();
    if (similarElements == null)
        return;
    for (int i = 0; i < similarElements.length; i++) {
        IJavaElement element = similarElements[i];
        if (!(element instanceof ILocalVariable)) {
            IJavaElement newElement = mapper.getRefactoredJavaElement(element);
            TestCase.assertTrue(newElement.exists());
            Assert.assertFalse(element.exists());
        }
    }
}
Also used : ILocalVariable(org.eclipse.jdt.core.ILocalVariable) IJavaElement(org.eclipse.jdt.core.IJavaElement) RenameTypeProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor) IJavaElementMapper(org.eclipse.jdt.core.refactoring.IJavaElementMapper)

Example 2 with RenameTypeProcessor

use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor in project che by eclipse.

the class RenameTypeRefactoringContribution method createRefactoring.

/**
	 * {@inheritDoc}
	 */
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) {
    JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
    RenameTypeProcessor processor = new RenameTypeProcessor(arguments, status);
    return new RenameRefactoring(processor);
}
Also used : JavaRefactoringArguments(org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments) RenameTypeProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)

Example 3 with RenameTypeProcessor

use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor in project che by eclipse.

the class RenameTypeTest method checkMappers.

private void checkMappers(Refactoring refactoring, IType type, String newCUName, IJavaElement[] someClassMembers) {
    RenameTypeProcessor rtp = (RenameTypeProcessor) ((RenameRefactoring) refactoring).getProcessor();
    ICompilationUnit newUnit = (ICompilationUnit) rtp.getRefactoredJavaElement(type.getCompilationUnit());
    TestCase.assertTrue(newUnit.exists());
    TestCase.assertTrue(newUnit.getElementName().equals(newCUName));
    IFile newFile = (IFile) rtp.getRefactoredResource(type.getResource());
    TestCase.assertTrue(newFile.exists());
    TestCase.assertTrue(newFile.getName().equals(newCUName));
    if ((type.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) && type.getCompilationUnit().getElementName().equals(type.getElementName() + ".java")) {
        Assert.assertFalse(type.getCompilationUnit().exists());
        Assert.assertFalse(type.getResource().exists());
    }
    IPackageFragment oldPackage = (IPackageFragment) type.getCompilationUnit().getParent();
    IPackageFragment newPackage = (IPackageFragment) rtp.getRefactoredJavaElement(oldPackage);
    Assert.assertEquals(oldPackage, newPackage);
    for (int i = 0; i < someClassMembers.length; i++) {
        IMember member = (IMember) someClassMembers[i];
        IJavaElement refactoredMember = rtp.getRefactoredJavaElement(member);
        if (member instanceof IMethod && member.getElementName().equals(type.getElementName()))
            // constructor
            continue;
        TestCase.assertTrue(refactoredMember.exists());
        Assert.assertEquals(member.getElementName(), refactoredMember.getElementName());
        Assert.assertFalse(refactoredMember.equals(member));
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) RenameTypeProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor) IMethod(org.eclipse.jdt.core.IMethod) IMember(org.eclipse.jdt.core.IMember)

Aggregations

RenameTypeProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor)3 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IFile (org.eclipse.core.resources.IFile)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 ILocalVariable (org.eclipse.jdt.core.ILocalVariable)1 IMember (org.eclipse.jdt.core.IMember)1 IMethod (org.eclipse.jdt.core.IMethod)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IJavaElementMapper (org.eclipse.jdt.core.refactoring.IJavaElementMapper)1 JavaRefactoringArguments (org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments)1 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1