diff --git a/csl.api/nbproject/project.properties b/csl.api/nbproject/project.properties --- a/csl.api/nbproject/project.properties +++ b/csl.api/nbproject/project.properties @@ -40,7 +40,7 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -spec.version.base=2.37.0 +spec.version.base=2.38.0 is.autoload=true javac.source=1.6 diff --git a/csl.api/nbproject/project.xml b/csl.api/nbproject/project.xml --- a/csl.api/nbproject/project.xml +++ b/csl.api/nbproject/project.xml @@ -69,6 +69,13 @@ + org.netbeans.modules.editor.actions + + 1 + 1.21 + + + org.netbeans.modules.editor.breadcrumbs @@ -146,7 +153,7 @@ 1 - 1.4 + 1.79 diff --git a/csl.api/src/org/netbeans/modules/csl/api/CslActions.java b/csl.api/src/org/netbeans/modules/csl/api/CslActions.java --- a/csl.api/src/org/netbeans/modules/csl/api/CslActions.java +++ b/csl.api/src/org/netbeans/modules/csl/api/CslActions.java @@ -43,6 +43,7 @@ package org.netbeans.modules.csl.api; import javax.swing.Action; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; /** * A factory class for creating actions provided by CSL. @@ -119,6 +120,7 @@ * @param originalAction - the action to wrap around; may be {@code null}. * @param next - {@code true} for navigating to next; {@code false} for previous. * + * @deprecated use {@link CamelCaseInterceptor} instead * @return the action; never {@code null}. */ public static Action createCamelCasePositionAction(Action originalAction, boolean next) { @@ -132,6 +134,7 @@ * @param originalAction - the action to wrap around; may be {@code null}. * @param next - {@code true} for navigating to next; {@code false} for previous. * + * @deprecated use {@link CamelCaseInterceptor} instead * @return the action; never {@code null}. */ public static Action createDeleteToCamelCasePositionAction(Action originalAction, boolean next) { @@ -145,6 +148,7 @@ * @param originalAction - the action to wrap around; may be {@code null}. * @param next - {@code true} for navigating to next; {@code false} for previous. * + * @deprecated use {@link CamelCaseInterceptor} instead * @return the action; never {@code null}. */ public static Action createSelectCamelCasePositionAction(Action originalAction, boolean next) { diff --git a/csl.api/src/org/netbeans/modules/csl/api/KeystrokeHandler.java b/csl.api/src/org/netbeans/modules/csl/api/KeystrokeHandler.java --- a/csl.api/src/org/netbeans/modules/csl/api/KeystrokeHandler.java +++ b/csl.api/src/org/netbeans/modules/csl/api/KeystrokeHandler.java @@ -50,6 +50,10 @@ import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.annotations.common.NonNull; import org.netbeans.modules.csl.spi.ParserResult; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; +import org.netbeans.spi.editor.typinghooks.DeletedTextInterceptor; +import org.netbeans.spi.editor.typinghooks.TypedBreakInterceptor; +import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor; /** @@ -57,6 +61,7 @@ * editing. * * @author Tor Norbye + * @deprecated use interceptors {@link CamelCaseInterceptor} {@link DeletedTextInterceptor} {@link TypedTextInterceptor} {@link TypedBreakInterceptor} instead. */ public interface KeystrokeHandler { /** diff --git a/csl.api/src/org/netbeans/modules/csl/core/CslCamelCaseInterceptor.java b/csl.api/src/org/netbeans/modules/csl/core/CslCamelCaseInterceptor.java new file mode 100644 --- /dev/null +++ b/csl.api/src/org/netbeans/modules/csl/core/CslCamelCaseInterceptor.java @@ -0,0 +1,90 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.csl.core; + +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.api.editor.mimelookup.MimeRegistrations; +import org.netbeans.modules.csl.api.KeystrokeHandler; +import org.netbeans.modules.csl.api.UiUtils; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; +import org.netbeans.spi.editor.typinghooks.TypedBreakInterceptor; + +public class CslCamelCaseInterceptor implements CamelCaseInterceptor { + + @Override + public boolean beforeChange(MutableContext context) throws BadLocationException { + return false; + } + + @Override + public void change(MutableContext context) throws BadLocationException { + int offset = context.getOffset(); + Document doc = context.getDocument(); + + KeystrokeHandler bc = UiUtils.getBracketCompletion(doc, offset); + if (bc != null) { + int nextOffset = bc.getNextWordOffset(doc, offset, context.isBackward()); + context.setNextWordOffset(nextOffset); + } + } + + @Override + public void afterChange(MutableContext context) throws BadLocationException { + } + + @Override + public void cancelled(MutableContext context) { + } + + @MimeRegistrations(value = { + @MimeRegistration(mimeType = "", service = CamelCaseInterceptor.Factory.class)}) + public static class Factory implements CamelCaseInterceptor.Factory { + + @Override + public CamelCaseInterceptor createCamelCaseInterceptor(MimePath mimePath) { + return new CslCamelCaseInterceptor(); + } + } +} diff --git a/csl.api/src/org/netbeans/modules/csl/core/CslEditorKit.java b/csl.api/src/org/netbeans/modules/csl/core/CslEditorKit.java --- a/csl.api/src/org/netbeans/modules/csl/core/CslEditorKit.java +++ b/csl.api/src/org/netbeans/modules/csl/core/CslEditorKit.java @@ -67,21 +67,17 @@ import org.netbeans.editor.ext.ExtSyntaxSupport; import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager; import org.netbeans.modules.csl.api.CslActions; -import org.netbeans.modules.csl.api.DeleteToNextCamelCasePosition; -import org.netbeans.modules.csl.api.DeleteToPreviousCamelCasePosition; -import org.netbeans.modules.csl.api.GoToDeclarationAction; import org.netbeans.modules.csl.api.InstantRenameAction; import org.netbeans.modules.csl.api.KeystrokeHandler; -import org.netbeans.modules.csl.api.NextCamelCasePosition; import org.netbeans.modules.csl.api.OffsetRange; -import org.netbeans.modules.csl.api.PreviousCamelCasePosition; import org.netbeans.modules.csl.api.SelectCodeElementAction; -import org.netbeans.modules.csl.api.SelectNextCamelCasePosition; -import org.netbeans.modules.csl.api.SelectPreviousCamelCasePosition; import org.netbeans.modules.csl.api.ToggleBlockCommentAction; import org.netbeans.modules.csl.api.UiUtils; import org.netbeans.modules.csl.api.GoToMarkOccurrencesAction; import org.netbeans.modules.editor.NbEditorKit; +import org.netbeans.spi.editor.typinghooks.DeletedTextInterceptor; +import org.netbeans.spi.editor.typinghooks.TypedBreakInterceptor; +import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor; import org.openide.awt.Mnemonics; import org.openide.filesystems.FileObject; import org.openide.util.Exceptions; @@ -182,14 +178,6 @@ actions.add(new GenericGenerateGoToPopupAction()); actions.add(new SelectCodeElementAction(SelectCodeElementAction.selectNextElementAction, true)); actions.add(new SelectCodeElementAction(SelectCodeElementAction.selectPreviousElementAction, false)); - //actions.add(new ExpandAllCodeBlockFolds()); - //actions.add(new CollapseAllCodeBlockFolds()); - actions.add(new NextCamelCasePosition(findAction(superActions, nextWordAction))); - actions.add(new PreviousCamelCasePosition(findAction(superActions, previousWordAction))); - actions.add(new SelectNextCamelCasePosition(findAction(superActions, selectionNextWordAction))); - actions.add(new SelectPreviousCamelCasePosition(findAction(superActions, selectionPreviousWordAction))); - actions.add(new DeleteToNextCamelCasePosition(findAction(superActions, removeNextWordAction))); - actions.add(new DeleteToPreviousCamelCasePosition(findAction(superActions, removePreviousWordAction))); if (language == null) { LOG.log(Level.WARNING, "Language missing for MIME type {0}", mimeType); @@ -231,6 +219,9 @@ return true; } + /** + * @deprecated use {@link TypedTextInterceptor} instead + */ private final class GsfDefaultKeyTypedAction extends ExtDefaultKeyTypedAction { private JTextComponent currentTarget; private String replacedText = null; @@ -318,6 +309,9 @@ } } + /** + * @deprecated use {@link TypedBreakInterceptor} instead + */ private final class GsfInsertBreakAction extends InsertBreakAction { static final long serialVersionUID = -1506173310438326380L; @@ -363,6 +357,9 @@ } } + /** + * @deprecated use {@link DeletedTextInterceptor} instead + */ private final class GsfDeleteCharAction extends ExtDeleteCharAction { private JTextComponent currentTarget; diff --git a/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java b/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java --- a/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java +++ b/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java @@ -123,7 +123,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Enumeration; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -139,6 +141,7 @@ import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; import javax.swing.text.Element; +import junit.framework.Assert; import org.netbeans.api.annotations.common.NullAllowed; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; @@ -199,6 +202,9 @@ import org.netbeans.spi.editor.bracesmatching.BracesMatcherFactory; import org.netbeans.spi.editor.bracesmatching.MatcherContext; import org.netbeans.spi.java.classpath.ClassPathProvider; +import org.openide.filesystems.MultiFileSystem; +import org.openide.filesystems.Repository; +import org.openide.filesystems.XMLFileSystem; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; import org.openide.util.test.MockLookup; @@ -213,6 +219,7 @@ } private Map classPathsForTest; + private static Object[] extraLookupContent = null; @Override protected void setUp() throws Exception { @@ -227,8 +234,35 @@ assert cache != null; CacheFolder.setCacheFolder(cache); - // This has to be before touching ClassPath class - MockLookup.setInstances(new TestClassPathProvider(), new TestPathRecognizer()); + List layers = new LinkedList(); + String[] additionalLayers = new String[]{"META-INF/generated-layer.xml"}; + Object[] additionalLookupContent = new Object[0]; + + for (int cntr = 0; cntr < additionalLayers.length; cntr++) { + boolean found = false; + + for (Enumeration en = Thread.currentThread().getContextClassLoader().getResources(additionalLayers[cntr]); en.hasMoreElements(); ) { + found = true; + layers.add(en.nextElement()); + } + + Assert.assertTrue(additionalLayers[cntr], found); + } + + XMLFileSystem xmlFS = new XMLFileSystem(); + xmlFS.setXmlUrls(layers.toArray(new URL[0])); + + FileSystem system = new MultiFileSystem(new FileSystem[] {FileUtil.createMemoryFileSystem(), xmlFS}); + + Repository repository = new Repository(system); + // This has to be before touching ClassPath cla + + extraLookupContent = new Object[additionalLookupContent.length + 1]; + + System.arraycopy(additionalLookupContent, 0, extraLookupContent, 1, additionalLookupContent.length); + + extraLookupContent[0] = repository; + MockLookup.setInstances(extraLookupContent, new TestClassPathProvider(), new TestPathRecognizer()); classPathsForTest = createClassPathsForTest(); if (classPathsForTest != null) { diff --git a/csl.api/test/unit/src/org/netbeans/modules/csl/editor/TypingCompletion.java b/csl.api/test/unit/src/org/netbeans/modules/csl/editor/TypingCompletion.java new file mode 100644 diff --git a/editor.actions/nbproject/project.properties b/editor.actions/nbproject/project.properties --- a/editor.actions/nbproject/project.properties +++ b/editor.actions/nbproject/project.properties @@ -43,7 +43,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.7 javadoc.title=Editor Actions -spec.version.base=1.21.0 +spec.version.base=1.22.0 #javadoc.arch=${basedir}/arch.xml #javadoc.apichanges=${basedir}/apichanges.xml diff --git a/editor.actions/nbproject/project.xml b/editor.actions/nbproject/project.xml --- a/editor.actions/nbproject/project.xml +++ b/editor.actions/nbproject/project.xml @@ -86,6 +86,15 @@ + org.netbeans.modules.editor.util + + + + 1 + 1.53 + + + org.openide.util diff --git a/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties b/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties --- a/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties +++ b/editor.actions/src/org/netbeans/modules/editor/actions/Bundle.properties @@ -61,3 +61,10 @@ move-code-element-up_menu_text=Move Code Element &Up move-code-element-down=Move Code Element Down move-code-element-down_menu_text=Move Code Element &Down + +remove-word-previous=Delete Previous Word +remove-word-next=Delete Next Word +caret-next-word=Insertion Point to Next Word +caret-previous-word=Insertion Point to Previous Word +selection-next-word=Extend Selection to Next Word +selection-previous-word=Extend Selection to Previous Word \ No newline at end of file diff --git a/editor.actions/src/org/netbeans/modules/editor/actions/CamelCaseActions.java b/editor.actions/src/org/netbeans/modules/editor/actions/CamelCaseActions.java new file mode 100644 --- /dev/null +++ b/editor.actions/src/org/netbeans/modules/editor/actions/CamelCaseActions.java @@ -0,0 +1,232 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 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 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.editor.actions; + +import java.awt.event.ActionEvent; +import java.util.Map; +import javax.swing.text.BadLocationException; +import javax.swing.text.Caret; +import javax.swing.text.DefaultEditorKit; +import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.EditorActionRegistration; +import org.netbeans.editor.BaseCaret; +import org.netbeans.editor.BaseDocument; +import org.netbeans.editor.BaseKit; +import org.netbeans.editor.Utilities; +import org.netbeans.lib.editor.util.swing.DocumentUtilities; +import org.netbeans.modules.editor.lib2.RectangularSelectionUtils; +import org.netbeans.modules.editor.lib2.typinghooks.CamelCaseInterceptorsManager; +import org.netbeans.spi.editor.AbstractEditorAction; + + +public class CamelCaseActions { + + /* package */ static final String deleteNextCamelCasePosition = "delete-next-camel-case-position"; //NOI18N + static final String SYSTEM_ACTION_CLASS_NAME_PROPERTY = "systemActionClassName"; + + public static abstract class CamelCaseAction extends AbstractEditorAction { + + public CamelCaseAction(Map attrs) { + super(attrs); + } + + public CamelCaseAction() { + } + + @Override + public void actionPerformed(final ActionEvent evt, final JTextComponent target) { + if (target != null) { + if (!target.isEditable() || !target.isEnabled()) { + target.getToolkit().beep(); + return; + } + + final Caret caret = target.getCaret(); + final BaseDocument doc = (BaseDocument)target.getDocument(); + final CamelCaseInterceptorsManager.Transaction t = CamelCaseInterceptorsManager.getInstance().openTransaction(target, caret.getDot(), !isForward()); + try { + if (!t.beforeChange()) { + final Boolean [] result = new Boolean [] { Boolean.FALSE }; + doc.runAtomicAsUser(new Runnable() { + @Override + public void run() { + DocumentUtilities.setTypingModification(doc, true); + Object[] r = t.change(); + try { + int dotPos = caret.getDot(); + int wsPos; + if (r == null) { + if (isForward()) { + int eolPos = Utilities.getRowEnd(doc, dotPos); + wsPos = Utilities.getNextWord(target, dotPos); + wsPos = (dotPos == eolPos) ? wsPos : Math.min(eolPos, wsPos); + } else { + int bolPos = Utilities.getRowStart(doc, dotPos); + wsPos = Utilities.getPreviousWord(target, dotPos); + wsPos = (dotPos == bolPos) ? wsPos : Math.max(bolPos, wsPos); + } + } else { + wsPos = (Integer) r[0]; + } + + if (isForward()) { + moveToNewOffset(target, dotPos, wsPos - dotPos); + } else { + moveToNewOffset(target, wsPos, dotPos - wsPos); + } + result[0] = Boolean.TRUE; + } catch (BadLocationException e) { + target.getToolkit().beep(); + } finally { + DocumentUtilities.setTypingModification(doc, false); + } + } + }); + + if(result[0].booleanValue()) { + t.afterChange(); + } + } + } finally { + t.close(); + } + + } + } + + protected abstract boolean isForward(); + protected abstract void moveToNewOffset(JTextComponent target, int offset, int length) throws BadLocationException; + } + + @EditorActionRegistration(name = BaseKit.removeNextWordAction) + public static class RemoveWordNextAction extends CamelCaseAction { + + @Override + protected boolean isForward() { + return true; + } + + @Override + protected void moveToNewOffset(JTextComponent target, int offset, int length) throws BadLocationException { + target.getDocument().remove(offset, length); + } + } + + @EditorActionRegistration(name = BaseKit.removePreviousWordAction) + public static class RemoveWordPreviousAction extends CamelCaseAction { + + @Override + protected boolean isForward() { + return false; + } + + @Override + protected void moveToNewOffset(JTextComponent target, int offset, int length) throws BadLocationException { + target.getDocument().remove(offset, length); + } + } + + @EditorActionRegistration(name = DefaultEditorKit.nextWordAction) + public static class NextCamelCasePosition extends CamelCaseAction { + + @Override + protected boolean isForward() { + return true; + } + + @Override + protected void moveToNewOffset(JTextComponent target, int offset, int length) throws BadLocationException { + target.setCaretPosition(offset+length); + } + } + + + @EditorActionRegistration(name = DefaultEditorKit.previousWordAction) + public static class PreviousCamelCasePosition extends CamelCaseAction { + + @Override + protected boolean isForward() { + return false; + } + + @Override + protected void moveToNewOffset(JTextComponent target, int offset, int length) throws BadLocationException { + target.setCaretPosition(offset); + } + } + + @EditorActionRegistration(name = DefaultEditorKit.selectionNextWordAction) + public static class SelectNextCamelCasePosition extends CamelCaseAction { + + @Override + protected boolean isForward() { + return true; + } + + protected void moveToNewOffset(JTextComponent target, int offset, int length) throws BadLocationException { + Caret caret = target.getCaret(); + if (caret instanceof BaseCaret && RectangularSelectionUtils.isRectangularSelection(target)) { + ((BaseCaret) caret).extendRectangularSelection(true, true); + } else { + target.getCaret().moveDot(offset + length); + } + } + } + + @EditorActionRegistration(name = DefaultEditorKit.selectionPreviousWordAction) + public static class SelectPreviousCamelCasePosition extends CamelCaseAction { + @Override + protected boolean isForward() { + return false; + } + + protected void moveToNewOffset(JTextComponent target, int offset, int length) throws BadLocationException { + Caret caret = target.getCaret(); + if (caret instanceof BaseCaret && RectangularSelectionUtils.isRectangularSelection(target)) { + ((BaseCaret) caret).extendRectangularSelection(false, true); + } else { + target.getCaret().moveDot(offset); + } + } + } + +} 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.7 -spec.version.base=3.40.0 +spec.version.base=3.41.0 is.autoload=true javadoc.arch=${basedir}/arch.xml diff --git a/editor.lib/src/org/netbeans/editor/ActionFactory.java b/editor.lib/src/org/netbeans/editor/ActionFactory.java --- a/editor.lib/src/org/netbeans/editor/ActionFactory.java +++ b/editor.lib/src/org/netbeans/editor/ActionFactory.java @@ -94,6 +94,7 @@ import org.netbeans.api.editor.NavigationHistory; import org.netbeans.modules.editor.lib2.RectangularSelectionUtils; import org.netbeans.modules.editor.lib2.view.DocumentView; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; import org.openide.util.ContextAwareAction; import org.openide.util.ImageUtilities; import org.openide.util.Lookup; @@ -207,41 +208,9 @@ } - /* #47709 - public static class RemoveWordAction extends LocalBaseAction { - - static final long serialVersionUID =9193117196412195554L; - - public RemoveWordAction() { - super(BaseKit.removeWordAction, MAGIC_POSITION_RESET - | ABBREV_RESET | UNDO_MERGE_RESET | WORD_MATCH_RESET); - } - - public void actionPerformed(ActionEvent evt, JTextComponent target) { - if (target != null) { - if (!target.isEditable() || !target.isEnabled()) { - target.getToolkit().beep(); - return; - } - - Caret caret = target.getCaret(); - try { - BaseDocument doc = (BaseDocument)target.getDocument(); - int dotPos = caret.getDot(); - int [] identBlock = Utilities.getIdentifierBlock(doc,dotPos); - if (identBlock != null){ - doc.remove(identBlock[0], identBlock[1] - identBlock[0]); - } - } catch (BadLocationException e) { - target.getToolkit().beep(); - } - } - } - } + /** + * @deprecated use {@link CamelCaseInterceptor} instead */ - - // Disabled annotations due to overriding by camel-case actions in GSF (no concrete mimetype) -// @EditorActionRegistration(name = BaseKit.removePreviousWordAction) public static class RemoveWordPreviousAction extends LocalBaseAction { public RemoveWordPreviousAction() { @@ -278,8 +247,9 @@ } } - // Disabled annotations due to overriding by camel-case actions in GSF (no concrete mimetype) -// @EditorActionRegistration(name = BaseKit.removeNextWordAction) + /** + * @deprecated use {@link CamelCaseInterceptor} instead + */ public static class RemoveWordNextAction extends LocalBaseAction { public RemoveWordNextAction() { diff --git a/editor.lib/src/org/netbeans/editor/BaseKit.java b/editor.lib/src/org/netbeans/editor/BaseKit.java --- a/editor.lib/src/org/netbeans/editor/BaseKit.java +++ b/editor.lib/src/org/netbeans/editor/BaseKit.java @@ -109,6 +109,7 @@ import org.netbeans.modules.editor.lib2.typinghooks.DeletedTextInterceptorsManager; import org.netbeans.modules.editor.lib2.typinghooks.TypedBreakInterceptorsManager; import org.netbeans.modules.editor.lib2.typinghooks.TypedTextInterceptorsManager; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; import org.openide.awt.StatusDisplayer; import org.openide.util.HelpCtx; import org.openide.util.Lookup; @@ -173,9 +174,6 @@ /** Reset the abbreviation accounting string */ public static final String abbrevResetAction = "abbrev-reset"; // NOI18N - /** Remove the word */ - //public static final String removeWordAction = "remove-word"; #47709 - /** Remove characters to the begining of the word or * the previous word if caret is not directly at word */ public static final String removePreviousWordAction = "remove-word-previous"; // NOI18N @@ -873,12 +871,6 @@ undoActionDef, redoActionDef, //new ActionFactory.ToggleLineNumbersAction(), - new NextWordAction(nextWordAction), - new NextWordAction(selectionNextWordAction), - new PreviousWordAction(previousWordAction), - new PreviousWordAction(selectionPreviousWordAction), - new ActionFactory.RemoveWordNextAction(), - new ActionFactory.RemoveWordPreviousAction(), new ActionFactory.ToggleRectangularSelectionAction(), // Self test actions @@ -2761,11 +2753,9 @@ } } - // Disabled annotations due to overriding by camel-case actions in GSF (no concrete mimetype) -// @EditorActionRegistrations({ -// @EditorActionRegistration(name = nextWordAction), -// @EditorActionRegistration(name = selectionNextWordAction) -// }) + /** + * @deprecated use {@link CamelCaseInterceptor} instead + */ public static class NextWordAction extends LocalBaseAction { static final long serialVersionUID =-5909906947175434032L; @@ -2809,11 +2799,9 @@ } } - // Disabled annotations due to overriding by camel-case actions in GSF (no concrete mimetype) -// @EditorActionRegistrations({ -// @EditorActionRegistration(name = previousWordAction), -// @EditorActionRegistration(name = selectionPreviousWordAction) -// }) + /** + * @deprecated use {@link CamelCaseInterceptor} instead + */ public static class PreviousWordAction extends LocalBaseAction { static final long serialVersionUID =-5465143382669785799L; diff --git a/editor.lib/src/org/netbeans/editor/Bundle.properties b/editor.lib/src/org/netbeans/editor/Bundle.properties --- a/editor.lib/src/org/netbeans/editor/Bundle.properties +++ b/editor.lib/src/org/netbeans/editor/Bundle.properties @@ -78,8 +78,6 @@ caret-end-word=Insertion Point to End of Word caret-end=Insertion Point to End of Document caret-forward=Insertion Point Forward -caret-next-word=Insertion Point to Next Word -caret-previous-word=Insertion Point to Previous Word caret-up=Insertion Point Up comment=Comment copy-to-clipboard=Copy @@ -161,10 +159,8 @@ selection-forward=Extend Selection Forward selection-last-non-white=Extend Selection to Last Non-whitespace Char selection-match-brace=Extend Selection to Matching Brace -selection-next-word=Extend Selection to Next Word selection-page-down=Extend Selection to Next Page selection-page-up=Extend Selection to Previous Page -selection-previous-word=Extend Selection to Previous Word selection-up=Extend Selection Up set-dot=Set Dot set-read-only=Set Read Only 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,20 @@ + + + Typing Hooks Camel Case SPI added + + + + + + Typing Hooks Camel Case SPI is addition to Typing Hooks. it allows interception of various key events + that are processed in the editor. The SPI is a replacement for + subclassing editor actions such as RemoveWordNextAction, PreviousCamelCasePosition, etc. + + + SidebarFactory interface adopted diff --git a/editor.lib2/nbproject/org-netbeans-modules-editor-lib2.sig b/editor.lib2/nbproject/org-netbeans-modules-editor-lib2.sig --- a/editor.lib2/nbproject/org-netbeans-modules-editor-lib2.sig +++ b/editor.lib2/nbproject/org-netbeans-modules-editor-lib2.sig @@ -1,8 +1,14 @@ #Signature file v4.1 -#Version 1.71.1 +#Version 1.78.0 + +CLSS public abstract interface java.awt.event.ActionListener +intf java.util.EventListener +meth public abstract void actionPerformed(java.awt.event.ActionEvent) CLSS public abstract interface java.io.Serializable +CLSS public abstract interface java.lang.Cloneable + CLSS public java.lang.Object cons public init() meth protected java.lang.Object clone() throws java.lang.CloneNotSupportedException @@ -54,6 +60,55 @@ supr java.lang.Object hfds serialVersionUID +CLSS public abstract javax.swing.AbstractAction +cons public init() +cons public init(java.lang.String) +cons public init(java.lang.String,javax.swing.Icon) +fld protected boolean enabled +fld protected javax.swing.event.SwingPropertyChangeSupport changeSupport +intf java.io.Serializable +intf java.lang.Cloneable +intf javax.swing.Action +meth protected java.lang.Object clone() throws java.lang.CloneNotSupportedException +meth protected void firePropertyChange(java.lang.String,java.lang.Object,java.lang.Object) +meth public boolean isEnabled() +meth public java.beans.PropertyChangeListener[] getPropertyChangeListeners() +meth public java.lang.Object getValue(java.lang.String) +meth public java.lang.Object[] getKeys() +meth public void addPropertyChangeListener(java.beans.PropertyChangeListener) +meth public void putValue(java.lang.String,java.lang.Object) +meth public void removePropertyChangeListener(java.beans.PropertyChangeListener) +meth public void setEnabled(boolean) +supr java.lang.Object +hfds RECONFIGURE_ON_NULL,arrayTable + +CLSS public abstract interface javax.swing.Action +fld public final static java.lang.String ACCELERATOR_KEY = "AcceleratorKey" +fld public final static java.lang.String ACTION_COMMAND_KEY = "ActionCommandKey" +fld public final static java.lang.String DEFAULT = "Default" +fld public final static java.lang.String DISPLAYED_MNEMONIC_INDEX_KEY = "SwingDisplayedMnemonicIndexKey" +fld public final static java.lang.String LARGE_ICON_KEY = "SwingLargeIconKey" +fld public final static java.lang.String LONG_DESCRIPTION = "LongDescription" +fld public final static java.lang.String MNEMONIC_KEY = "MnemonicKey" +fld public final static java.lang.String NAME = "Name" +fld public final static java.lang.String SELECTED_KEY = "SwingSelectedKey" +fld public final static java.lang.String SHORT_DESCRIPTION = "ShortDescription" +fld public final static java.lang.String SMALL_ICON = "SmallIcon" +intf java.awt.event.ActionListener +meth public abstract boolean isEnabled() +meth public abstract java.lang.Object getValue(java.lang.String) +meth public abstract void addPropertyChangeListener(java.beans.PropertyChangeListener) +meth public abstract void putValue(java.lang.String,java.lang.Object) +meth public abstract void removePropertyChangeListener(java.beans.PropertyChangeListener) +meth public abstract void setEnabled(boolean) + +CLSS public abstract javax.swing.text.TextAction +cons public init(java.lang.String) +meth protected final javax.swing.text.JTextComponent getFocusedComponent() +meth protected final javax.swing.text.JTextComponent getTextComponent(java.awt.event.ActionEvent) +meth public final static javax.swing.Action[] augmentList(javax.swing.Action[],javax.swing.Action[]) +supr javax.swing.AbstractAction + CLSS public final org.netbeans.api.editor.DialogBinding cons public init() meth public static void bindComponentToDocument(javax.swing.text.Document,int,int,int,javax.swing.text.JTextComponent) @@ -83,6 +138,8 @@ anno 0 java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy value=SOURCE) anno 0 java.lang.annotation.Target(java.lang.annotation.ElementType[] value=[TYPE, METHOD]) intf java.lang.annotation.Annotation +meth public abstract !hasdefault boolean noIconInMenu() +meth public abstract !hasdefault boolean noKeyBinding() meth public abstract !hasdefault boolean preferencesDefault() meth public abstract !hasdefault int menuPosition() meth public abstract !hasdefault int popupPosition() @@ -123,6 +180,36 @@ meth public static javax.swing.Action getAction(javax.swing.text.EditorKit,java.lang.String) supr java.lang.Object +CLSS public final org.netbeans.api.editor.NavigationHistory +fld public final static java.lang.String PROP_WAYPOINTS = "NavigationHHistory.PROP_WAYPOINTS" +innr public final static Waypoint +meth public boolean hasNextWaypoints() +meth public boolean hasPreviousWaypoints() +meth public java.util.List getNextWaypoints() +meth public java.util.List getPreviousWaypoints() +meth public org.netbeans.api.editor.NavigationHistory$Waypoint getCurrentWaypoint() +meth public org.netbeans.api.editor.NavigationHistory$Waypoint markWaypoint(javax.swing.text.JTextComponent,int,boolean,boolean) throws javax.swing.text.BadLocationException +meth public org.netbeans.api.editor.NavigationHistory$Waypoint navigateBack() +meth public org.netbeans.api.editor.NavigationHistory$Waypoint navigateFirst() +meth public org.netbeans.api.editor.NavigationHistory$Waypoint navigateForward() +meth public org.netbeans.api.editor.NavigationHistory$Waypoint navigateLast() +meth public org.netbeans.api.editor.NavigationHistory$Waypoint navigateTo(org.netbeans.api.editor.NavigationHistory$Waypoint) +meth public static org.netbeans.api.editor.NavigationHistory getEdits() +meth public static org.netbeans.api.editor.NavigationHistory getNavigations() +meth public void addPropertyChangeListener(java.beans.PropertyChangeListener) +meth public void removePropertyChangeListener(java.beans.PropertyChangeListener) +supr java.lang.Object +hfds LOCK,LOG,PCS,id,instances,pointer,sublistsCache,waypoints +hcls RingBuffer + +CLSS public final static org.netbeans.api.editor.NavigationHistory$Waypoint + outer org.netbeans.api.editor.NavigationHistory +meth public int getOffset() +meth public java.net.URL getUrl() +meth public javax.swing.text.JTextComponent getComponent() +supr java.lang.Object +hfds compRef,navigationHistory,pos,rawIndex,url + CLSS public final org.netbeans.api.editor.document.EditorDocumentUtils meth public static void runExclusive(javax.swing.text.Document,java.lang.Runnable) supr java.lang.Object @@ -137,6 +224,49 @@ supr java.lang.Object hfds INSTANCE +CLSS public abstract org.netbeans.spi.editor.AbstractEditorAction +cons protected init() +cons protected init(java.util.Map) +fld public final static java.lang.String ASYNCHRONOUS_KEY = "asynchronous" +fld public final static java.lang.String DISPLAY_NAME_KEY = "displayName" +fld public final static java.lang.String ICON_RESOURCE_KEY = "iconBase" +fld public final static java.lang.String MENU_TEXT_KEY = "menuText" +fld public final static java.lang.String MIME_TYPE_KEY = "mimeType" +fld public final static java.lang.String MULTI_ACCELERATOR_LIST_KEY = "MultiAcceleratorListKey" +fld public final static java.lang.String NO_ICON_IN_MENU = "noIconInMenu" +fld public final static java.lang.String NO_KEY_BINDING = "no-keybinding" +fld public final static java.lang.String POPUP_TEXT_KEY = "popupText" +fld public final static java.lang.String PREFERENCES_DEFAULT_KEY = "preferencesDefault" +fld public final static java.lang.String PREFERENCES_KEY_KEY = "preferencesKey" +fld public final static java.lang.String PREFERENCES_NODE_KEY = "preferencesNode" +fld public final static java.lang.String WRAPPER_ACTION_KEY = "WrapperActionKey" +intf org.openide.util.actions.Presenter$Menu +intf org.openide.util.actions.Presenter$Popup +intf org.openide.util.actions.Presenter$Toolbar +meth protected abstract void actionPerformed(java.awt.event.ActionEvent,javax.swing.text.JTextComponent) +meth protected boolean asynchronous() +meth protected final java.lang.String actionName() +meth protected final void resetCaretMagicPosition(javax.swing.text.JTextComponent) +meth protected java.lang.Object createValue(java.lang.String) +meth protected void valuesUpdated() +meth public boolean isEnabled() +meth public final java.lang.Object getValue(java.lang.String) +meth public final void actionPerformed(java.awt.event.ActionEvent) +meth public final void putValue(java.lang.String,java.lang.Object) +meth public java.awt.Component getToolbarPresenter() +meth public java.lang.Object[] getKeys() +meth public java.lang.String toString() +meth public javax.swing.JMenuItem getMenuPresenter() +meth public javax.swing.JMenuItem getPopupPresenter() +meth public void setEnabled(boolean) +supr javax.swing.text.TextAction +hfds LOG,LOGGED_ACTION_NAMES,MASK_NULL_VALUE,UILOG,UNITIALIZED_ACTION,attrs,delegateAction,preferencesNodeAndListener,properties,serialVersionUID +hcls DelegateActionPropertyChangeListener,PreferencesNodeAndListener + +CLSS public abstract interface org.netbeans.spi.editor.SideBarFactory + anno 0 org.netbeans.spi.editor.mimelookup.MimeLocation(java.lang.Class instanceProviderClass=class org.netbeans.spi.editor.mimelookup.InstanceProvider, java.lang.String subfolderName="SideBar") +meth public abstract javax.swing.JComponent createSideBar(javax.swing.text.JTextComponent) + CLSS public abstract interface org.netbeans.spi.editor.codegen.CodeGenerator innr public abstract interface static Factory meth public abstract java.lang.String getDisplayName() @@ -373,12 +503,33 @@ CLSS public final static org.netbeans.spi.editor.typinghooks.TypedTextInterceptor$MutableContext outer org.netbeans.spi.editor.typinghooks.TypedTextInterceptor +meth public java.lang.String getReplacedText() meth public java.lang.String getText() meth public void setText(java.lang.String,int) supr org.netbeans.spi.editor.typinghooks.TypedTextInterceptor$Context -hfds caretPosition,insertionText +hfds caretPosition,insertionText,replacedText hcls Accessor CLSS public abstract interface org.openide.util.Cancellable meth public abstract boolean cancel() +CLSS public abstract interface org.openide.util.actions.Presenter +innr public abstract interface static Menu +innr public abstract interface static Popup +innr public abstract interface static Toolbar + +CLSS public abstract interface static org.openide.util.actions.Presenter$Menu + outer org.openide.util.actions.Presenter +intf org.openide.util.actions.Presenter +meth public abstract javax.swing.JMenuItem getMenuPresenter() + +CLSS public abstract interface static org.openide.util.actions.Presenter$Popup + outer org.openide.util.actions.Presenter +intf org.openide.util.actions.Presenter +meth public abstract javax.swing.JMenuItem getPopupPresenter() + +CLSS public abstract interface static org.openide.util.actions.Presenter$Toolbar + outer org.openide.util.actions.Presenter +intf org.openide.util.actions.Presenter +meth public abstract java.awt.Component getToolbarPresenter() + 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.7 javac.compilerargs=-Xlint:unchecked -spec.version.base=1.78.0 +spec.version.base=1.79.0 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/DeletedTextInterceptorsManager.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/CamelCaseInterceptorsManager.java copy from editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/DeletedTextInterceptorsManager.java copy to editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/CamelCaseInterceptorsManager.java --- a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/DeletedTextInterceptorsManager.java +++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/CamelCaseInterceptorsManager.java @@ -51,6 +51,7 @@ import java.util.WeakHashMap; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.JTextComponent; import org.netbeans.api.editor.mimelookup.MimeLookup; @@ -58,13 +59,9 @@ import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.lib.editor.util.swing.DocumentUtilities; -import org.netbeans.spi.editor.typinghooks.DeletedTextInterceptor; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; -/** - * - * @author vita - */ -public final class DeletedTextInterceptorsManager { +public final class CamelCaseInterceptorsManager { static MimePath getMimePath(final Document doc, final int offset) { final MimePath[] mimePathR = new MimePath[1]; @@ -80,17 +77,17 @@ return mimePathR[0]; } - public static DeletedTextInterceptorsManager getInstance() { + public static CamelCaseInterceptorsManager getInstance() { if (instance == null) { - instance = new DeletedTextInterceptorsManager(); + instance = new CamelCaseInterceptorsManager(); } return instance; } - public Transaction openTransaction(JTextComponent c, int offset, String removedText, boolean backwardDelete) { + public Transaction openTransaction(JTextComponent c, int offset, boolean backward) { synchronized (this) { if (transaction == null) { - transaction = new Transaction(c, offset, removedText, backwardDelete); + transaction = new Transaction(c, offset, backward); return transaction; } else { throw new IllegalStateException("Too many transactions; only one at a time is allowed!"); //NOI18N @@ -100,14 +97,14 @@ public final class Transaction { - public boolean beforeRemove() { - for(DeletedTextInterceptor i : interceptors) { + public boolean beforeChange() { + for(CamelCaseInterceptor i : interceptors) { try { - if (i.beforeRemove(context)) { + if (i.beforeChange(context)) { return true; } - } catch (Exception e) { - LOG.log(Level.INFO, "DeletedTextInterceptor crashed in beforeRemove(): " + i, e); //NOI18N + } catch (BadLocationException e) { + LOG.log(Level.INFO, "DeleteWordInterceptor crashed in beforeRemove(): " + i, e); //NOI18N } } @@ -115,27 +112,33 @@ return false; } - public void textDeleted() { + public Object[] change() { Object [] data = null; - for(DeletedTextInterceptor i : interceptors) { + for(CamelCaseInterceptor i : interceptors) { try { - i.remove(context); - } catch (Exception e) { - LOG.log(Level.INFO, "DeletedTextInterceptor crashed in remove(): " + i, e); //NOI18N + i.change(context); + } catch (BadLocationException e) { + LOG.log(Level.INFO, "DeleteWordInterceptor crashed in remove(): " + i, e); //NOI18N continue; } + + data = TypingHooksSpiAccessor.get().getDwiContextData(context); + if (data != null) { + break; + } } phase++; + return data; } - public void afterRemove() { - for(DeletedTextInterceptor i : interceptors) { + public void afterChange() { + for(CamelCaseInterceptor i : interceptors) { try { - i.afterRemove(context); - } catch (Exception e) { - LOG.log(Level.INFO, "DeletedTextInterceptor crashed in afterRemove(): " + i, e); //NOI18N + i.afterChange(context); + } catch (BadLocationException e) { + LOG.log(Level.INFO, "DeleteWordInterceptor crashed in afterRemove(): " + i, e); //NOI18N } } @@ -144,16 +147,16 @@ public void close() { if (phase < 3) { - for(DeletedTextInterceptor i : interceptors) { + for(CamelCaseInterceptor i : interceptors) { try { i.cancelled(context); } catch (Exception e) { - LOG.log(Level.INFO, "DeletedTextInterceptor crashed in cancelled(): " + i, e); //NOI18N + LOG.log(Level.INFO, "DeleteWordInterceptor crashed in cancelled(): " + i, e); //NOI18N } } } - synchronized (DeletedTextInterceptorsManager.this) { + synchronized (CamelCaseInterceptorsManager.this) { transaction = null; } } @@ -162,12 +165,12 @@ // Private implementation // ------------------------------------------------------------------------ - private final DeletedTextInterceptor.Context context; - private final Collection interceptors; + private final CamelCaseInterceptor.MutableContext context; + private final Collection interceptors; private int phase = 0; - private Transaction(JTextComponent c, int offset, String removedText, boolean backwardDelete) { - this.context = TypingHooksSpiAccessor.get().createDtiContext(c, offset, removedText, backwardDelete); + private Transaction(JTextComponent c, int offset, boolean backwardDelete) { + this.context = TypingHooksSpiAccessor.get().createDwiContext(c, offset, backwardDelete); this.interceptors = getInterceptors(c.getDocument(), offset); } } // End of Transaction class @@ -176,34 +179,34 @@ // Private implementation // ------------------------------------------------------------------------ - private static final Logger LOG = Logger.getLogger(DeletedTextInterceptorsManager.class.getName()); + private static final Logger LOG = Logger.getLogger(CamelCaseInterceptorsManager.class.getName()); - private static DeletedTextInterceptorsManager instance; + private static CamelCaseInterceptorsManager instance; private Transaction transaction = null; - private final Map>> cache = new WeakHashMap>>(); + private final Map>> cache = new WeakHashMap<>(); - private DeletedTextInterceptorsManager() { + private CamelCaseInterceptorsManager() { } // XXX: listne on changes in MimeLookup - private Collection getInterceptors(Document doc, int offset) { + private Collection getInterceptors(Document doc, int offset) { MimePath mimePath = getMimePath(doc, offset); synchronized (cache) { - Reference> ref = cache.get(mimePath); - Collection interceptors = ref == null ? null : ref.get(); + Reference> ref = cache.get(mimePath); + Collection interceptors = ref == null ? null : ref.get(); if (interceptors == null) { - Collection factories = MimeLookup.getLookup(mimePath).lookupAll(DeletedTextInterceptor.Factory.class); - interceptors = new HashSet(factories.size()); + Collection factories = MimeLookup.getLookup(mimePath).lookupAll(CamelCaseInterceptor.Factory.class); + interceptors = new HashSet<>(factories.size()); if (LOG.isLoggable(Level.FINE)) { - LOG.log(Level.FINE, "DeletedTextInterceptor.Factory instances for {0}:" , mimePath.getPath()); //NOI18N + LOG.log(Level.FINE, "CamelCaseInterceptor.Factory instances for {0}:" , mimePath.getPath()); //NOI18N } - for(DeletedTextInterceptor.Factory f : factories) { - DeletedTextInterceptor interceptor = f.createDeletedTextInterceptor(mimePath); + for(CamelCaseInterceptor.Factory f : factories) { + CamelCaseInterceptor interceptor = f.createCamelCaseInterceptor(mimePath); if (interceptor != null) { interceptors.add(interceptor); } @@ -217,7 +220,7 @@ } // XXX: this should really be a timed WeakReference - cache.put(mimePath, new SoftReference>(interceptors)); + cache.put(mimePath, new SoftReference<>(interceptors)); } return interceptors; diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java --- a/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java +++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/typinghooks/TypingHooksSpiAccessor.java @@ -41,6 +41,7 @@ import javax.swing.text.JTextComponent; import javax.swing.text.Position; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; import org.netbeans.spi.editor.typinghooks.DeletedTextInterceptor; import org.netbeans.spi.editor.typinghooks.TypedBreakInterceptor; import org.netbeans.spi.editor.typinghooks.TypedTextInterceptor; @@ -79,6 +80,8 @@ public abstract void resetTtiContextData(TypedTextInterceptor.MutableContext context); public abstract DeletedTextInterceptor.Context createDtiContext(JTextComponent c, int offset, String removedText, boolean backwardDelete); + public abstract Object [] getDwiContextData(CamelCaseInterceptor.MutableContext context); + public abstract CamelCaseInterceptor.MutableContext createDwiContext(JTextComponent c, int offset, boolean backwardDelete); public abstract TypedBreakInterceptor.MutableContext createTbiContext(JTextComponent c, int caretOffset, int insertBreakOffset); public abstract Object [] getTbiContextData(TypedBreakInterceptor.MutableContext context); diff --git a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/DeletedTextInterceptor.java b/editor.lib2/src/org/netbeans/spi/editor/typinghooks/CamelCaseInterceptor.java copy from editor.lib2/src/org/netbeans/spi/editor/typinghooks/DeletedTextInterceptor.java copy to editor.lib2/src/org/netbeans/spi/editor/typinghooks/CamelCaseInterceptor.java --- a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/DeletedTextInterceptor.java +++ b/editor.lib2/src/org/netbeans/spi/editor/typinghooks/CamelCaseInterceptor.java @@ -48,14 +48,17 @@ import org.netbeans.api.editor.mimelookup.MimePath; /** - * An interceptor which is called when user deletes text from a document. You should + * An interceptor which is called when user use camel case action. You should * implement this interface if you want to hook in the keyboard input - * processing done in the editor infrastructure that would normally result in removing text - * from a document. Typically, implementations of this interface will be called + * processing done in the editor infrastructure that would normally result in removing word + * from a document, selecting word or moving to next word. Typically, implementations of this interface will be called * when processing KeyEvents that reach the default editor actions bound to - * VK_DELETE and VK_BACK_SPACE events. + * CTRL+DEL, CTRL+BACKSPACE, CTRL+RIGHT_ARROW, CTRL+LEFT_ARROW, CTRL+SHIFT+RIGHT_ARROW, CTRL+SHIFT+LEFT_ARROW events. * - *

Registration: DeletedTextInterceptors can be plugged in the editor infrastructure + *

When you set nextWordOffset, the implementation deletes/jumps according to this value. If value is not set or set to -1, + * the default implementation of camel case action is performed. + * + *

Registration: CamelCaseInterceptors can be plugged in the editor infrastructure * by implementing the {@link Factory} interface and registering it in MimeLookup * under the appropriate mimetype (ie. MimePath). * @@ -66,7 +69,7 @@ * the interceptors are guaranteed to be called in AWT thread only, which means that * they should not need any internal synchronization model. * - *

Processing rules: If there are multiple instances of DeletedTextInterceptor registered + *

Processing rules: If there are multiple instances of CamelCaseInterceptor registered * for the same mime type the infrastructure will queue them up in their registration * order and when processing an event it will call them all until the processing is done * or terminated. @@ -78,45 +81,17 @@ * all the queued interceptors before moving on to the next stage and calling next * method. * - *

    - *
  • {@link #beforeRemove(Context)} - It's called before any text is removed - * from a document. No document lock is held when this method is called. The method - * is not allowed to modify the document (and it's not supposed to do any tricks to - * break this rule). An interceptor can stop further processing of the event by returning - * true from this method. If it does so, no other interceptors' - * beforeRemove method will be called and the processing will be terminated - * without removing any text. - * - *
  • {@link #remove(Context)} - This method is called during the text - * removal stage immediately after the text was removed from a document. At this - * time the document is already write locked and the interceptors can modify it - * if they need to. - * - *
  • {@link #afterRemove(Context)} - This is the last method in the processing - * chain and it will be called when the text has already been removed from the document. - * Similarly as in beforeRemove the document is not locked when - * this method is called. - * - *
  • {@link #cancelled(Context)} - This is an additional method that will be called - * when the processing is terminated in the before-removal stage (ie. by an interceptor - * returning true from its beforeRemove method). - * The infrastructure will only call this method on interceptors that have already - * had their beforeRemove method called, but not on those that - * have not yet been called at all. - *
- * *

Errors recovery: If an exception is thrown from any of the methods * when calling an interceptor the infrastructure will catch it and log it, * but it will not stop further processing. The infrastructure may blacklist the offending * interceptor and exclude it from processing future events. * - * @author Vita Stejskal - * @since 1.31 + * @since 1.79 */ -public interface DeletedTextInterceptor { +public interface CamelCaseInterceptor { /** - * This method is called before any text is removed from a document. The context object + * This method is called before any text is removed from a document or before caret move. The context object * passed to the method provides access to the document and its editor pane. The interceptors * are not allowed to modify the document in this method. * @@ -138,10 +113,10 @@ * @throws BadLocationException Since the document is not locked prior calling this * method the processing may fail when working with stale context data. */ - boolean beforeRemove(Context context) throws BadLocationException; + boolean beforeChange(MutableContext context) throws BadLocationException; /** - * This method is called immediately after the text is removed from a document. + * This method is called immediately after the text is removed from a document or caret is moved. * Implementors can modify the document as they need. The document and all * the other useful information is accessible from the Context object * passed in this method. The document is write-locked. @@ -154,10 +129,10 @@ * * @throws BadLocationException If the processing fails. */ - void remove(Context context) throws BadLocationException; + void change(MutableContext context) throws BadLocationException; /** - * This method is called after text is removed from a document and its editor's + * This method is called after text is removed from a document and/or its editor's * caret is adjusted. * *

Locking: When this method is called the document is not locked @@ -170,24 +145,24 @@ * @throws BadLocationException Since the document is not locked prior calling this * method the processing may fail when working with stale context data. */ - void afterRemove(Context context) throws BadLocationException; + void afterChange(MutableContext context) throws BadLocationException; /** * This method is called when the normal processing is terminated by some - * interceptor's beforeRemove method. Please note that this - * method will not be called if the beforeRemove method was not + * interceptor's beforeChange method. Please note that this + * method will not be called if the beforeChange method was not * called. * - * @param context The context object used for calling the beforeRemove + * @param context The context object used for calling the beforeChange * method. */ - void cancelled(Context context); + void cancelled(MutableContext context); /** * The context class providing information about the edited document, its - * editor pane and the offset where the delete key event occurred. + * editor pane and the offset where the key event occurred. */ - public static final class Context { + public static final class MutableContext { /** * Gets the editor component where the currently processed key typed event @@ -210,27 +185,22 @@ } /** - * Gets the removal offset. This is the offset in the document where - * a user performed the delete action (ie. where the currently processed KeyEvent - * happened). This is also the offset with text, which will be removed. + * Gets the offset. This is the offset in the document where + * a user performed the camel case action (ie. where the currently processed KeyEvent + * happened). This is also the offset with text, which will be removed or jumped. * * @return The offset in the edited document. */ public int getOffset() { return offset; } - -// XXX: since this is always one (character) it make no sense to have it -// public int getLength() { -// return lenght; -// } /** - * Determines the type of the character removal action performed by a user. The two + * Determines the type of the direction performed by a user. The two * possible actions are called differently on different platforms, * but they are always defined by the position of a character, which they are - * applied to. The backspace action deletes a character on the left hand - * side of a caret, while the delete action deletes a character on + * applied to. The backspace/left arrow action deletes/jumps a character on the left hand + * side of a caret, while the delete/right arrow action deletes/jumps a character on * the right hand side of the caret. * *

In other words one delete action removes characters backwards moving @@ -242,20 +212,17 @@ * backspace action. false if the handled action is the * delete action. */ - public boolean isBackwardDelete() { - return backwardDelete; + public boolean isBackward() { + return backward; } - + /** - * Gets the text being removed. In beforeRemove method this - * text is still present in the document, while in the other methods this - * text has already been removed from the document. Nevertheless this method - * always returns a copy of the text. - * - * @return The text being removed by the currently processed key typed event. + * Sets the new offset after remove or jump. + * + * @param nextWordOffset == -1 if default implementation should process otherwise nextWordOffset is used to jump/delete */ - public String getText() { - return removedText; + public void setNextWordOffset(int nextWordOffset) { + this.nextWordOffset = nextWordOffset; } // ------------------------------------------------------------------- @@ -265,33 +232,32 @@ private final JTextComponent component; private final Document document; private final int offset; - private final boolean backwardDelete; - private final String removedText; + private final boolean backward; + private int nextWordOffset = -1; - /* package */ Context(JTextComponent component, int offset, String removedText, boolean backwardDelete) { + /* package */ MutableContext(JTextComponent component, int offset, boolean backwardDelete) { this.component = component; this.document = component.getDocument(); this.offset = offset; - this.backwardDelete = backwardDelete; - this.removedText = removedText; + this.backward = backwardDelete; } + + Object[] getData() { + return nextWordOffset != -1 ? new Object[] {nextWordOffset} : null; + } + + } // End of Context class /** - * The factory interface for registering DeletedTextInterceptors - * in MimeLookup. An example registration in an XML layer shown - * below registers Factory implementation under text/x-something - * mime type in MimeLookup. + * The factory interface for registering CamelCaseInterceptors + * in MimeLookup. An example registration with java annotations. + * * *

-     * <folder name="Editors">
-     *  <folder name="text">
-     *   <folder name="x-something">
-     *    <file name="org-some-module-DTIFactory.instance" />
-     *   </folder>
-     *  </folder>
-     * </folder>
+     * @MimeRegistrations({
+     *  @MimeRegistration(mimeType = "x-something", service = CamelCaseInterceptor.Factory.class)})
      * 
*/ public interface Factory { @@ -306,6 +272,6 @@ * * @return The new interceptor. */ - DeletedTextInterceptor createDeletedTextInterceptor(MimePath mimePath); + CamelCaseInterceptor createCamelCaseInterceptor(MimePath mimePath); } // End of Factory interface } diff --git a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java b/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java --- a/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java +++ b/editor.lib2/src/org/netbeans/spi/editor/typinghooks/TypedTextInterceptor.java @@ -354,6 +354,11 @@ } @Override + public CamelCaseInterceptor.MutableContext createDwiContext(JTextComponent c, int offset, boolean backwardDelete) { + return new CamelCaseInterceptor.MutableContext(c, offset, backwardDelete); + } + + @Override public TypedBreakInterceptor.MutableContext createTbiContext(JTextComponent c, int caretOffset, int insertBreakOffset) { return new TypedBreakInterceptor.MutableContext(c, caretOffset, insertBreakOffset); } @@ -367,6 +372,11 @@ public void resetTbiContextData(TypedBreakInterceptor.MutableContext context) { context.resetData(); } + + @Override + public Object[] getDwiContextData(CamelCaseInterceptor.MutableContext context) { + return context.getData(); + } } // End of Accessor class static { diff --git a/java.editor/nbproject/project.properties b/java.editor/nbproject/project.properties --- a/java.editor/nbproject/project.properties +++ b/java.editor/nbproject/project.properties @@ -42,7 +42,7 @@ javadoc.title=Java Editor -spec.version.base=2.54.0 +spec.version.base=2.55.0 test.qa-functional.cp.extra=${editor.dir}/modules/org-netbeans-modules-editor-fold.jar javac.source=1.7 #test.unit.cp.extra= diff --git a/java.editor/nbproject/project.xml b/java.editor/nbproject/project.xml --- a/java.editor/nbproject/project.xml +++ b/java.editor/nbproject/project.xml @@ -170,7 +170,7 @@ 1 - 1.35 + 1.79
diff --git a/java.editor/src/org/netbeans/modules/editor/java/AbstractCamelCasePosition.java b/java.editor/src/org/netbeans/modules/editor/java/AbstractCamelCasePosition.java deleted file mode 100644 --- a/java.editor/src/org/netbeans/modules/editor/java/AbstractCamelCasePosition.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.editor.java; - -import java.awt.event.ActionEvent; -import java.util.MissingResourceException; -import java.util.prefs.Preferences; -import javax.swing.Action; -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; -import org.netbeans.editor.BaseAction; -import org.netbeans.editor.BaseDocument; -import org.netbeans.lib.editor.util.swing.DocumentUtilities; -import org.openide.util.NbBundle; -import org.openide.util.NbPreferences; - -/** - * - * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com) - */ -/* package */ abstract class AbstractCamelCasePosition extends BaseAction { - - private Action originalAction; - - public AbstractCamelCasePosition(String name, Action originalAction) { - super(name, MAGIC_POSITION_RESET); - - if (originalAction != null) { - Object nameObj = originalAction.getValue(Action.NAME); - if (nameObj instanceof String) { - // We will be wrapping around the original action, use its name - putValue(NAME, nameObj); - this.originalAction = originalAction; - } - } - - String desc = getShortDescription(); - if (desc != null) { - putValue(SHORT_DESCRIPTION, desc); - } - } - - public final void actionPerformed(ActionEvent evt, final JTextComponent target) { - if (target != null) { - if (originalAction != null && !isUsingCamelCase()) { - if (originalAction instanceof BaseAction) { - ((BaseAction) originalAction).actionPerformed(evt, target); - } else { - originalAction.actionPerformed(evt); - } - } else { - final BaseDocument bdoc = org.netbeans.editor.Utilities.getDocument(target); - if (bdoc != null) { - bdoc.runAtomicAsUser(new Runnable () { - public void run () { - DocumentUtilities.setTypingModification(bdoc, true); - try { - int offset = newOffset(target); - if (offset != -1) { - moveToNewOffset(target, offset); - } - } catch (BadLocationException ble) { - target.getToolkit().beep(); - } finally { - DocumentUtilities.setTypingModification(bdoc, false); - } - } - }); - } else { - target.getToolkit().beep(); - } - } - } - } - - protected abstract int newOffset(JTextComponent textComponent) throws BadLocationException; - protected abstract void moveToNewOffset(JTextComponent textComponent, int offset) throws BadLocationException; - - public String getShortDescription(){ - String name = (String)getValue(Action.NAME); - if (name == null) return null; - String shortDesc; - try { - shortDesc = NbBundle.getBundle(JavaKit.class).getString(name); // NOI18N - }catch (MissingResourceException mre){ - shortDesc = name; - } - return shortDesc; - } - - - - private boolean isUsingCamelCase() { - Preferences p = NbPreferences.forModule(AbstractCamelCasePosition.class); - return NbPreferences.root ().getBoolean("useCamelCaseStyleNavigation", true); // NOI18N - } -} diff --git a/java.editor/src/org/netbeans/modules/editor/java/Bundle.properties b/java.editor/src/org/netbeans/modules/editor/java/Bundle.properties --- a/java.editor/src/org/netbeans/modules/editor/java/Bundle.properties +++ b/java.editor/src/org/netbeans/modules/editor/java/Bundle.properties @@ -74,12 +74,6 @@ select-element-next=Select Next Element select-element-previous=Select Previous Element -previous-camel-case-position=Insertion Point to Previous Camel Case Position -next-camel-case-position=Insertion Point to Next Camel Case Position -select-previous-camel-case-position=Extend Selection to Previous Camel Case Position -select-next-camel-case-position=Extend Selection to Next Camel Case Position -delete-previous-camel-case-position=Delete to Previous Camel Case Position -delete-next-camel-case-position=Delete to Next Camel Case Position abbrev-debug-line=Debug Filename and Line Number opening-element=Opening {0}... diff --git a/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java b/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java --- a/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java +++ b/java.editor/src/org/netbeans/modules/editor/java/CamelCaseOperations.java @@ -48,13 +48,18 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.JTextComponent; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.api.editor.mimelookup.MimeRegistrations; import org.netbeans.api.java.lexer.JavaTokenId; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.Utilities; -import org.openide.util.Exceptions; +import static org.netbeans.modules.editor.java.JavaKit.JAVA_MIME_TYPE; +import org.netbeans.spi.editor.typinghooks.CamelCaseInterceptor; +import org.openide.util.NbPreferences; /** * @@ -216,4 +221,49 @@ return Utilities.getPreviousWord((BaseDocument)doc, offset); } + public static class JavaCamelCaseInterceptor implements CamelCaseInterceptor { + + private boolean isUsingCamelCase() { + return NbPreferences.root().getBoolean("useCamelCaseStyleNavigation", true); // NOI18N + } + + @Override + public boolean beforeChange(MutableContext context) throws BadLocationException { + return false; + } + + @Override + public void change(MutableContext context) throws BadLocationException { + if (isUsingCamelCase()) { + if (context.isBackward()) { + context.setNextWordOffset(CamelCaseOperations.previousCamelCasePosition(context.getComponent())); + } else { + context.setNextWordOffset(CamelCaseOperations.nextCamelCasePosition(context.getComponent())); + } + } + } + + @Override + public void afterChange(MutableContext context) throws BadLocationException { + } + + @Override + public void cancelled(MutableContext context) { + } + + @MimeRegistrations({ + @MimeRegistration(mimeType = JAVA_MIME_TYPE, service = CamelCaseInterceptor.Factory.class), + @MimeRegistration(mimeType = "text/x-javadoc", service = CamelCaseInterceptor.Factory.class), //NOI18N + @MimeRegistration(mimeType = "text/x-java-string", service = CamelCaseInterceptor.Factory.class), //NOI18N + @MimeRegistration(mimeType = "text/x-java-character", service = CamelCaseInterceptor.Factory.class) //NOI18N + }) + @MimeRegistration(mimeType = JAVA_MIME_TYPE, service = CamelCaseInterceptor.Factory.class) + public static class JavaFactory implements CamelCaseInterceptor.Factory { + + @Override + public CamelCaseInterceptor createCamelCaseInterceptor(MimePath mimePath) { + return new JavaCamelCaseInterceptor(); + } + } + } } diff --git a/java.editor/src/org/netbeans/modules/editor/java/DeleteToNextCamelCasePosition.java b/java.editor/src/org/netbeans/modules/editor/java/DeleteToNextCamelCasePosition.java deleted file mode 100644 --- a/java.editor/src/org/netbeans/modules/editor/java/DeleteToNextCamelCasePosition.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.editor.java; - -import javax.swing.Action; -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; - -/** - * - * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com) - */ -/* package */ final class DeleteToNextCamelCasePosition extends SelectNextCamelCasePosition { - - public DeleteToNextCamelCasePosition(Action originalAction) { - super(JavaKit.deleteNextCamelCasePosition, originalAction); - } - - protected @Override void moveToNewOffset(JTextComponent textComponent, int offset) throws BadLocationException { - textComponent.getDocument().remove(textComponent.getCaretPosition(), offset - textComponent.getCaretPosition()); - } -} - diff --git a/java.editor/src/org/netbeans/modules/editor/java/DeleteToPreviousCamelCasePosition.java b/java.editor/src/org/netbeans/modules/editor/java/DeleteToPreviousCamelCasePosition.java deleted file mode 100644 --- a/java.editor/src/org/netbeans/modules/editor/java/DeleteToPreviousCamelCasePosition.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.editor.java; - -import javax.swing.Action; -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; - -/** - * - * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com) - */ -/* package */ final class DeleteToPreviousCamelCasePosition extends PreviousCamelCasePosition { - - public DeleteToPreviousCamelCasePosition(Action originalAction) { - super(JavaKit.deletePreviousCamelCasePosition, originalAction); - } - - protected @Override void moveToNewOffset(JTextComponent textComponent, int offset) throws BadLocationException { - textComponent.getDocument().remove(offset, textComponent.getCaretPosition() - offset); - } -} - diff --git a/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java b/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java --- a/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java +++ b/java.editor/src/org/netbeans/modules/editor/java/JavaKit.java @@ -218,18 +218,6 @@ public static final String selectPreviousElementAction = "select-element-previous"; //NOI18N - /* package */ static final String previousCamelCasePosition = "previous-camel-case-position"; //NOI18N - - /* package */ static final String nextCamelCasePosition = "next-camel-case-position"; //NOI18N - - /* package */ static final String selectPreviousCamelCasePosition = "select-previous-camel-case-position"; //NOI18N - - /* package */ static final String selectNextCamelCasePosition = "select-next-camel-case-position"; //NOI18N - - /* package */ static final String deletePreviousCamelCasePosition = "delete-previous-camel-case-position"; //NOI18N - - /* package */ static final String deleteNextCamelCasePosition = "delete-next-camel-case-position"; //NOI18N - // public static Action create(FileObject file) { // initialize(); // @@ -273,13 +261,6 @@ new JavaMoveCodeElementAction(EditorActionNames.moveCodeElementUp, false), new JavaMoveCodeElementAction(EditorActionNames.moveCodeElementDown, true), - new JavaNextWordAction(nextWordAction), - new JavaPreviousWordAction(previousWordAction), - new JavaNextWordAction(selectionNextWordAction), - new JavaPreviousWordAction(selectionPreviousWordAction), - new DeleteToNextCamelCasePosition(findAction(superActions, removeNextWordAction)), - new DeleteToPreviousCamelCasePosition(findAction(superActions, removePreviousWordAction)), - new FastImportAction(), new GoToSuperTypeAction(), @@ -291,16 +272,6 @@ return TextAction.augmentList(superActions, actions); } - private static Action findAction(Action [] actions, String name) { - for(Action a : actions) { - Object nameObj = a.getValue(Action.NAME); - if (nameObj instanceof String && name.equals(nameObj)) { - return a; - } - } - return null; - } - @Override public void install(JEditorPane c) { super.install(c); @@ -837,38 +808,4 @@ } } - - private static boolean isUsingCamelCase() { - return NbPreferences.root().getBoolean("useCamelCaseStyleNavigation", true); // NOI18N - } - - public static class JavaNextWordAction extends NextWordAction { - - JavaNextWordAction(String name) { - super(name); - } - - @Override - protected int getNextWordOffset(JTextComponent target) throws BadLocationException { - return isUsingCamelCase() - ? CamelCaseOperations.nextCamelCasePosition(target) - : super.getNextWordOffset(target); - } - - } - - public static class JavaPreviousWordAction extends PreviousWordAction { - - JavaPreviousWordAction(String name) { - super(name); - } - - protected int getPreviousWordOffset(JTextComponent target) throws BadLocationException { - return isUsingCamelCase() - ? CamelCaseOperations.previousCamelCasePosition(target) - : super.getPreviousWordOffset(target); - } - - } - } diff --git a/java.editor/src/org/netbeans/modules/editor/java/NextCamelCasePosition.java b/java.editor/src/org/netbeans/modules/editor/java/NextCamelCasePosition.java deleted file mode 100644 --- a/java.editor/src/org/netbeans/modules/editor/java/NextCamelCasePosition.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.editor.java; - -import javax.swing.Action; -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; - -/** - * - * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com) - */ -/* package */ class NextCamelCasePosition extends AbstractCamelCasePosition { - - public NextCamelCasePosition(Action originalAction) { - this(JavaKit.nextCamelCasePosition, originalAction); - } - - protected NextCamelCasePosition(String name, Action originalAction) { - super(name, originalAction); - } - - protected int newOffset(JTextComponent textComponent) throws BadLocationException { - return CamelCaseOperations.nextCamelCasePosition(textComponent); - } - - protected void moveToNewOffset(JTextComponent textComponent, int offset) throws BadLocationException { - textComponent.setCaretPosition(offset); - } -} diff --git a/java.editor/src/org/netbeans/modules/editor/java/PreviousCamelCasePosition.java b/java.editor/src/org/netbeans/modules/editor/java/PreviousCamelCasePosition.java deleted file mode 100644 --- a/java.editor/src/org/netbeans/modules/editor/java/PreviousCamelCasePosition.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.editor.java; - -import javax.swing.Action; -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; - -/** - * - * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com) - */ -/* package */ class PreviousCamelCasePosition extends AbstractCamelCasePosition { - - public PreviousCamelCasePosition(Action originalAction) { - this(JavaKit.previousCamelCasePosition, originalAction); - } - - protected PreviousCamelCasePosition(String name, Action originalAction) { - super(name, originalAction); - } - - protected int newOffset(JTextComponent textComponent) throws BadLocationException { - return CamelCaseOperations.previousCamelCasePosition(textComponent); - } - - protected void moveToNewOffset(JTextComponent textComponent, int offset) throws BadLocationException { - textComponent.setCaretPosition(offset); - } -} - diff --git a/java.editor/src/org/netbeans/modules/editor/java/SelectNextCamelCasePosition.java b/java.editor/src/org/netbeans/modules/editor/java/SelectNextCamelCasePosition.java deleted file mode 100644 --- a/java.editor/src/org/netbeans/modules/editor/java/SelectNextCamelCasePosition.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.editor.java; - -import javax.swing.Action; -import javax.swing.text.BadLocationException; -import javax.swing.text.JTextComponent; - -/** - * - * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com) - */ -/* package */ class SelectNextCamelCasePosition extends NextCamelCasePosition { - - public SelectNextCamelCasePosition(Action originalAction) { - this(JavaKit.selectNextCamelCasePosition, originalAction); - } - - protected SelectNextCamelCasePosition(String name, Action originalAction) { - super(name, originalAction); - } - - protected void moveToNewOffset(JTextComponent textComponent, int offset) throws BadLocationException { - textComponent.getCaret().moveDot(offset); - } -} - diff --git a/java.editor/src/org/netbeans/modules/editor/java/SelectPreviousCamelCasePosition.java b/java.editor/src/org/netbeans/modules/editor/java/SelectPreviousCamelCasePosition.java deleted file mode 100644 --- a/java.editor/src/org/netbeans/modules/editor/java/SelectPreviousCamelCasePosition.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.editor.java; - -import javax.swing.Action; -import javax.swing.text.JTextComponent; - -/** - * - * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com) - */ -/* package */ class SelectPreviousCamelCasePosition extends PreviousCamelCasePosition { - - public SelectPreviousCamelCasePosition(Action originalAction) { - this(JavaKit.selectPreviousCamelCasePosition, originalAction); - } - - protected SelectPreviousCamelCasePosition(String name, Action originalAction) { - super(name, originalAction); - } - - protected void moveToNewOffset(JTextComponent textComponent, int offset) { - textComponent.getCaret().moveDot(offset); - } -} -