diff --git a/editor.lib/test/unit/src/org/netbeans/editor/UndoableEditWrapperTest.java b/editor.lib/test/unit/src/org/netbeans/editor/UndoableEditWrapperTest.java --- a/editor.lib/test/unit/src/org/netbeans/editor/UndoableEditWrapperTest.java +++ b/editor.lib/test/unit/src/org/netbeans/editor/UndoableEditWrapperTest.java @@ -62,10 +62,10 @@ import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.mimelookup.test.MockMimeLookup; import org.netbeans.junit.NbTestCase; -import org.netbeans.modules.openide.text.NbDocumentRefactoringHack; import org.openide.awt.UndoRedo; import org.openide.cookies.EditorCookie; import org.openide.text.CloneableEditorSupport; +import org.openide.text.NbDocument; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.windows.CloneableOpenSupport; @@ -99,12 +99,12 @@ // }); doc.insertString(0, "Test", null); Class wrapEditClass = TestingUndoableEditWrapper.WrapCompoundEdit.class; - assertNotNull(NbDocumentRefactoringHack.getEditToBeUndoneOfType(env.support, wrapEditClass)); + assertNotNull(NbDocument.getEditToBeUndoneOfType(env.support, wrapEditClass)); Class wrapEditClass2 = TestingUndoableEditWrapper2.WrapCompoundEdit2.class; - assertNotNull(NbDocumentRefactoringHack.getEditToBeUndoneOfType(env.support, wrapEditClass2)); + assertNotNull(NbDocument.getEditToBeUndoneOfType(env.support, wrapEditClass2)); // A trick to get whole edit - UndoableEdit wholeEdit = NbDocumentRefactoringHack.getEditToBeUndoneOfType(env.support, UndoableEdit.class); + UndoableEdit wholeEdit = NbDocument.getEditToBeUndoneOfType(env.support, UndoableEdit.class); assertTrue(wholeEdit instanceof List); @SuppressWarnings("unchecked") List listEdit = (List) wholeEdit; diff --git a/editor.lib2/apichanges.xml b/editor.lib2/apichanges.xml --- a/editor.lib2/apichanges.xml +++ b/editor.lib2/apichanges.xml @@ -107,6 +107,21 @@ + + UndoableEditWrapper interface added + + + + + +

+ Added UndoableEditWrapper interface which allows wrapping + of document-generated undoable edit by custom wrapping undoable edit(s). +

+
+ +
+ EditorDocumentUtils.runExclusive method added diff --git a/editor.lib2/manifest.mf b/editor.lib2/manifest.mf --- a/editor.lib2/manifest.mf +++ b/editor.lib2/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.editor.lib2/1 -OpenIDE-Module-Implementation-Version: 30 +OpenIDE-Module-Implementation-Version: 31 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml OpenIDE-Module-Needs: org.netbeans.modules.editor.actions diff --git a/editor.lib2/nbproject/project.properties b/editor.lib2/nbproject/project.properties --- a/editor.lib2/nbproject/project.properties +++ b/editor.lib2/nbproject/project.properties @@ -43,7 +43,7 @@ is.autoload=true javac.source=1.6 javac.compilerargs=-Xlint:unchecked -spec.version.base=1.59.0 +spec.version.base=1.60.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/editor.lib2/nbproject/project.xml b/editor.lib2/nbproject/project.xml --- a/editor.lib2/nbproject/project.xml +++ b/editor.lib2/nbproject/project.xml @@ -189,6 +189,7 @@ org.netbeans.api.editor org.netbeans.api.editor.document org.netbeans.spi.editor.codegen + org.netbeans.spi.editor.document org.netbeans.spi.editor.highlighting org.netbeans.spi.editor.highlighting.support org.netbeans.spi.editor.typinghooks diff --git a/editor.lib2/src/org/netbeans/spi/editor/document/UndoableEditWrapper.java b/editor.lib2/src/org/netbeans/spi/editor/document/UndoableEditWrapper.java --- a/editor.lib2/src/org/netbeans/spi/editor/document/UndoableEditWrapper.java +++ b/editor.lib2/src/org/netbeans/spi/editor/document/UndoableEditWrapper.java @@ -51,6 +51,7 @@ * Instances should be registered by using @MimeRegistration. * * @author Miloslav Metelka + * @since 1.60 */ public interface UndoableEditWrapper { @@ -60,8 +61,7 @@ * * @param edit original undoable edit generated by document (or previous wrapper). * @param doc document which generated the original undoable edit. - * @return wrap edit or original edit. - * @since 1.56 + * @return wrap edit instance (delegating to the given edit) or original edit. */ @NonNull UndoableEdit wrap(@NonNull UndoableEdit edit, @NonNull Document doc); diff --git a/openide.text/apichanges.xml b/openide.text/apichanges.xml --- a/openide.text/apichanges.xml +++ b/openide.text/apichanges.xml @@ -49,6 +49,24 @@ Text API + + + Added NbDocument.getEditToBeUndoneOfType + + + + + +

+ Added NbDocument.getEditToBeUndoneOfType() + and NbDocument.getEditToBeRedoneOfType() + to retrieve custom undoable edits that wrap document-generated + undoable edits. +

+
+ + +
Added methods NbDocument.getDocument, diff --git a/openide.text/nbproject/project.properties b/openide.text/nbproject/project.properties --- a/openide.text/nbproject/project.properties +++ b/openide.text/nbproject/project.properties @@ -47,7 +47,7 @@ javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=6.46 +spec.version.base=6.47 test.config.stableBTD.includes=**/*Test.class test.config.stableBTD.excludes=\ **/CloneableEditorSupportTest.class,\ diff --git a/openide.text/src/org/netbeans/modules/openide/text/NbDocumentRefactoringHack.java b/openide.text/src/org/netbeans/modules/openide/text/NbDocumentRefactoringHack.java deleted file mode 100644 --- a/openide.text/src/org/netbeans/modules/openide/text/NbDocumentRefactoringHack.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2012 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2012 Sun Microsystems, Inc. - */ -package org.netbeans.modules.openide.text; - -import java.util.Collection; -import org.openide.cookies.EditorCookie; -import org.openide.text.NbDocument; - -/** - * * TODO: will be removed after API review - */ -public class NbDocumentRefactoringHack { - - public static abstract class APIAccessor { - - static { - Class c = NbDocument.class; - try { - Class.forName(c.getName(), true, c.getClassLoader()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - - public static APIAccessor DEFAULT; - - public abstract T getEditToBeUndoneOfType(EditorCookie ec, Class type); - - public abstract T getEditToBeRedoneOfType(EditorCookie ec, Class type); - } - - public static T getEditToBeUndoneOfType(EditorCookie ec, Class type) { - return APIAccessor.DEFAULT.getEditToBeUndoneOfType(ec, type); - } - - public static T getEditToBeRedoneOfType(EditorCookie ec, Class type) { - return APIAccessor.DEFAULT.getEditToBeRedoneOfType(ec, type); - } -} diff --git a/openide.text/src/org/openide/text/NbDocument.java b/openide.text/src/org/openide/text/NbDocument.java --- a/openide.text/src/org/openide/text/NbDocument.java +++ b/openide.text/src/org/openide/text/NbDocument.java @@ -57,7 +57,6 @@ import javax.swing.text.*; import javax.swing.undo.UndoableEdit; import org.netbeans.api.actions.Openable; -import org.netbeans.modules.openide.text.NbDocumentRefactoringHack; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.awt.UndoRedo; @@ -534,33 +533,39 @@ ((Annotatable) doc).removeAnnotation(annotation); } - /** - * TODO: will be removed after API review + /** + * Get an edit of given type that would be undone if an undo operation would be invoked + * at this time for an editor cookie. + *
+ * The edit to be undone may be composed from instances of various undoable edit types + * (see UndoableEditWrapper). + * + * @param type of undoable edit to be retrieved. + * @param ec editor cookie providing an undo/redo manager. + * @param type class of undoable edit to be retrieved. + * @return undoable edit of given type or null if there is no edit to be undone + * or an instance of the given type is not contained in the edit to be undone. + * @since 6.47 */ - - static { - NbDocumentRefactoringHack.APIAccessor.DEFAULT = new APIAccessorImpl(); - } - - private static class APIAccessorImpl extends NbDocumentRefactoringHack.APIAccessor { - - @Override - public T getEditToBeUndoneOfType(EditorCookie ec, Class type) { - return NbDocument.getEditToBeUndoneOfType(ec, type); - } - - @Override - public T getEditToBeRedoneOfType(EditorCookie ec, Class type) { - return NbDocument.getEditToBeRedoneOfType(ec, type); - } - - } - - static T getEditToBeUndoneOfType(EditorCookie ec, Class type) { + public static T getEditToBeUndoneOfType(EditorCookie ec, Class type) { return getEditToBeUndoneRedoneOfType(ec, type, false); } - static T getEditToBeRedoneOfType(EditorCookie ec, Class type) { + /** + * Get an edit of given type that would be redone if a redo operation would be invoked + * at this time for an editor cookie. + *
+ * The edit to be undone may be composed from instances of various undoable edit types + * (see UndoableEditWrapper). + * + * @param type of undoable edit to be retrieved. + * @param ec editor cookie providing an undo/redo manager. + * @param type class of undoable edit to be retrieved. + * @return undoable edit of given type or null if there is no edit to be redone + * or an instance of the given type is not contained in the edit to be redone. + * @since 6.47 + */ + public static T getEditToBeRedoneOfType(EditorCookie ec, Class type) { return getEditToBeUndoneRedoneOfType(ec, type, true); } @@ -588,8 +593,6 @@ return null; } - //End of TODO - /** * Get the document associated with a file. * diff --git a/refactoring.api/nbproject/project.properties b/refactoring.api/nbproject/project.properties --- a/refactoring.api/nbproject/project.properties +++ b/refactoring.api/nbproject/project.properties @@ -4,5 +4,5 @@ javadoc.apichanges=${basedir}/apichanges.xml javadoc.title=Refactoring API -spec.version.base=1.24.0 +spec.version.base=1.25.0 test.config.stableBTD.includes=**/*Test.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 @@ -55,7 +55,7 @@ 1 - + 1.60 @@ -163,10 +163,10 @@ org.openide.text - + - + 6.47 diff --git a/refactoring.api/src/org/netbeans/modules/refactoring/spi/BackupFacility2.java b/refactoring.api/src/org/netbeans/modules/refactoring/spi/BackupFacility2.java --- a/refactoring.api/src/org/netbeans/modules/refactoring/spi/BackupFacility2.java +++ b/refactoring.api/src/org/netbeans/modules/refactoring/spi/BackupFacility2.java @@ -53,7 +53,6 @@ import java.util.*; import java.util.logging.Logger; import org.netbeans.editor.BaseDocument; -import org.netbeans.modules.openide.text.NbDocumentRefactoringHack; import org.netbeans.modules.refactoring.spi.impl.UndoableWrapper; import org.netbeans.modules.refactoring.spi.impl.UndoableWrapper.UndoableEditDelegate; import org.openide.cookies.EditorCookie; @@ -62,6 +61,7 @@ import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; import org.openide.text.CloneableEditorSupport; +import org.openide.text.NbDocument; import org.openide.util.Exceptions; import org.openide.util.Lookup; @@ -257,7 +257,9 @@ } else { EditorCookie editor = dob.getLookup().lookup(EditorCookie.class); if (editor != null && doc!=null && editor.isModified()) { - UndoableEditDelegate edit = undo?NbDocumentRefactoringHack.getEditToBeUndoneOfType(editor, UndoableWrapper.UndoableEditDelegate.class):NbDocumentRefactoringHack.getEditToBeRedoneOfType(editor, UndoableWrapper.UndoableEditDelegate.class); + UndoableEditDelegate edit = undo + ? NbDocument.getEditToBeUndoneOfType(editor, UndoableWrapper.UndoableEditDelegate.class) + : NbDocument.getEditToBeRedoneOfType(editor, UndoableWrapper.UndoableEditDelegate.class); if (edit == null) { try { LOG.fine("Editor Undo Different");