use of org.lxtk.RenameProvider in project lxtk by lxtk-org.
the class RenameRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
RenameProvider[] renameProviders = getRenameProviders();
if (renameProviders.length == 0)
return RefactoringStatus.createFatalErrorStatus(Messages.RenameRefactoring_No_rename_provider);
RefactoringStatus status = checkNewName();
if (status.hasFatalError())
return status;
WorkspaceEdit workspaceEdit = null;
int i = 0;
if (prepareRenameProvider != null)
while (i < renameProviders.length && renameProviders[i] != prepareRenameProvider) i++;
SubMonitor subMonitor = SubMonitor.convert(pm, renameProviders.length - i);
while (i < renameProviders.length) {
RenameProvider renameProvider = renameProviders[i++];
RenameRequest request = newRenameRequest();
request.setProvider(renameProvider);
request.setParams(new RenameParams(DocumentUri.toTextDocumentIdentifier(target.getDocumentUri()), getPosition(), getNewName()));
request.setProgressMonitor(subMonitor.split(1));
request.setUpWorkDoneProgress(() -> new DefaultWorkDoneProgress(Either.forLeft(UUID.randomUUID().toString())));
try {
workspaceEdit = request.sendAndReceive();
} catch (CompletionException e) {
status.merge(handleError(e.getCause(), request.getErrorMessage()));
}
if (workspaceEdit != null) {
setWorkspaceEdit(workspaceEdit);
return super.checkFinalConditions(null);
}
}
// no workspace edit
if (!status.hasFatalError())
status.addFatalError(Messages.RenameRefactoring_No_workspace_edit);
return status;
}
use of org.lxtk.RenameProvider in project lxtk by lxtk-org.
the class RenameRefactoring method checkInitialConditions.
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
setPrepareRenameResult(null, null);
RenameProvider[] renameProviders = getRenameProviders();
if (renameProviders.length == 0)
return RefactoringStatus.createFatalErrorStatus(Messages.RenameRefactoring_No_rename_provider);
RefactoringStatus status = new RefactoringStatus();
SubMonitor subMonitor = SubMonitor.convert(pm, renameProviders.length);
for (int i = 0; i < renameProviders.length; i++) {
RenameProvider renameProvider = renameProviders[i];
if (!Boolean.TRUE.equals(renameProvider.getRegistrationOptions().getPrepareProvider()))
return new RefactoringStatus();
PrepareRenameRequest request = newPrepareRenameRequest();
request.setProvider(renameProvider);
PrepareRenameParams params = new PrepareRenameParams(DocumentUri.toTextDocumentIdentifier(target.getDocumentUri()), getPosition());
request.setParams(params);
request.setProgressMonitor(subMonitor.split(1));
Either<Range, PrepareRenameResult> prepareRenameResult = null;
try {
prepareRenameResult = request.sendAndReceive();
} catch (CompletionException e) {
status.merge(handleError(e.getCause(), request.getErrorMessage()));
}
if (prepareRenameResult != null) {
setPrepareRenameResult(renameProvider, prepareRenameResult);
return new RefactoringStatus();
}
}
// no prepare rename result
if (!status.hasFatalError())
status.addFatalError(Messages.RenameRefactoring_No_prepare_rename_result);
return status;
}
Aggregations