Search in sources :

Example 21 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project webtools.sourceediting by eclipse.

the class RenameResourceAction method run.

public void run(IStructuredSelection selection) {
    IResource resource = getResource(selection);
    RenameResourceProcessor processor = new RenameResourceProcessor(resource);
    if (!processor.isApplicable())
        return;
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    try {
        RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, // TODO: provide correct strings
        RefactoringWizardMessages.RenameComponentWizard_defaultPageTitle, RefactoringWizardMessages.RenameComponentWizard_inputPage_description, null);
        RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
        op.run(XSDEditorPlugin.getShell(), wizard.getDefaultPageTitle());
    } catch (InterruptedException e) {
    // do nothing. User action got cancelled
    }
}
Also used : RenameResourceProcessor(org.eclipse.wst.xsd.ui.internal.refactor.rename.RenameResourceProcessor) RefactoringWizardOpenOperation(org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RenameRefactoringWizard(org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard) RefactoringWizard(org.eclipse.ltk.ui.refactoring.RefactoringWizard) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) IResource(org.eclipse.core.resources.IResource)

Example 22 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenamePrivateFieldTest method helper2.

private void helper2(String fieldName, String newFieldName, boolean updateReferences, boolean updateTextualMatches, boolean renameGetter, boolean renameSetter, boolean expectedGetterRenameEnabled, boolean expectedSetterRenameEnabled) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType classA = getType(cu, "A");
    IField field = classA.getField(fieldName);
    RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_FIELD);
    descriptor.setJavaElement(field);
    descriptor.setNewName(newFieldName);
    descriptor.setUpdateReferences(updateReferences);
    descriptor.setUpdateTextualOccurrences(updateTextualMatches);
    descriptor.setRenameGetters(renameGetter);
    descriptor.setRenameSetters(renameSetter);
    RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
    RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();
    assertEquals("getter rename enabled", expectedGetterRenameEnabled, processor.canEnableGetterRenaming() == null);
    assertEquals("setter rename enabled", expectedSetterRenameEnabled, processor.canEnableSetterRenaming() == null);
    String newGetterName = processor.getNewGetterName();
    String newSetterName = processor.getNewSetterName();
    List elements = new ArrayList();
    elements.add(field);
    List args = new ArrayList();
    args.add(new RenameArguments(newFieldName, updateReferences));
    if (renameGetter && expectedGetterRenameEnabled) {
        elements.add(processor.getGetter());
        args.add(new RenameArguments(newGetterName, updateReferences));
    }
    if (renameSetter && expectedSetterRenameEnabled) {
        elements.add(processor.getSetter());
        args.add(new RenameArguments(newSetterName, updateReferences));
    }
    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());
}
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) ArrayList(java.util.ArrayList) List(java.util.List) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 23 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenamePrivateMethodTest method helper1_0.

private void helper1_0(String methodName, String newMethodName, String[] signatures) throws Exception {
    IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A");
    RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(classA.getMethod(methodName, signatures));
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setNewElementName(newMethodName);
    RefactoringStatus result = performRefactoring(refactoring);
    assertNotNull("precondition was supposed to fail", result);
}
Also used : RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor) IType(org.eclipse.jdt.core.IType)

Example 24 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenamePrivateMethodTest method test18.

@Test
public void test18() throws Exception {
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    ICompilationUnit cuC = createCUfromTestFile(getPackageP(), "C");
    IType classB = getType(cu, "B");
    RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(classB.getMethod("m", new String[] { "I" }));
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setNewElementName("kk");
    assertEquals("was supposed to pass", null, performRefactoring(refactoring));
    assertEqualLines("invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
    assertEqualLines("invalid renaming C", getFileContents(getOutputTestFileName("C")), cuC.getSource());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 25 with RenameRefactoring

use of org.eclipse.ltk.core.refactoring.participants.RenameRefactoring in project che by eclipse.

the class RenamePrivateMethodTest method helper2_0.

private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean updateReferences, boolean createDelegate) throws Exception {
    ParticipantTesting.reset();
    ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
    IType classA = getType(cu, "A");
    IMethod method = classA.getMethod(methodName, signatures);
    String[] handles = ParticipantTesting.createHandles(method);
    RenameMethodProcessor processor = new RenameNonVirtualMethodProcessor(method);
    RenameRefactoring refactoring = new RenameRefactoring(processor);
    processor.setUpdateReferences(updateReferences);
    processor.setNewElementName(newMethodName);
    processor.setDelegateUpdating(createDelegate);
    assertEquals("was supposed to pass", null, performRefactoring(refactoring));
    assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
    ParticipantTesting.testRename(handles, new RenameArguments[] { new RenameArguments(newMethodName, updateReferences) });
    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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameNonVirtualMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameNonVirtualMethodProcessor) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RenameMethodProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType)

Aggregations

RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)36 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)13 IType (org.eclipse.jdt.core.IType)12 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 JavaRefactoringArguments (org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments)8 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)5 RenameMethodProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodProcessor)5 RenameTypeParameterProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeParameterProcessor)5 RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)5 RefactoringWizard (org.eclipse.ltk.ui.refactoring.RefactoringWizard)5 RefactoringWizardOpenOperation (org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation)5 RenameRefactoringWizard (org.eclipse.wst.xsd.ui.internal.refactor.wizard.RenameRefactoringWizard)5 CoreException (org.eclipse.core.runtime.CoreException)4 IMethod (org.eclipse.jdt.core.IMethod)4 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)4 RenameVirtualMethodProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IFile (org.eclipse.core.resources.IFile)3