Search in sources :

Example 1 with RefactoringTickProvider

use of org.eclipse.ltk.core.refactoring.RefactoringTickProvider in project eclipse.jdt.ls by eclipse.

the class FileEventHandler method getRenameEdit.

private static WorkspaceEdit getRenameEdit(IJavaElement targetElement, String newName, IProgressMonitor monitor) throws CoreException {
    RenameSupport renameSupport = RenameSupport.create(targetElement, newName, RenameSupport.UPDATE_REFERENCES);
    if (renameSupport == null) {
        return null;
    }
    if (targetElement instanceof IPackageFragment) {
        ((RenamePackageProcessor) renameSupport.getJavaRenameProcessor()).setRenameSubpackages(true);
    }
    RenameRefactoring renameRefactoring = renameSupport.getRenameRefactoring();
    RefactoringTickProvider rtp = renameRefactoring.getRefactoringTickProvider();
    SubMonitor submonitor = SubMonitor.convert(monitor, "Creating rename changes...", rtp.getAllTicks());
    CheckConditionsOperation checkConditionOperation = new CheckConditionsOperation(renameRefactoring, CheckConditionsOperation.ALL_CONDITIONS);
    checkConditionOperation.run(submonitor.split(rtp.getCheckAllConditionsTicks()));
    if (checkConditionOperation.getStatus().getSeverity() >= RefactoringStatus.FATAL) {
        JavaLanguageServerPlugin.logError(checkConditionOperation.getStatus().getMessageMatchingSeverity(RefactoringStatus.ERROR));
    }
    Change change = renameRefactoring.createChange(submonitor.split(rtp.getCreateChangeTicks()));
    change.initializeValidationData(new NotCancelableProgressMonitor(submonitor.split(rtp.getInitializeChangeTicks())));
    return ChangeUtil.convertToWorkspaceEdit(change);
}
Also used : RefactoringTickProvider(org.eclipse.ltk.core.refactoring.RefactoringTickProvider) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenamePackageProcessor(org.eclipse.jdt.ls.core.internal.corext.refactoring.rename.RenamePackageProcessor) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) SubMonitor(org.eclipse.core.runtime.SubMonitor) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) Change(org.eclipse.ltk.core.refactoring.Change) NotCancelableProgressMonitor(org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor) RenameSupport(org.eclipse.jdt.ls.core.internal.corext.refactoring.rename.RenameSupport)

Aggregations

SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 RenamePackageProcessor (org.eclipse.jdt.ls.core.internal.corext.refactoring.rename.RenamePackageProcessor)1 RenameSupport (org.eclipse.jdt.ls.core.internal.corext.refactoring.rename.RenameSupport)1 Change (org.eclipse.ltk.core.refactoring.Change)1 CheckConditionsOperation (org.eclipse.ltk.core.refactoring.CheckConditionsOperation)1 RefactoringTickProvider (org.eclipse.ltk.core.refactoring.RefactoringTickProvider)1 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1 NotCancelableProgressMonitor (org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor)1