[hg] main-silver: #237961: Stepping and breakpoints in evaluated...

  • From:
  • To:
  • Subject: [hg] main-silver: #237961: Stepping and breakpoints in evaluated...
  • Date: Mon, 04 Nov 2013 22:52:13 +0000

changeset aea4b7f5204a in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/aea4b7f5204a
description:
        #237961: Stepping and breakpoints in evaluated scripts should work 
now.

diffstat:

 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/FutureLine.java
                     |   98 +++++
 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpoint.java
                   |   17 +-
 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpointAnnotationListener.java
 |  174 +++++++++-
 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSLineBreakpoint.java
               |   63 +++-
 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/JSBreakpointReader.java
          |   10 +-
 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/PersistenceManager.java
          |   13 +-
 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/Source.java 
                             |    2 +
 
debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/SourceURLMapper.java
                     |   17 +-
 
debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/DebuggingNodeModel.java
                  |   13 +-
 
debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
                   |   14 +-
 10 files changed, 389 insertions(+), 32 deletions(-)

diffs (710 lines):

diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/FutureLine.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/FutureLine.java
new file mode 100644
--- /dev/null
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/FutureLine.java
@@ -0,0 +1,98 @@
+/*
+ * 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.debugger.jpda.js.breakpoints;
+
+import java.net.URL;
+import org.openide.text.Line;
+import org.openide.util.lookup.Lookups;
+
+/**
+ *
+ * @author Martin
+ */
+public class FutureLine extends Line {
+    
+    private final URL url;
+    private final int lineNumber;
+    
+    public FutureLine(URL url, int lineNumber) {
+        super(Lookups.fixed());
+        this.url = url;
+        this.lineNumber = lineNumber;
+    }
+
+    @Override
+    public int getLineNumber() {
+        return lineNumber;
+    }
+    
+    public URL getURL() {
+        return url;
+    }
+
+    @Override
+    public void show(int kind, int column) {
+    }
+
+    @Override
+    public void setBreakpoint(boolean b) {
+    }
+
+    @Override
+    public boolean isBreakpoint() {
+        return false;
+    }
+
+    @Override
+    public void markError() {}
+
+    @Override
+    public void unmarkError() {}
+
+    @Override
+    public void markCurrentLine() {}
+
+    @Override
+    public void unmarkCurrentLine() {}
+    
+}
diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpoint.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpoint.java
--- 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpoint.java
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpoint.java
@@ -44,6 +44,7 @@
 import org.netbeans.api.debugger.Breakpoint;
 import org.netbeans.api.debugger.DebuggerManager;
 import org.netbeans.api.debugger.jpda.JPDABreakpoint;
+import org.openide.filesystems.FileObject;
 
 /**
  *
@@ -56,26 +57,28 @@
     private JPDABreakpoint javaBreakpoint;
     private String condition;
 
-    protected JPDABreakpoint getJavaBreakpoint() {
+    protected final JPDABreakpoint getJavaBreakpoint() {
         return javaBreakpoint;
     }
 
-    protected void setJavaBreakpoint(JPDABreakpoint javaBreakpoint) {
+    protected final void setJavaBreakpoint(JPDABreakpoint javaBreakpoint) {
         this.javaBreakpoint = javaBreakpoint;
     }
     
+    abstract protected FileObject getFileObject();
+    
     @Override
-    public boolean isEnabled() {
+    public final boolean isEnabled() {
         return javaBreakpoint.isEnabled();
     }
 
     @Override
-    public void disable() {
+    public final void disable() {
         javaBreakpoint.disable();
     }
 
     @Override
-    public void enable() {
+    public final void enable() {
         javaBreakpoint.enable();
     }
 
@@ -85,11 +88,11 @@
         
DebuggerManager.getDebuggerManager().removeBreakpoint(javaBreakpoint);
     }
 
-    public String getCondition() {
+    public final String getCondition() {
         return condition;
     }
 
-    public void setCondition(String condition) {
+    public final void setCondition(String condition) {
         this.condition = condition;
     }
     
diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpointAnnotationListener.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpointAnnotationListener.java
--- 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpointAnnotationListener.java
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSBreakpointAnnotationListener.java
@@ -41,18 +41,31 @@
  */
 package org.netbeans.modules.debugger.jpda.js.breakpoints;
 
+import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import org.netbeans.api.debugger.Breakpoint;
 import org.netbeans.api.debugger.DebuggerManager;
 import org.netbeans.api.debugger.DebuggerManagerAdapter;
 import org.netbeans.api.debugger.LazyDebuggerManagerListener;
 import org.netbeans.modules.debugger.jpda.js.Context;
+import org.netbeans.modules.debugger.jpda.js.JSUtils;
 import org.netbeans.spi.debugger.DebuggerServiceRegistration;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataObject;
 import org.openide.text.AnnotationProvider;
 import org.openide.text.Line;
 import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.WeakListeners;
+import org.openide.util.WeakSet;
 
 /**
  *
@@ -63,37 +76,142 @@
 public class JSBreakpointAnnotationListener extends DebuggerManagerAdapter
                                             implements AnnotationProvider {
     
+    private static final Logger logger = 
Logger.getLogger(JSBreakpointAnnotationListener.class.getName());
+    
     private final Map<JSBreakpoint, Object> breakpointAnnotations = new 
HashMap<>();
+    private final Set<FileObject> annotatedFiles = new WeakSet<>();
+    private Set<PropertyChangeListener> dataObjectListeners;
+    private final RequestProcessor annotationProcessor = new 
RequestProcessor("Annotation Refresh", 1);
 
     @Override
     public String[] getProperties() {
         return new String[] { DebuggerManager.PROP_BREAKPOINTS, 
DebuggerManager.PROP_DEBUGGER_ENGINES }; 
     }
 
+    private static boolean isAnnotateable(Breakpoint breakpoint) {
+        return breakpoint instanceof JSBreakpoint;
+    }
+    
+    private static boolean isAnnotateable(FileObject fo) {
+        return JSUtils.JS_MIME_TYPE.equals(fo.getMIMEType());
+    }
+
     @Override
     public void breakpointAdded(Breakpoint breakpoint) {
-        if (! (breakpoint instanceof JSBreakpoint)) {
+        if (!isAnnotateable(breakpoint)) {
             return;
         }
-        addAnnotation((JSBreakpoint) breakpoint);
+        JSBreakpoint b = (JSBreakpoint) breakpoint;
+        FileObject fo = b.getFileObject();
+        synchronized (breakpointAnnotations) {
+            boolean isFileAnnotated = annotatedFiles.contains(fo);
+            logger.log(Level.FINE, "breakpointAdded({0}), fo = {1}, foID = 
{2}, annotated = {3}",
+                       new Object[] { breakpoint, fo, 
System.identityHashCode(fo), isFileAnnotated });
+            //if (isFileAnnotated) {
+                //addAnnotation(b);
+                annotationProcessor.post(new AnnotationRefresh(b, false, 
true));
+            //}
+        }
+        
     }
 
     @Override
     public void breakpointRemoved(Breakpoint breakpoint) {
-        if (! (breakpoint instanceof JSBreakpoint)) {
+        if (!isAnnotateable(breakpoint)) {
             return;
         }
-        removeAnnotation((JSBreakpoint) breakpoint);
+        JSBreakpoint b = (JSBreakpoint) breakpoint;
+        logger.log(Level.FINE, "breakpointRemoved({0})", breakpoint);
+        annotationProcessor.post(new AnnotationRefresh(b, true, false));
+        //removeAnnotation((JSBreakpoint) breakpoint);
     }
     
     @Override
     public void annotate(Line.Set set, Lookup context) {
-        // Annotate all JS breakpoints
-        DebuggerManager.getDebuggerManager().getBreakpoints();
+        final FileObject fo = context.lookup(FileObject.class);
+        if (fo == null || !isAnnotateable(fo)) {
+            return ;
+        }
+        DataObject dobj = context.lookup(DataObject.class);
+        logger.log(Level.FINE, "annotate({0}, {1}), fo = {2}, foID = {3}, 
dobj = {4}",
+                   new Object[] { set, context, fo, 
System.identityHashCode(fo), dobj });
+        if (dobj != null) {
+            PropertyChangeListener pchl = new PropertyChangeListener() {
+                /** annotate renamed files. */
+                @Override
+                public void propertyChange(PropertyChangeEvent evt) {
+                    if 
(DataObject.PROP_PRIMARY_FILE.equals(evt.getPropertyName())) {
+                        DataObject dobj = (DataObject) evt.getSource();
+                        final FileObject newFO = dobj.getPrimaryFile();
+                        annotationProcessor.post(new Runnable() {
+                            @Override
+                            public void run() {
+                                annotate(newFO);
+                            }
+                        });
+                    }
+                }
+            };
+            
dobj.addPropertyChangeListener(WeakListeners.propertyChange(pchl, dobj));
+            synchronized (this) {
+                if (dataObjectListeners == null) {
+                    dataObjectListeners = new 
HashSet<PropertyChangeListener>();
+                }
+                // Prevent from GC.
+                dataObjectListeners.add(pchl);
+            }
+        }
+        annotate(fo);
+    }
+    
+    public void annotate (final FileObject fo) {
+        synchronized (breakpointAnnotations) {
+//            if (annotatedFiles.contains(fo)) {
+//                // Already annotated
+//                return ;
+//            }
+            //Set<JSBreakpoint> annotatedBreakpoints = 
breakpointAnnotations.keySet();
+            for (Breakpoint breakpoint : 
DebuggerManager.getDebuggerManager().getBreakpoints()) {
+                if (isAnnotateable(breakpoint)) {
+                    JSBreakpoint b = (JSBreakpoint) breakpoint;
+                    if (fo.equals(b.getFileObject())) {
+                        logger.log(Level.FINE, "annotate({0} (ID={1})): b = 
{2}",
+                                   new Object[] { fo, 
System.identityHashCode(fo), b });
+                        annotationProcessor.post(new AnnotationRefresh(b, 
false, true));
+                    }
+                    /*
+                    int[] lines = getAnnotationLines(b, fo);
+                    if (lines != null && lines.length > 0) {
+                        if (!annotatedBreakpoints.contains(b)) {
+                            b.addPropertyChangeListener (this);
+                            breakpointToAnnotations.put(b, new 
WeakSet<Annotation>());
+                            if (b instanceof LineBreakpoint) {
+                                LineBreakpoint lb = (LineBreakpoint) b;
+                                
LineTranslations.getTranslations().registerForLineUpdates(lb);
+                            }
+                        }
+                        addAnnotationTo(b, fo, lines);
+                    }
+                    */
+                }
+            }
+            annotatedFiles.add(fo);
+            logger.log(Level.FINE, "Annotated files = {0}", annotatedFiles);
+        }
+//        if (attachManagerListener) {
+//            attachManagerListener = false;
+//            
setCurrentDebugger(DebuggerManager.getDebuggerManager().getCurrentEngine());
+//            DebuggerManager.getDebuggerManager().addDebuggerListener(
+//                    WeakListeners.create(DebuggerManagerListener.class,
+//                                         this,
+//                                         
DebuggerManager.getDebuggerManager()));
+//        }
     }
 
     private void addAnnotation(JSBreakpoint breakpoint) {
         Object annotation = Context.annotate(((JSBreakpoint) breakpoint));
+        logger.log(Level.FINE, "Added annotation of {0} : {1}",
+                   new Object[] { breakpoint, annotation });
         if (annotation != null) {
             synchronized (breakpointAnnotations) {
                 breakpointAnnotations.put(breakpoint, annotation);
@@ -107,8 +225,52 @@
             annotation = breakpointAnnotations.remove(breakpoint);
         }
         if (annotation != null) {
+            logger.log(Level.FINE, "Removed annotation of {0} : {1}",
+                       new Object[] { breakpoint, annotation });
             Context.removeAnnotation(annotation);
         }
     }
     
+    private final class AnnotationRefresh implements Runnable {
+        
+        private final JSBreakpoint b;
+        private final boolean remove, add;
+        
+        public AnnotationRefresh(JSBreakpoint b, boolean remove, boolean 
add) {
+            this.b = b;
+            this.remove = remove;
+            this.add = add;
+        }
+
+        @Override
+        public void run() {
+            synchronized (breakpointAnnotations) {
+                if (b != null) {
+                    refreshAnnotation(b);
+                } else {
+                    List<JSBreakpoint> bpts = new 
ArrayList<>(breakpointAnnotations.keySet());
+                    for (JSBreakpoint bp : bpts) {
+                        refreshAnnotation(bp);
+                    }
+                }
+            }
+        }
+        
+        private void refreshAnnotation(JSBreakpoint b) {
+            removeAnnotation(b);
+            /*if (remove) {
+                if (!add) {
+                    breakpointAnnotations.remove(b);
+                }
+            }*/
+            if (add) {
+                addAnnotation(b);
+                /*breakpointAnnotations.put(b, new WeakSet<Annotation>());
+                for (FileObject fo : annotatedFiles) {
+                    addAnnotationTo(b, fo);
+                }*/
+            }
+        }
+        
 }
+    }
diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSLineBreakpoint.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSLineBreakpoint.java
--- 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSLineBreakpoint.java
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/JSLineBreakpoint.java
@@ -47,7 +47,13 @@
 import org.netbeans.api.debugger.jpda.JPDABreakpoint;
 import org.netbeans.api.debugger.jpda.LineBreakpoint;
 import org.netbeans.modules.debugger.jpda.js.JSUtils;
+import org.netbeans.modules.debugger.jpda.js.source.SourceURLMapper;
+import org.openide.cookies.LineCookie;
 import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.URLMapper;
+import org.openide.loaders.DataObject;
+import org.openide.loaders.DataObjectNotFoundException;
 import org.openide.text.Line;
 
 /**
@@ -72,21 +78,72 @@
         return line;
     }
     
+    private void setLine(Line line) {
+        this.line = line;
+    }
+    
     public int getLineNumber() {
         return line.getLineNumber() + 1;
     }
     
     public URL getURL() {
+        if (line instanceof FutureLine) {
+            return ((FutureLine) line).getURL();
+        }
         return line.getLookup().lookup(FileObject.class).toURL();
     }
 
+    @Override
+    protected FileObject getFileObject() {
+        if (line instanceof FutureLine) {
+            URL url = getURL();
+            FileObject fo = URLMapper.findFileObject(url);
+            if (fo != null) {
+                try {
+                    DataObject dobj = DataObject.find(fo);
+                    LineCookie lineCookie = 
dobj.getLookup().lookup(LineCookie.class);
+                    if (lineCookie == null) {
+                        return null;
+                    }
+                    Line l = 
lineCookie.getLineSet().getCurrent(getLineNumber() - 1);
+                    setLine(l);
+                } catch (DataObjectNotFoundException ex) {
+                }
+            }
+            return fo;
+        }
+        return line.getLookup().lookup(FileObject.class);
+    }
+    
     private LineBreakpoint createJavaLB(Line line) {
         FileObject fo = line.getLookup().lookup(FileObject.class);
-        String url = fo.toURL().toExternalForm();
+        String url;
+        String name;
+        if (fo != null) {
+            url = fo.toURL().toExternalForm();
+            name = fo.getName();
+        } else {
+            url = ((FutureLine) line).getURL().toExternalForm();
+            int i1 = url.lastIndexOf('/');
+            if (i1 < 0) {
+                i1 = 0;
+            } else {
+                i1++;
+            }
+            int i2 = url.lastIndexOf('.');
+            if (i2 < i1) {
+                i2 = url.length();
+            }
+            name = url.substring(i1, i2);
+            name = SourceURLMapper.percentDecode(name);
+        }
+        if ("<eval>".equals(name)) {        // NOI18N
+            name = "\\^eval\\_";            // NOI18N
+        }
         int lineNo = getLineNumber();
-        LineBreakpoint lb = LineBreakpoint.create(url, lineNo);
+        LineBreakpoint lb = LineBreakpoint.create("", lineNo);
         lb.setHidden(true);
-        lb.setPreferredClassName(JSUtils.NASHORN_SCRIPT + fo.getName());
+        lb.setPreferredClassName(JSUtils.NASHORN_SCRIPT + name);
         lb.setSuspend(JPDABreakpoint.SUSPEND_EVENT_THREAD);
         return lb;
     }
diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/JSBreakpointReader.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/JSBreakpointReader.java
--- 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/JSBreakpointReader.java
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/JSBreakpointReader.java
@@ -53,9 +53,11 @@
 import org.netbeans.api.debugger.Properties;
 import org.netbeans.api.project.Project;
 import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.debugger.jpda.js.breakpoints.FutureLine;
 import org.netbeans.modules.debugger.jpda.js.breakpoints.JSBreakpoint;
 import org.netbeans.modules.debugger.jpda.js.breakpoints.JSLineBreakpoint;
 import 
org.netbeans.modules.debugger.jpda.js.breakpoints.io.BreakpointsFromGroup.TestGroupProperties;
+import org.netbeans.modules.debugger.jpda.js.source.Source;
 import org.netbeans.spi.debugger.DebuggerServiceRegistration;
 import org.openide.cookies.LineCookie;
 import org.openide.filesystems.FileObject;
@@ -94,10 +96,16 @@
             String urlStr = properties.getString (JSLineBreakpoint.PROP_URL, 
null);
             int lineNumber = properties.getInt 
(JSLineBreakpoint.PROP_LINE_NUMBER, 1);
             try {
-                FileObject fo = URLMapper.findFileObject(new URL(urlStr));
+                URL url = new URL(urlStr);
+                FileObject fo = URLMapper.findFileObject(url);
                 if (fo == null) {
+                    if (Source.URL_PROTOCOL.equals(url.getProtocol())) {
+                        Line line = new FutureLine(url, lineNumber - 1);
+                        return new JSLineBreakpoint(line);
+                    } else {
                     return null;
                 }
+                }
                 try {
                     DataObject dobj = DataObject.find(fo);
                     LineCookie lineCookie = 
dobj.getLookup().lookup(LineCookie.class);
diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/PersistenceManager.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/PersistenceManager.java
--- 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/PersistenceManager.java
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/breakpoints/io/PersistenceManager.java
@@ -90,7 +90,18 @@
             JS_PROPERTY, 
             new Breakpoint [0]
         );
-        for (Breakpoint b : breakpoints) {
+        for (int i = 0; i < breakpoints.length; i++) {
+            Breakpoint b = breakpoints[i];
+            if (b == null) {
+                Breakpoint[] breakpoints2 = new 
Breakpoint[breakpoints.length - 1];
+                System.arraycopy(breakpoints, 0, breakpoints2, 0, i);
+                if (i < breakpoints.length - 1) {
+                    System.arraycopy(breakpoints, i + 1, breakpoints2, i, 
breakpoints.length - i - 1);
+                }
+                breakpoints = breakpoints2;
+                i--;
+                continue;
+            }
             b.addPropertyChangeListener(this);
         }
         return breakpoints;
diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/Source.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/Source.java
--- 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/Source.java
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/Source.java
@@ -62,6 +62,8 @@
  */
 public final class Source {
     
+    public static final String URL_PROTOCOL = "js-scripts"; // NOI18N
+    
     private static final String SOURCE_CLASS = 
"jdk.nashorn.internal.runtime.Source";   // NOI18N
     private static final String SOURCE_FIELD = "source";    // NOI18N
     
diff --git 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/SourceURLMapper.java
 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/SourceURLMapper.java
--- 
a/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/SourceURLMapper.java
+++ 
b/debugger.jpda.js/src/org/netbeans/modules/debugger/jpda/js/source/SourceURLMapper.java
@@ -65,15 +65,13 @@
 import org.openide.util.lookup.ServiceProvider;
 
 /**
+ * Support for URLs of the form js_sources://fs&lt;ID&gt;/folder/file
  *
  * @author Martin
  */
 @ServiceProvider(service=URLMapper.class)
 public final class SourceURLMapper extends URLMapper {
     
-    // Support for URLs of the form memory://fs23/folder/file
-    private static final String PROTOCOL = "jssource"; // NOI18N
-    
     private static final Map<Long,Reference<FileSystem>> filesystems = new 
HashMap<>(); // i.e. a sparse array by id
     
     public @Override URL getURL(FileObject fo, int type) {
@@ -106,7 +104,7 @@
         }
         try {
             //return new URL(null, PROTOCOL + "://fs" + fs.getID() + "/" + 
path, new SourceURLHandler());
-            return new URL(PROTOCOL, "fs" + fs.getID(), -1, "/" + 
percentEncode(path), new SourceURLHandler());
+            return new URL(Source.URL_PROTOCOL, "fs" + fs.getID(), -1, "/" + 
percentEncode(path), new SourceURLHandler());
         } catch (MalformedURLException x) {
             throw new AssertionError(x);
         }
@@ -114,7 +112,7 @@
     
     private static final Pattern HOST = Pattern.compile("fs(\\d+)"); // 
NOI18N
     static FileObject find(URL url) {
-        if (!PROTOCOL.equals(url.getProtocol())) {
+        if (!Source.URL_PROTOCOL.equals(url.getProtocol())) {
             return null;
         }
         Matcher m = HOST.matcher(url.getHost());
@@ -142,7 +140,7 @@
         return f != null ? new FileObject[] {f} : null;
     }
     
-    private static String percentEncode(String text) {
+    public static String percentEncode(String text) {
         StringBuilder encoded = null;
         int li = 0;
         for (int i = 0; i < text.length(); i++) {
@@ -150,7 +148,8 @@
             int v = c;
             if (47 <= v && v <= 57 || // slash and 0-9
                 'A' <= v && v <= 'Z' ||
-                'a' <= v && v <= 'z') {
+                'a' <= v && v <= 'z' ||
+                v == '.') {
                 
                 continue;
             }
@@ -192,7 +191,7 @@
         return sb.toString();
     }
     
-    private static String percentDecode(String text) {
+    public static String percentDecode(String text) {
         int i = text.indexOf('%');
         if (i < 0) {
             return text;
@@ -233,7 +232,7 @@
     }
     
 
-    @URLStreamHandlerRegistration(protocol=PROTOCOL)
+    @URLStreamHandlerRegistration(protocol=Source.URL_PROTOCOL)
     public static final class SourceURLHandler extends URLStreamHandler {
         
         protected @Override URLConnection openConnection(URL u) throws 
IOException {
diff --git 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/DebuggingNodeModel.java
 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/DebuggingNodeModel.java
--- 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/DebuggingNodeModel.java
+++ 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/DebuggingNodeModel.java
@@ -348,14 +348,25 @@
         if (breakpoint instanceof LineBreakpoint) {
             LineBreakpoint lb = (LineBreakpoint) breakpoint;
             String fileName = null;
+            String urlStr = lb.getURL();
+            if (urlStr.isEmpty()) {
+                fileName = lb.getPreferredClassName();
+                if (fileName != null) {
+                    int i = fileName.lastIndexOf('.');
+                    if (i > 0) {
+                        fileName = fileName.substring(i+1);
+                    }
+                }
+            } else {
             try {
-                FileObject fo = URLMapper.findFileObject(new 
URL(lb.getURL()));
+                    FileObject fo = URLMapper.findFileObject(new 
URL(urlStr));
                 if (fo != null) {
                     fileName = fo.getNameExt();
                 }
             } catch (MalformedURLException ex) {
                 ErrorManager.getDefault().notify(ex);
             }
+            }
             if (fileName == null) fileName = lb.getURL();
             return NbBundle.getMessage(DebuggingNodeModel.class, 
"CTL_Thread_At_LineBreakpoint",
                                        threadName, fileName, 
lb.getLineNumber());
diff --git 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
--- 
a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
+++ 
b/debugger.jpda/src/org/netbeans/modules/debugger/jpda/breakpoints/LineBreakpointImpl.java
@@ -210,7 +210,12 @@
         LineBreakpoint breakpoint = getBreakpoint();
         updateLineNumber();
         String[] preferredSourceRoot = new String[] { null };
-        String sourcePath = 
getDebugger().getEngineContext().getRelativePath(breakpoint.getURL(), '/', 
true);
+        boolean isEmptyURL = breakpoint.getURL().isEmpty();
+        String sourcePath;
+        if (isEmptyURL) {
+            sourcePath = null;
+        } else {
+            sourcePath = 
getDebugger().getEngineContext().getRelativePath(breakpoint.getURL(), '/', 
true);
         if (sourcePath == null) {
             String reason = NbBundle.getMessage(LineBreakpointImpl.class,
                                                 "MSG_NoSourceRoot",
@@ -218,6 +223,7 @@
             setInvalid(reason);
             return ;
         }
+        }
         String className = breakpoint.getPreferredClassName();
         if (className == null || className.isEmpty()) {
             className = reader.findCachedClassName(breakpoint);
@@ -237,8 +243,8 @@
             return ;
         }
 
-        boolean isInSources = false;
-        {
+        boolean isInSources = isEmptyURL;
+        if (!isEmptyURL) {
             String srcRoot = getSourceRoot();
             if (srcRoot != null) {
                 String[] sourceRoots = 
getDebugger().getEngineContext().getSourceRoots();
@@ -256,7 +262,7 @@
                        new Object[]{breakpoint, breakpoint.getURL(), 
className});
             return ;
         }
-        if (isInSources && !isEnabled(sourcePath, preferredSourceRoot)) {
+        if (isInSources && sourcePath != null && !isEnabled(sourcePath, 
preferredSourceRoot)) {
             String reason = NbBundle.getMessage(LineBreakpointImpl.class,
                                                 
"MSG_DifferentPrefferedSourceRoot",
                                                 preferredSourceRoot[0]);

[hg] main-silver: #237961: Stepping and breakpoints in evaluated...

mentlicher 11/04/2013

Project Features

About this Project

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