Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java |
| diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java |
| index cda45df44ed7dd2ffe39b9f4e96f7830a4dbdfad..e16e7875418e926d2ce390cd0fc6f4bdf1084ec2 100644 |
| --- a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java |
| +++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/refactoring/RefactoringSaveHelper.java |
| @@ -13,19 +13,28 @@ |
| */ |
| package com.google.dart.tools.ui.internal.refactoring; |
| +import com.google.dart.tools.core.analysis.AnalysisServer; |
| +import com.google.dart.tools.core.internal.model.DartProjectNature; |
| +import com.google.dart.tools.core.internal.model.PackageLibraryManagerProvider; |
| import com.google.dart.tools.ui.DartToolsPlugin; |
| import com.google.dart.tools.ui.internal.text.editor.EditorUtility; |
| import com.google.dart.tools.ui.internal.util.CoreUtility; |
| import com.google.dart.tools.ui.internal.util.ExceptionHandler; |
| +import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IncrementalProjectBuilder; |
| import org.eclipse.core.resources.ResourcesPlugin; |
| import org.eclipse.core.runtime.Assert; |
| import org.eclipse.core.runtime.CoreException; |
| +import org.eclipse.core.runtime.IPath; |
| import org.eclipse.swt.widgets.Shell; |
| +import org.eclipse.ui.IEditorInput; |
| import org.eclipse.ui.IEditorPart; |
| +import org.eclipse.ui.IFileEditorInput; |
| import org.eclipse.ui.actions.GlobalBuildAction; |
| +import java.io.File; |
| + |
| /** |
| * Helper to save dirty editors prior to starting a refactoring. Saving happens with automatic build |
| * turned off, so when {@link #triggerIncrementalBuild()} should be called later to build changes |
| @@ -48,6 +57,27 @@ public class RefactoringSaveHelper { |
| */ |
| public static final int SAVE_NOTHING = 3; |
| + /** |
| + * Notifies {@link AnalysisServer} about change, so it will put on hold any requests to search |
| + * engine until changed file will be indexed. We need this because "normal" way to do this - |
| + * builder may be will not pick up yet changes to the time when we will make requests to search |
| + * engine in refactoring processors. |
| + */ |
|
messick
2012/10/30 04:29:51
It took me a while to understand this comment. I'm
scheglov
2012/10/30 04:33:09
Thank you!
|
| + private static void notifyAnalysisServerAboutFileChange(IEditorPart editor) { |
| + IEditorInput input = editor.getEditorInput(); |
| + if (input instanceof IFileEditorInput) { |
| + IFile file = ((IFileEditorInput) input).getFile(); |
| + if (!DartProjectNature.hasDartNature(file)) { |
| + return; |
| + } |
| + IPath fileLocation = file.getLocation(); |
| + if (fileLocation != null) { |
| + File javaFile = fileLocation.toFile(); |
| + PackageLibraryManagerProvider.getDefaultAnalysisServer().changed(javaFile); |
| + } |
| + } |
| + } |
| + |
| public RefactoringSaveHelper(int saveMode) { |
| Assert.isLegal(saveMode == SAVE_ALL || saveMode == SAVE_NOTHING); |
| this.saveMode = saveMode; |
| @@ -72,9 +102,15 @@ public class RefactoringSaveHelper { |
| try { |
| boolean autoBuild = CoreUtility.setAutoBuilding(false); |
| try { |
| + // do save |
| if (!DartToolsPlugin.getActiveWorkbenchWindow().getWorkbench().saveAllEditors(false)) { |
| return false; |
| } |
| + // notify AnalysisServer |
| + for (IEditorPart editor : dirtyEditors) { |
| + notifyAnalysisServerAboutFileChange(editor); |
| + } |
| + // done |
| filesSaved = true; |
| } finally { |
| CoreUtility.setAutoBuilding(autoBuild); |