Search in sources :

Example 91 with RenameJavaElementDescriptor

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

the class RenamePackageProcessor method createRefactoringDescriptor.

private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project = null;
    IJavaProject javaProject = fPackage.getJavaProject();
    if (javaProject != null) {
        project = javaProject.getElementName();
    }
    final int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
    final String description = Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short, getElementLabel(fPackage));
    final String header = Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description, new String[] { getElementLabel(fPackage), getNewElementName() });
    final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
    if (fRenameSubpackages) {
        comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages);
    }
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment.asString());
    descriptor.setFlags(flags);
    descriptor.setJavaElement(fPackage);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
    if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) {
        descriptor.setFileNamePatterns(fFilePatterns);
    }
    descriptor.setUpdateHierarchy(fRenameSubpackages);
    return descriptor;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 92 with RenameJavaElementDescriptor

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

the class RenamePackageProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
        final RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
        final DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
        result.addAll(fChangeManager.getAllChanges());
        fRenamePackageChange = new RenamePackageChange(fPackage, getNewElementName(), fRenameSubpackages);
        result.add(fRenamePackageChange);
        monitor.worked(1);
        return result;
    } finally {
        fChangeManager = null;
        fImportsManager = null;
        monitor.done();
    }
}
Also used : DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenamePackageChange(org.eclipse.jdt.ls.core.internal.corext.refactoring.changes.RenamePackageChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 93 with RenameJavaElementDescriptor

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

the class RenameLocalVariableProcessor method createRefactoringDescriptor.

private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project = null;
    IJavaProject javaProject = fCu.getJavaProject();
    if (javaProject != null) {
        project = javaProject.getElementName();
    }
    final String header = Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName) });
    final String description = Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
    final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
    final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment);
    descriptor.setFlags(RefactoringDescriptor.NONE);
    descriptor.setJavaElement(fLocalVariable);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    return descriptor;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 94 with RenameJavaElementDescriptor

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

the class RenameSourceFolderProcessor method createChange.

@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 1);
    try {
        final IResource resource = fSourceFolder.getResource();
        final String project = resource.getProject().getName();
        final String newName = getNewElementName();
        final String description = Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description_short, JavaElementLabels.getElementLabel(fSourceFolder, JavaElementLabels.ALL_DEFAULT));
        final String header = Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getJavaElementName(newName) });
        final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
        final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_SOURCE_FOLDER);
        descriptor.setProject(project);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(RefactoringDescriptor.NONE);
        descriptor.setJavaElement(fSourceFolder);
        descriptor.setNewName(newName);
        return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameSourceFolderRefactoring_rename, new Change[] { new RenameSourceFolderChange(fSourceFolder, newName) });
    } finally {
        monitor.done();
    }
}
Also used : RenameSourceFolderChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenameSourceFolderChange) DynamicValidationRefactoringChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IResource(org.eclipse.core.resources.IResource) JDTRefactoringDescriptorComment(org.eclipse.jdt.internal.corext.refactoring.JDTRefactoringDescriptorComment)

Example 95 with RenameJavaElementDescriptor

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

the class RenameLinkedMode method undoAndCreateRenameSupport.

private RenameSupport undoAndCreateRenameSupport(String newName) throws CoreException {
    // Assumption: the linked mode model should be shut down by now.
    final ISourceViewer viewer = fEditor.getViewer();
    try {
        if (!fOriginalName.equals(newName)) {
            fEditor.getSite().getWorkbenchWindow().run(false, true, monitor -> {
                if (viewer instanceof ITextViewerExtension6) {
                    IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
                    if (undoManager instanceof IUndoManagerExtension) {
                        IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
                        IUndoContext undoContext = undoManagerExtension.getUndoContext();
                        IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
                        while (undoManager.undoable()) {
                            if (fStartingUndoOperation != null && fStartingUndoOperation.equals(operationHistory.getUndoOperation(undoContext)))
                                return;
                            undoManager.undo();
                        }
                    }
                }
            });
        }
    } catch (InvocationTargetException e) {
        throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), ReorgMessages.RenameLinkedMode_error_saving_editor, e));
    } catch (InterruptedException e) {
        // canceling is OK
        return null;
    } finally {
        JavaModelUtil.reconcile(getCompilationUnit());
    }
    viewer.setSelectedRange(fOriginalSelection.x, fOriginalSelection.y);
    if (newName.length() == 0)
        return null;
    RenameJavaElementDescriptor descriptor = createRenameDescriptor(fJavaElement, newName);
    RenameSupport renameSupport = RenameSupport.create(descriptor);
    return renameSupport;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) CoreException(org.eclipse.core.runtime.CoreException) IUndoManager(org.eclipse.jface.text.IUndoManager) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) RenameSupport(org.eclipse.jdt.ui.refactoring.RenameSupport) InvocationTargetException(java.lang.reflect.InvocationTargetException) IUndoManagerExtension(org.eclipse.jface.text.IUndoManagerExtension)

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