MartinBalin commented on code in PR #9732: URL: https://github.com/apache/netbeans/pull/9732#discussion_r4314096344
########## java/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/actions/AddLogpointAction.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.debugger.jpda.ui.actions; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.netbeans.api.debugger.DebuggerManager; +import org.netbeans.api.debugger.jpda.JPDABreakpoint; +import org.netbeans.api.debugger.jpda.LineBreakpoint; +import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge; +import org.openide.cookies.EditorCookie; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionRegistration; +import org.openide.util.NbBundle.Messages; + +@ActionID( + category = "Debug", + id = "org.netbeans.modules.debugger.jpda.ui.actions.AddLogpointAction" +) +@ActionRegistration( + displayName = "#CTL_AddLogpointAction" +) +@ActionReference(path = "Editors/text/x-java/Popup", position = 1900) +@Messages({ + "CTL_AddLogpointAction=Add &Logpoint", + "# {0} - clazz name", + "# {1} - method name", + "# {2} - line number", + "# {3} - suffix", + "MSG_LogpointAt=Logpoint at {0}.{1}:{2} {3}" +}) +public final class AddLogpointAction implements ActionListener { + private final EditorCookie context; + + public AddLogpointAction(EditorCookie context) { + this.context = context; + } + + @Override + public void actionPerformed(ActionEvent ev) { + String where = EditorContextBridge.getContext().getCurrentURL(); + int at = EditorContextBridge.getContext().getCurrentLineNumber(); + + LineBreakpoint lb = LineBreakpoint.create(where, at); + lb.setSuspend(JPDABreakpoint.SUSPEND_NONE); + lb.setPrintText(Bundle.MSG_LogpointAt("{className}", "{methodName}", at, "{locals}")); Review Comment: **Log messages retain the original line number after relocation** Passing `at` embeds a literal line number in the saved message. Inserting lines above the logpoint, changing its location, or automatic relocation to an executable line updates the breakpoint but leaves its output reporting the old location. Use the existing `{lineNumber}` placeholder. -- 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
