1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

Bug 558474 - CleanUp deprecated methods in org.eclipse.cdt.ui

Reworked deprecated usages of SubProgressMonitor by SubMonitor (Part 5
Latest)

Change-Id: Ia7a06893c5acda374f2045666447ec494b8fccdc
Signed-off-by: Sergey Kovalchuk <sergei.kovalchuk@arsysop.ru>
This commit is contained in:
Sergey Kovalchuk 2020-01-08 10:39:41 +03:00 committed by Jonah Graham
parent 711cb3c4b9
commit 4ec47dbc35
7 changed files with 89 additions and 122 deletions

View file

@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ProgressMonitorWrapper; import org.eclipse.core.runtime.ProgressMonitorWrapper;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog;
@ -144,14 +144,13 @@ public class ChangeExceptionHandler {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() { IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override @Override
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
monitor.beginTask("", 11); //$NON-NLS-1$ SubMonitor subMonitor = SubMonitor.convert(monitor, 11);
try { try {
undo.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1))); undo.initializeValidationData(new NotCancelableProgressMonitor(subMonitor.split(1)));
if (undo.isValid(new SubProgressMonitor(monitor, 1)).hasFatalError()) { if (undo.isValid(subMonitor.split(1)).hasFatalError()) {
monitor.done();
return; return;
} }
undo.perform(new SubProgressMonitor(monitor, 9)); undo.perform(subMonitor.split(9));
} finally { } finally {
undo.dispose(); undo.dispose();
} }

View file

@ -45,7 +45,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.search.core.text.TextSearchEngine; import org.eclipse.search.core.text.TextSearchEngine;
import org.eclipse.search.core.text.TextSearchMatchAccess; import org.eclipse.search.core.text.TextSearchMatchAccess;
import org.eclipse.search.core.text.TextSearchRequestor; import org.eclipse.search.core.text.TextSearchRequestor;
@ -262,6 +262,7 @@ public class TextSearchWrapper {
*/ */
public IStatus searchWord(IFile[] filesToSearch, int scope, IFile scopeAnchor, String workingSet, String[] patterns, public IStatus searchWord(IFile[] filesToSearch, int scope, IFile scopeAnchor, String workingSet, String[] patterns,
String word, IProgressMonitor monitor, final List<CRefactoringMatch> target) { String word, IProgressMonitor monitor, final List<CRefactoringMatch> target) {
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
int startPos = target.size(); int startPos = target.size();
TextSearchEngine engine = TextSearchEngine.create(); TextSearchEngine engine = TextSearchEngine.create();
StringBuilder searchPattern = new StringBuilder(word.length() + 8); StringBuilder searchPattern = new StringBuilder(word.length() + 8);
@ -285,14 +286,15 @@ public class TextSearchWrapper {
return true; return true;
} }
}; };
IStatus result = engine.search(searchscope, requestor, pattern, new SubProgressMonitor(monitor, 95)); IStatus result = engine.search(searchscope, requestor, pattern, subMonitor.split(95));
categorizeMatches(target.subList(startPos, target.size()), new SubProgressMonitor(monitor, 5)); categorizeMatches(target.subList(startPos, target.size()), subMonitor.split(5));
return result; return result;
} }
public void categorizeMatches(List<CRefactoringMatch> matches, IProgressMonitor monitor) { public void categorizeMatches(List<CRefactoringMatch> matches, IProgressMonitor monitor) {
monitor.beginTask(RenameMessages.TextSearch_monitor_categorizeMatches, matches.size()); SubMonitor subMonitor = SubMonitor.convert(monitor, RenameMessages.TextSearch_monitor_categorizeMatches,
matches.size());
IFile file = null; IFile file = null;
ArrayList<int[]> locations = null; ArrayList<int[]> locations = null;
for (Iterator<CRefactoringMatch> iter = matches.iterator(); iter.hasNext();) { for (Iterator<CRefactoringMatch> iter = matches.iterator(); iter.hasNext();) {
@ -304,7 +306,7 @@ public class TextSearchWrapper {
computeLocations(file, locations); computeLocations(file, locations);
} }
match.setLocation(findLocation(match, locations)); match.setLocation(findLocation(match, locations));
monitor.worked(1); subMonitor.worked(1);
} }
} }

View file

@ -31,7 +31,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
@ -327,7 +327,7 @@ public class TeamProjectIndexExportWizardPage extends WizardPage implements List
IRunnableWithProgress op = new IRunnableWithProgress() { IRunnableWithProgress op = new IRunnableWithProgress() {
@Override @Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", projects.length); //$NON-NLS-1$ SubMonitor subMonitor = SubMonitor.convert(monitor, projects.length);
for (ICProject project : projects) { for (ICProject project : projects) {
TeamPDOMExportOperation op = new TeamPDOMExportOperation(project); TeamPDOMExportOperation op = new TeamPDOMExportOperation(project);
op.setTargetLocation(dest); op.setTargetLocation(dest);
@ -335,7 +335,7 @@ public class TeamProjectIndexExportWizardPage extends WizardPage implements List
op.setOptions(TeamPDOMExportOperation.EXPORT_OPTION_RESOURCE_SNAPSHOT); op.setOptions(TeamPDOMExportOperation.EXPORT_OPTION_RESOURCE_SNAPSHOT);
} }
try { try {
op.run(new SubProgressMonitor(monitor, 1)); op.run(subMonitor.split(1));
} catch (CoreException e) { } catch (CoreException e) {
status.merge(e.getStatus()); status.merge(e.getStatus());
} }

View file

@ -51,9 +51,8 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
@ -338,70 +337,57 @@ public class FormatAllAction extends SelectionDispatchAction {
private void doRunOnMultiple(ITranslationUnit[] tus, MultiStatus status, IProgressMonitor monitor) private void doRunOnMultiple(ITranslationUnit[] tus, MultiStatus status, IProgressMonitor monitor)
throws OperationCanceledException { throws OperationCanceledException {
if (monitor == null) { SubMonitor subMonitor = SubMonitor.convert(monitor, ActionMessages.FormatAllAction_operation_description,
monitor = new NullProgressMonitor(); tus.length * 4);
} Map<String, Object> lastOptions = null;
monitor.setTaskName(ActionMessages.FormatAllAction_operation_description); ICProject lastProject = null;
monitor.beginTask("", tus.length * 4); //$NON-NLS-1$ for (int i = 0; i < tus.length; i++) {
try { ITranslationUnit tu = tus[i];
Map<String, Object> lastOptions = null; IPath path = tu.getPath();
ICProject lastProject = null; if (lastProject == null || lastOptions == null || !lastProject.equals(tu.getCProject())) {
lastProject = tu.getCProject();
for (int i = 0; i < tus.length; i++) { lastOptions = getFomatterSettings(lastProject);
ITranslationUnit tu = tus[i]; }
IPath path = tu.getPath();
if (lastProject == null || lastOptions == null || !lastProject.equals(tu.getCProject())) { ILanguage language = null;
lastProject = tu.getCProject(); try {
lastOptions = getFomatterSettings(lastProject); language = tu.getLanguage();
} } catch (CoreException exc) {
// use fallback CPP
ILanguage language = null; language = GPPLanguage.getDefault();
try { }
language = tu.getLanguage();
} catch (CoreException exc) { // use working copy if available
// use fallback CPP ITranslationUnit wc = CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(tu);
language = GPPLanguage.getDefault(); if (wc != null) {
} tu = wc;
}
// use working copy if available lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu);
ITranslationUnit wc = CDTUITools.getWorkingCopyManager().findSharedWorkingCopy(tu); lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_LANGUAGE, language);
if (wc != null) { lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_CURRENT_FILE, tu.getResource());
tu = wc;
} ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_TRANSLATION_UNIT, tu); try {
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_LANGUAGE, language); try {
lastOptions.put(DefaultCodeFormatterConstants.FORMATTER_CURRENT_FILE, tu.getResource()); manager.connect(path, LocationKind.IFILE, subMonitor.split(1));
subMonitor.subTask(path.makeRelative().toString());
if (monitor.isCanceled()) { ITextFileBuffer fileBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
throw new OperationCanceledException(); boolean wasDirty = fileBuffer.isDirty();
}
formatTranslationUnit(fileBuffer, lastOptions);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
try { if (fileBuffer.isDirty() && !wasDirty) {
try { fileBuffer.commit(subMonitor.split(2), false);
manager.connect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1)); } else {
subMonitor.worked(2);
monitor.subTask(path.makeRelative().toString()); }
ITextFileBuffer fileBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE); } finally {
boolean wasDirty = fileBuffer.isDirty(); manager.disconnect(path, LocationKind.IFILE, subMonitor.split(1));
}
formatTranslationUnit(fileBuffer, lastOptions); } catch (CoreException e) {
status.add(e.getStatus());
if (fileBuffer.isDirty() && !wasDirty) {
fileBuffer.commit(new SubProgressMonitor(monitor, 2), false);
} else {
monitor.worked(2);
}
} finally {
manager.disconnect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
}
} catch (CoreException e) {
status.add(e.getStatus());
}
} }
} finally {
monitor.done();
} }
} }

View file

@ -39,10 +39,9 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.layout.PixelConverter; import org.eclipse.jface.layout.PixelConverter;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
@ -225,10 +224,7 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
@Override @Override
public void performApply(IProgressMonitor monitor) throws CoreException { public void performApply(IProgressMonitor monitor) throws CoreException {
if (monitor == null) { SubMonitor subMonitor = SubMonitor.convert(monitor, CUIMessages.BinaryParserBlock_settingBinaryParser, 2);
monitor = new NullProgressMonitor();
}
monitor.beginTask(CUIMessages.BinaryParserBlock_settingBinaryParser, 2);
List<BinaryParserConfiguration> parsers = binaryList.getElements(); List<BinaryParserConfiguration> parsers = binaryList.getElements();
final List<BinaryParserConfiguration> selected = new ArrayList<>(); // must do this to get proper order. final List<BinaryParserConfiguration> selected = new ArrayList<>(); // must do this to get proper order.
for (int i = 0; i < parsers.size(); i++) { for (int i = 0; i < parsers.size(); i++) {
@ -241,13 +237,14 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
@Override @Override
public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException { public void execute(ICDescriptor descriptor, IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
if (initialSelected == null || !selected.equals(initialSelected)) { if (initialSelected == null || !selected.equals(initialSelected)) {
descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID); descriptor.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
for (int i = 0; i < selected.size(); i++) { for (int i = 0; i < selected.size(); i++) {
descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, selected.get(i).getID()); descriptor.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, selected.get(i).getID());
} }
} }
monitor.worked(1); subMonitor.worked(1);
// Give a chance to the contributions to save. // Give a chance to the contributions to save.
// We have to do it last to make sure the parser id // We have to do it last to make sure the parser id
// is save // is save
@ -255,13 +252,13 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
for (int i = 0; i < selected.size(); i++) { for (int i = 0; i < selected.size(); i++) {
ICOptionPage page = getBinaryParserPage(selected.get(i).getID()); ICOptionPage page = getBinaryParserPage(selected.get(i).getID());
if (page != null && page.getControl() != null) { if (page != null && page.getControl() != null) {
page.performApply(new SubProgressMonitor(monitor, 1)); page.performApply(subMonitor.split(1));
} }
} }
} }
}; };
CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(getContainer().getProject(), op, CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(getContainer().getProject(), op,
monitor); subMonitor.split(2));
} else { } else {
if (initialSelected == null || !selected.equals(initialSelected)) { if (initialSelected == null || !selected.equals(initialSelected)) {
Preferences store = getContainer().getPreferences(); Preferences store = getContainer().getPreferences();
@ -269,17 +266,16 @@ public class BinaryParserBlock extends AbstractBinaryParserPage {
store.setValue(CCorePlugin.PREF_BINARY_PARSER, arrayToString(selected.toArray())); store.setValue(CCorePlugin.PREF_BINARY_PARSER, arrayToString(selected.toArray()));
} }
} }
monitor.worked(1); subMonitor.worked(1);
// Give a chance to the contributions to save. // Give a chance to the contributions to save.
for (int i = 0; i < selected.size(); i++) { for (int i = 0; i < selected.size(); i++) {
ICOptionPage page = getBinaryParserPage(selected.get(i).getID()); ICOptionPage page = getBinaryParserPage(selected.get(i).getID());
if (page != null && page.getControl() != null) { if (page != null && page.getControl() != null) {
page.performApply(new SubProgressMonitor(monitor, 1)); page.performApply(subMonitor.split(1));
} }
} }
} }
initialSelected = selected; initialSelected = selected;
monitor.done();
} }
@Override @Override

View file

@ -24,8 +24,7 @@ import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -168,18 +167,11 @@ public class ReferenceBlock extends AbstractCOptionPage {
IProject[] refProjects = getReferencedProjects(); IProject[] refProjects = getReferencedProjects();
if (refProjects != null) { if (refProjects != null) {
IProject project = getContainer().getProject(); IProject project = getContainer().getProject();
if (monitor == null) { SubMonitor subMonitor = SubMonitor.convert(monitor, CUIMessages.ReferenceBlock_task_ReferenceProjects, 1);
monitor = new NullProgressMonitor(); IProjectDescription description = project.getDescription();
} description.setReferencedProjects(refProjects);
monitor.beginTask(CUIMessages.ReferenceBlock_task_ReferenceProjects, 1); project.setDescription(description, subMonitor.split(1));
try {
IProjectDescription description = project.getDescription();
description.setReferencedProjects(refProjects);
project.setDescription(description, new SubProgressMonitor(monitor, 1));
} catch (CoreException e) {
}
} }
} }
@Override @Override

View file

@ -22,8 +22,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout; import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
@ -151,24 +150,17 @@ public abstract class TabFolderOptionBlock {
public boolean performApply(IProgressMonitor monitor) { public boolean performApply(IProgressMonitor monitor) {
if (initializingTabs) if (initializingTabs)
return false; return false;
if (monitor == null) { SubMonitor subMonitor = SubMonitor.convert(monitor, pages.size());
monitor = new NullProgressMonitor(); Iterator<ICOptionPage> iter = pages.iterator();
} while (iter.hasNext()) {
monitor.beginTask("", pages.size()); //$NON-NLS-1$ ICOptionPage tab = iter.next();
try { try {
Iterator<ICOptionPage> iter = pages.iterator(); tab.performApply(subMonitor.split(1));
while (iter.hasNext()) { } catch (CoreException e) {
ICOptionPage tab = iter.next(); CUIPlugin.errorDialog(composite.getShell(), CUIMessages.TabFolderOptionBlock_error,
try { CUIMessages.TabFolderOptionBlock_error_settingOptions, e, true);
tab.performApply(new SubProgressMonitor(monitor, 1)); return false;
} catch (CoreException e) {
CUIPlugin.errorDialog(composite.getShell(), CUIMessages.TabFolderOptionBlock_error,
CUIMessages.TabFolderOptionBlock_error_settingOptions, e, true);
return false;
}
} }
} finally {
monitor.done();
} }
return true; return true;
} }