[hg] main-silver: #223912: disabling OnSaveTasks during refactor...

  • From: Jan Lahoda < >
  • To: , ,
  • Subject: [hg] main-silver: #223912: disabling OnSaveTasks during refactor...
  • Date: Fri, 11 Jan 2013 09:39:05 -0800

changeset 4130b9ad2186 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/4130b9ad2186
description:
        #223912: disabling OnSaveTasks during refactoring perform and undo

diffstat:

 editor.lib/nbproject/project.properties                                      
    |   2 +-
 editor.lib/src/org/netbeans/editor/Utilities.java                            
    |  10 ++++
 editor.lib/src/org/netbeans/modules/editor/lib/BeforeSaveTasks.java          
    |  18 ++++++++
 refactoring.api/nbproject/project.xml                                        
    |   2 +-
 
refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
 |  22 +++++++++-
 5 files changed, 50 insertions(+), 4 deletions(-)

diffs (151 lines):

diff --git a/editor.lib/nbproject/project.properties 
b/editor.lib/nbproject/project.properties
--- a/editor.lib/nbproject/project.properties
+++ b/editor.lib/nbproject/project.properties
@@ -42,7 +42,7 @@
 
 javac.compilerargs=-Xlint:unchecked
 javac.source=1.6
-spec.version.base=3.33.0
+spec.version.base=3.34.0
 is.autoload=true
 
 javadoc.arch=${basedir}/arch.xml
diff --git a/editor.lib/src/org/netbeans/editor/Utilities.java 
b/editor.lib/src/org/netbeans/editor/Utilities.java
--- a/editor.lib/src/org/netbeans/editor/Utilities.java
+++ b/editor.lib/src/org/netbeans/editor/Utilities.java
@@ -99,11 +99,13 @@
 import org.netbeans.lib.editor.util.swing.DocumentUtilities;
 import org.netbeans.modules.editor.indent.api.Reformat;
 import org.netbeans.modules.editor.indent.spi.CodeStylePreferences;
+import org.netbeans.modules.editor.lib.BeforeSaveTasks;
 import org.netbeans.modules.editor.lib2.EditorPreferencesDefaults;
 import org.netbeans.modules.editor.lib2.EditorPreferencesKeys;
 import org.netbeans.modules.editor.lib2.view.DocumentView;
 import org.netbeans.modules.editor.lib2.view.EditorView;
 import org.openide.util.Exceptions;
+import org.openide.util.Mutex;
 import org.openide.util.NbBundle;
 
 /**
@@ -1608,6 +1610,14 @@
         return new JComponent [] { sp, editorPane };
     }
 
+    /**Don't use unless you know what you are doing.
+     * 
+     * @since 3.34
+     */
+    public static <T> T runWithOnSaveTasksDisabled(Mutex.Action<T> run) {
+        return BeforeSaveTasks.runWithOnSaveTasksDisabled(run);
+    }
+
     private static void adjustScrollPaneSize(JScrollPane sp, JEditorPane 
editorPane) {
         int height;
         //logger.fine("createSingleLineEditor(): editorPane's margin = 
"+editorPane.getMargin());
diff --git 
a/editor.lib/src/org/netbeans/modules/editor/lib/BeforeSaveTasks.java 
b/editor.lib/src/org/netbeans/modules/editor/lib/BeforeSaveTasks.java
--- a/editor.lib/src/org/netbeans/modules/editor/lib/BeforeSaveTasks.java
+++ b/editor.lib/src/org/netbeans/modules/editor/lib/BeforeSaveTasks.java
@@ -59,6 +59,7 @@
 import org.netbeans.modules.editor.lib2.document.EditorDocumentServices;
 import org.netbeans.modules.editor.lib2.document.ModRootElement;
 import org.netbeans.spi.editor.document.OnSaveTask;
+import org.openide.util.Mutex;
 
 /**
  * Registration of tasks performed right before document save.
@@ -79,6 +80,22 @@
         return beforeSaveTasks;
     }
     
+    private final static ThreadLocal<Boolean> ignoreOnSaveTasks = new 
ThreadLocal<Boolean>() {
+        @Override protected Boolean initialValue() {
+            return false;
+        }
+    };
+    
+    public static <T> T runWithOnSaveTasksDisabled(Mutex.Action<T> run) {
+        Boolean originalIgnore = ignoreOnSaveTasks.get();
+        ignoreOnSaveTasks.set(true);
+        try {
+            return run.run();
+        } finally {
+            ignoreOnSaveTasks.set(originalIgnore);
+        }
+    }
+    
     private final BaseDocument doc;
 
     private BeforeSaveTasks(BaseDocument doc) {
@@ -98,6 +115,7 @@
     }
 
     void runTasks() {
+        if (ignoreOnSaveTasks.get() == Boolean.TRUE) return ;
         String mimeType = DocumentUtilities.getMimeType(doc);
         Collection<? extends OnSaveTask.Factory> factories = 
MimeLookup.getLookup(mimeType).
                 lookupAll(OnSaveTask.Factory.class);
diff --git a/refactoring.api/nbproject/project.xml 
b/refactoring.api/nbproject/project.xml
--- a/refactoring.api/nbproject/project.xml
+++ b/refactoring.api/nbproject/project.xml
@@ -46,7 +46,7 @@
                     <compile-dependency/>
                     <run-dependency>
                         <release-version>3</release-version>
-                        <specification-version>3.20.1</specification-version>
+                        <specification-version>3.34</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git 
a/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
 
b/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
--- 
a/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
+++ 
b/refactoring.api/src/org/netbeans/modules/refactoring/api/RefactoringSession.java
@@ -52,6 +52,7 @@
 import org.netbeans.api.annotations.common.CheckForNull;
 import org.netbeans.api.annotations.common.NonNull;
 import org.netbeans.api.editor.mimelookup.MimeLookup;
+import org.netbeans.editor.Utilities;
 import org.netbeans.modules.refactoring.api.impl.ProgressSupport;
 import org.netbeans.modules.refactoring.api.impl.SPIAccessor;
 import org.netbeans.modules.refactoring.spi.ProgressProvider;
@@ -67,6 +68,7 @@
 import org.openide.loaders.DataObject;
 import org.openide.loaders.DataObjectNotFoundException;
 import org.openide.util.Exceptions;
+import org.openide.util.Mutex.Action;
 import org.openide.util.Parameters;
 
 
@@ -114,7 +116,15 @@
      * @return instance of Problem or null, if everything is OK
      */
     @CheckForNull
-    public Problem doRefactoring(boolean saveAfterDone) {
+    public Problem doRefactoring(final boolean saveAfterDone) {
+        return Utilities.runWithOnSaveTasksDisabled(new Action<Problem>() {
+            @Override public Problem run() {
+                return reallyDoRefactoring(saveAfterDone);
+            }
+        });
+    }
+    
+    private Problem reallyDoRefactoring(boolean saveAfterDone) {
         long time = System.currentTimeMillis();
         
         Iterator it = internalList.iterator();
@@ -241,7 +251,15 @@
      * @return instance of Problem or null, if everything is OK
      */
     @CheckForNull
-    public Problem undoRefactoring(boolean saveAfterDone) {
+    public Problem undoRefactoring(final boolean saveAfterDone) {
+        return Utilities.runWithOnSaveTasksDisabled(new Action<Problem>() {
+            @Override public Problem run() {
+                return reallyUndoRefactoring(saveAfterDone);
+            }
+        });
+    }
+    
+    private Problem reallyUndoRefactoring(boolean saveAfterDone) {
         try {
             ListIterator it = internalList.listIterator(internalList.size());
             fireProgressListenerStart(0, internalList.size()+1);

[hg] main-silver: #223912: disabling OnSaveTasks during refactor...

Jan Lahoda 01/11/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close