[hg] main-silver: #81925: Provide a navigation to class types. T...

  • From:
  • To:
  • Subject: [hg] main-silver: #81925: Provide a navigation to class types. T...
  • Date: Fri, 26 Apr 2013 21:48:03 -0700

changeset db80890d0b89 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/db80890d0b89
description:
        #81925: Provide a navigation to class types. The original Go to 
Source renamed to Go to Declaration to prevent from confusion.

diffstat:

 
debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/Bundle.properties
             |    5 +-
 
debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/VariablesActionsProvider.java
 |  113 +++++++++-
 2 files changed, 115 insertions(+), 3 deletions(-)

diffs (168 lines):

diff --git 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/Bundle.properties
 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/Bundle.properties
--- 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/Bundle.properties
+++ 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/Bundle.properties
@@ -284,7 +284,10 @@
 MSG_NA=N/A
 
 #VariablesActionProvider
-CTL_GoToSource=Go to Source
+# Go to field declaration
+CTL_GoToSource=Go to Declaration
+CTL_GoToTypeSource=Go to Type Source
+MSG_NoSourceFile=Cannot find source file {0} for class {1}.
 
 # Hidden Call Stack Frames Filter
 LBL_HIDDEN_FRAMES=Hidden Source Calls
diff --git 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/VariablesActionsProvider.java
 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/VariablesActionsProvider.java
--- 
a/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/VariablesActionsProvider.java
+++ 
b/debugger.jpda.ui/src/org/netbeans/modules/debugger/jpda/ui/models/VariablesActionsProvider.java
@@ -44,9 +44,18 @@
 
 package org.netbeans.modules.debugger.jpda.ui.models;
 
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.concurrent.Future;
 import javax.swing.Action;
+import javax.swing.SwingUtilities;
+import org.netbeans.api.debugger.DebuggerEngine;
+import org.netbeans.api.debugger.DebuggerManager;
 
 import org.netbeans.api.debugger.jpda.*;
+import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
+import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
 import org.netbeans.spi.debugger.ContextProvider;
 import org.netbeans.spi.viewmodel.Models;
 import org.netbeans.spi.viewmodel.NodeActionsProvider;
@@ -57,6 +66,12 @@
 import org.netbeans.modules.debugger.jpda.ui.SourcePath;
 import org.netbeans.spi.debugger.DebuggerServiceRegistration;
 import org.netbeans.spi.debugger.DebuggerServiceRegistrations;
+import org.openide.DialogDisplayer;
+import org.openide.NotifyDescriptor;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.URLMapper;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
 
 import org.openide.util.NbBundle;
 import org.openide.util.RequestProcessor;
@@ -99,6 +114,23 @@
         Models.MULTISELECTION_TYPE_EXACTLY_ONE
     );
         
+    private final Action GO_TO_TYPE_SOURCE_ACTION = Models.createAction (
+        NbBundle.getMessage(VariablesActionsProvider.class, 
"CTL_GoToTypeSource"), 
+        new Models.ActionPerformer () {
+            public boolean isEnabled (Object node) {
+                return true;
+            }
+            public void perform (final Object[] nodes) {
+                lookupProvider.lookupFirst(null, 
RequestProcessor.class).post(new Runnable() {
+                    public void run() {
+                        showSource (((ObjectVariable) nodes [0]).getType());
+                    }
+                });
+            }
+        },
+        Models.MULTISELECTION_TYPE_EXACTLY_ONE
+    );
+        
         
     private ContextProvider lookupProvider;
 
@@ -112,9 +144,21 @@
             return new Action[] {
                 WatchesActionsProvider.NEW_WATCH_ACTION
             };
-        if (node instanceof Field)
+        if (node instanceof Field) {
+            if (node instanceof ObjectVariable) {
             return new Action [] {
-                GO_TO_SOURCE_ACTION
+                    GO_TO_SOURCE_ACTION,
+                    GO_TO_TYPE_SOURCE_ACTION,
+                };
+            } else {
+                return new Action [] {
+                    GO_TO_SOURCE_ACTION,
+                };
+            }
+        }
+        if (node instanceof ObjectVariable)
+            return new Action [] {
+                GO_TO_TYPE_SOURCE_ACTION,
             };
         if (node instanceof Variable)
             return new Action [] {
@@ -169,4 +213,69 @@
         SourcePath ectx = lookupProvider.lookupFirst(null, SourcePath.class);
         return ectx.sourceAvailable (v);
     }
+    
+    private void showSource(final String type) {
+        DebuggerEngine engine = 
DebuggerManager.getDebuggerManager().getCurrentEngine();
+        if (engine != null) {
+            JPDADebugger debugger = engine.lookupFirst(null, 
JPDADebugger.class);
+            final String typePath = EditorContextBridge.getRelativePath 
(type);
+            final String url = ((JPDADebuggerImpl) 
debugger).getEngineContext().getURL(typePath, true);
+            final int lineNumber = findClassLine(url, type);
+            SwingUtilities.invokeLater (new Runnable () {
+                @Override
+                public void run () {
+                    boolean success = 
EditorContextBridge.getContext().showSource(url, lineNumber, null);
+                    if (!success) {
+                        NotifyDescriptor d = new 
NotifyDescriptor.Message(NbBundle.getMessage(VariablesActionsProvider.class, 
"MSG_NoSourceFile", typePath, type), NotifyDescriptor.WARNING_MESSAGE);
+                        DialogDisplayer.getDefault().notifyLater(d);
 }
+                }
+            });
+        }
+    }
+    
+    private static int findClassLine(String url, String clazz) {
+        FileObject fo;
+        try {
+            fo = URLMapper.findFileObject(new URL(url));
+        } catch (MalformedURLException ex) {
+            return 1;
+        }
+        // TODO: Add getClassLineNumber() into EditorContext
+        String editorContextImplName = 
"org.netbeans.modules.debugger.jpda.projects.EditorContextImpl"; // NOI18N
+        Class editorContextImpl;
+        try {
+            editorContextImpl = 
Thread.currentThread().getContextClassLoader().loadClass(editorContextImplName);
+        } catch (ClassNotFoundException cnfex) {
+            ClassLoader cl = Lookup.getDefault().lookup(ClassLoader.class);
+            if (cl == null) {
+                return 1;
+            }
+            try {
+                editorContextImpl = cl.loadClass(editorContextImplName);
+            } catch (ClassNotFoundException ex) {
+                Exceptions.printStackTrace(ex);
+                return 1;
+            }
+        }
+        try {
+            Method getClassLineNumber = editorContextImpl.getDeclaredMethod(
+                    "getClassLineNumber", FileObject.class, String.class, 
String[].class);  // NOI18N
+            getClassLineNumber.setAccessible(true);
+            Future<Integer> lineNumberFuture = (Future<Integer>) 
getClassLineNumber.invoke(null, fo, clazz, new String[] {});
+            if (lineNumberFuture == null) {
+                return 1;
+            }
+            Integer line = lineNumberFuture.get();
+            if (line == null) {
+                return 1;
+            } else {
+                return line.intValue();
+            }
+        } catch (Exception ex) {
+            Exceptions.printStackTrace(ex);
+            return 1;
+        }
+    }
+
+}

[hg] main-silver: #81925: Provide a navigation to class types. T...

mentlicher 04/27/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