jtulach commented on code in PR #9433: URL: https://github.com/apache/netbeans/pull/9433#discussion_r3379584649
########## java/kotlin.editor/src/org/netbeans/modules/kotlin/editor/ToggleKotlinBreakpointActionProvider.java: ########## @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.kotlin.editor; + +import java.io.IOException; +import java.net.URI; +import java.util.Collections; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.netbeans.api.debugger.Breakpoint; +import org.netbeans.api.debugger.DebuggerManager; +import org.netbeans.api.debugger.jpda.LineBreakpoint; +import org.netbeans.spi.debugger.*; +import org.netbeans.spi.debugger.jpda.EditorContext; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.URLMapper; +import org.openide.util.Exceptions; [email protected]({ + @ActionsProvider.Registration(path="netbeans-JPDASession", actions={ "toggleBreakpoint" }, activateForMIMETypes={ "text/x-kotlin" }), + @ActionsProvider.Registration(path="", actions={ "toggleBreakpoint" }, activateForMIMETypes={ "text/x-kotlin" }) +}) +public final class ToggleKotlinBreakpointActionProvider extends ActionsProvider { + public ToggleKotlinBreakpointActionProvider() { + } + + @Override + public Set<String> getActions() { + return Collections.singleton("toggleBreakpoint"); + } + + @Override + public void doAction(Object o) { + final DebuggerManager m = DebuggerManager.getDebuggerManager (); + for (EditorContext ctx : m.lookup(null, EditorContext.class)) { + String url = ctx.getCurrentURL(); + int line = ctx.getCurrentLineNumber(); + if (url != null && line >= 0) { + if (!url.endsWith(".kt")) { + continue; + } + if (removeExistingBreakpoint(m, line, url)) { + return; + } + createNewBreakpoint(url, line, m); + return; + } + } + } + + private static final Pattern PACKAGE = Pattern.compile("package *([\\p{Alnum}+\\.$]+) *"); + private void createNewBreakpoint(String url, int line, final DebuggerManager m) { + try { + var b = LineBreakpoint.create(url, line); Review Comment: This is a tedious piece of code that every JVM language needs to write to allow `LineBreakpoint`. I am convinced that `LineBreakpoint` should be a _core debugger feature_ and should be applicable to any line in any file automatically. That's why I'd like to introduce `LineBreakpoint` next to `ide/api.debugger/src/org/netbeans/api/debugger/Breakpoint.java` and automatically handle placing it everywhere (in `.txt` files, or `.md` files, etc.). It would then be up to various debuggers (like JPDA debugger) to pick all such generic `LineBreakpoint`s up and use them. Of course, that would be for a separate PR and review... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
