Search in sources :

Example 96 with RenameJavaElementDescriptor

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

the class BinaryReferencesTests method testRenamePackage01.

@Test
public void testRenamePackage01() throws Exception {
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    IPackageFragment pack = findType("source.BaseClass").getPackageFragment();
    descriptor.setJavaElement(pack);
    descriptor.setNewName("newName");
    descriptor.setUpdateReferences(true);
    descriptor.setUpdateHierarchy(false);
    List<SearchMatch> matches = doRefactoring(descriptor);
    assertContainsMatches(matches, new String[] { "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass", "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass", "=BinaryReference/binary<ref(ReferenceClass.class[ReferenceClass", "=BinaryReference/binary<ref(SubClass.class[SubClass", "=BinaryReference/binary<ref(SubClass.class[SubClass" });
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) Test(org.junit.Test)

Example 97 with RenameJavaElementDescriptor

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

the class RenameNonPrivateFieldTests 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<IAnnotatable> elements = new ArrayList<>();
    elements.add(field);
    List<RenameArguments> 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);
    assertNull("was supposed to pass", result);
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    ParticipantTesting.testRename(renameHandles, args.toArray(new RenameArguments[args.size()]));
    assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertFalse("! anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
    RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
    assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
    assertFalse("! anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
    assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
    RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
    assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameFieldProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) IAnnotatable(org.eclipse.jdt.core.IAnnotatable) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 98 with RenameJavaElementDescriptor

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

the class RenameNonPrivateFieldTests method helper1_0.

private void helper1_0(String fieldName, String newFieldName) throws Exception {
    IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A");
    IField field = classA.getField(fieldName);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_FIELD);
    descriptor.setJavaElement(field);
    descriptor.setUpdateReferences(true);
    descriptor.setNewName(newFieldName);
    RefactoringStatus result = performRefactoring(descriptor);
    assertNotNull("precondition was supposed to fail", result);
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IField(org.eclipse.jdt.core.IField) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IType(org.eclipse.jdt.core.IType)

Example 99 with RenameJavaElementDescriptor

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

the class RenameStaticMethodTests 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");
    assertNull("was supposed to pass", performRefactoring(descriptor));
    assertEqualLines("invalid renaming in A", getFileContents(getOutputTestFileName("A")), cuA.getSource());
    assertEqualLines("invalid renaming in B", getFileContents(getOutputTestFileName("B")), cuB.getSource());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IMethod(org.eclipse.jdt.core.IMethod) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 100 with RenameJavaElementDescriptor

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

the class RenamePackageTests method createRefactoringDescriptor.

// -------------
private RenameJavaElementDescriptor createRefactoringDescriptor(IPackageFragment pack, String newName) {
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setJavaElement(pack);
    descriptor.setNewName(newName);
    descriptor.setUpdateReferences(true);
    return descriptor;
}
Also used : RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

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