diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java index 6a559af62c6..6789824fbe7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java @@ -19,10 +19,8 @@ import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.Region; import org.eclipse.jface.viewers.ISelection; @@ -108,31 +106,27 @@ public abstract class CRefactoring extends Refactoring { @Override public final RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { - if (pm == null) - pm = new NullProgressMonitor(); - pm.beginTask(Messages.CRefactoring_checking_final_conditions, 10); + SubMonitor progress = SubMonitor.convert(pm, Messages.CRefactoring_checking_final_conditions, 12); - CheckConditionsContext context= new CheckConditionsContext(); - context.add(new ValidateEditChecker(getValidationContext())); - ResourceChangeChecker resourceChecker = new ResourceChangeChecker(); - IResourceChangeDescriptionFactory deltaFactory = resourceChecker.getDeltaFactory(); - context.add(resourceChecker); - - RefactoringStatus result = checkFinalConditions(new SubProgressMonitor(pm, 8), context); - if (result.hasFatalError()) { - pm.done(); + try { + CheckConditionsContext context= new CheckConditionsContext(); + context.add(new ValidateEditChecker(getValidationContext())); + ResourceChangeChecker resourceChecker = new ResourceChangeChecker(); + IResourceChangeDescriptionFactory deltaFactory = resourceChecker.getDeltaFactory(); + context.add(resourceChecker); + + RefactoringStatus result = checkFinalConditions(progress.split(8), context); + if (result.hasFatalError()) + return result; + + modificationCollector = new ModificationCollector(deltaFactory); + collectModifications(progress.split(2), modificationCollector); + + result.merge(context.check(progress.split(2))); return result; + } finally { + progress.done(); } - if (pm.isCanceled()) - throw new OperationCanceledException(); - - modificationCollector = new ModificationCollector(deltaFactory); - collectModifications(pm, modificationCollector); - - result.merge(context.check(new SubProgressMonitor(pm, 2))); - - pm.done(); - return result; } protected RefactoringStatus checkFinalConditions(IProgressMonitor subProgressMonitor, diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringSaveHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringSaveHelper.java index 9dfef502d31..f617a3d9547 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringSaveHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringSaveHelper.java @@ -14,6 +14,17 @@ package org.eclipse.cdt.internal.ui.refactoring; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -22,20 +33,6 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; - -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ResourcesPlugin; - -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.window.Window; - import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.GlobalBuildAction; @@ -133,14 +130,17 @@ public class RefactoringSaveHelper { @Override public void run(IProgressMonitor pm) throws InterruptedException { int count= dirtyEditors.length; - pm.beginTask("", count); //$NON-NLS-1$ - for (int i= 0; i < count; i++) { - IEditorPart editor= dirtyEditors[i]; - editor.doSave(new SubProgressMonitor(pm, 1)); - if (pm.isCanceled()) - throw new InterruptedException(); + SubMonitor progress = SubMonitor.convert(pm, "", count); //$NON-NLS-1$ + try { + for (int i= 0; i < count; i++) { + IEditorPart editor= dirtyEditors[i]; + editor.doSave(progress.split(1)); + } + } catch (OperationCanceledException e) { + throw new InterruptedException(); + } finally { + progress.done(); } - pm.done(); } }; try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java index e66ca30aa38..5f6406d3fb9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NameHelper.java @@ -24,7 +24,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.Keywords; @@ -74,10 +73,10 @@ public class NameHelper { ICPPASTQualifiedName qname = new CPPASTQualifiedName( (ICPPASTName) declaratorName.copy(CopyStyle.withLocations)); - ICPPASTNameSpecifier[] declarationNames = NamespaceHelper.getSurroundingNamespace(declarationTu, - selectionOffset, astCache).getAllSegments(); - ICPPASTNameSpecifier[] implementationNames = NamespaceHelper.getSurroundingNamespace(insertFileTu, - insertLocation, astCache).getAllSegments(); + ICPPASTName[] declarationNames = + NamespaceHelper.getSurroundingNamespace(declarationTu, selectionOffset, astCache); + ICPPASTName[] implementationNames = + NamespaceHelper.getSurroundingNamespace(insertFileTu, insertLocation, astCache); for (int i = 0; i < declarationNames.length; i++) { if (i >= implementationNames.length) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java index d3811b17bd9..a595ca8fbfb 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/NamespaceHelper.java @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.refactoring.utils; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -20,14 +23,13 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle; import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamedTypeSpecifier; -import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateId; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId; @@ -49,16 +51,16 @@ public class NamespaceHelper { * @return ICPPASTQualifiedName with the names of all namespaces * @throws CoreException */ - public static ICPPASTQualifiedName getSurroundingNamespace(final ITranslationUnit translationUnit, final int offset, CRefactoringContext astCache) - throws CoreException { - final CPPASTQualifiedName qualifiedName = new CPPASTQualifiedName(); + public static ICPPASTName[] getSurroundingNamespace(final ITranslationUnit translationUnit, + final int offset, CRefactoringContext astCache) throws CoreException { + final List names = new ArrayList<>(); astCache.getAST(translationUnit, null).accept(new CPPASTAllVisitor() { @Override public int visit(IASTDeclSpecifier declSpec) { if (declSpec instanceof ICPPASTCompositeTypeSpecifier && checkFileNameAndLocation(translationUnit.getLocation(), offset, declSpec)) { - qualifiedName.addName(createNameWithTemplates(declSpec)); + names.add((ICPPASTName) createNameWithTemplates(declSpec)); } return super.visit(declSpec); } @@ -66,14 +68,14 @@ public class NamespaceHelper { @Override public int visit(ICPPASTNamespaceDefinition namespace) { if (checkFileNameAndLocation(translationUnit.getLocation(), offset, namespace)) { - qualifiedName.addName((namespace).getName().copy(CopyStyle.withLocations)); + names.add((ICPPASTName) namespace.getName().copy(CopyStyle.withLocations)); } return super.visit(namespace); } }); - - return qualifiedName; + + return names.toArray(new ICPPASTName[names.size()]); } private static boolean checkFileNameAndLocation(final IPath path, final int offset, IASTNode namespace) {