Commits

Anonymous committed 4585579

- Fixed some bugs in inspector. Inspecting package is still not pretty and inspecting symbols in package doesn't work. I need to include general inspecting parts that are
not recognized, since sometimes swank produces very unstructured results
when inspector is called.

Comments (0)

Files changed (3)

org.lispdev.swank/src/org/lispdev/swank/LispImplementation.java

 package org.lispdev.swank;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.runtime.IPath;
    */
   private static class InspectNthPart implements IInspectCmd
   {
-    private final String n;
+    private final int n;
     private final LispDebugTarget target;
 
     /**
      * @param parent
      * @param n
      */
-    public InspectNthPart(LispDebugTarget target, String n)
+    public InspectNthPart(LispDebugTarget target, int n)
     {
       this.n = n;
       this.target = target;
     @Override
     public InspectInfo inspect(LispValue parent)
     {
-      try
+      if( n < 0 )
       {
-        int nn = Integer.parseInt(n);
+        Log.logError("Cannot inspect part " + n);
       }
-      catch(NumberFormatException e)
-      {
-        Log.logException("Cannot inspect part " + n, e);
-        return null;
-      }
-      LispNode r = target.getSwank().inspectNthPart(n, 500);
+      LispNode r = target.getSwank().inspectNthPart(String.valueOf(n), 500);
       return getInspectInfo(target, parent, r);
     }
   }
   " (:value "VERSION" 28) "                " " = " (:value "\"0.1\"" 29) " " (:action "[set value]" 27) " " (:action "[make unbound]" 28) "
   ") 150 0 150))) 7)
 
+  <--(:return (:ok (:title "#<PACKAGE {2396E571}>" :id 5 :content (("" "Name: " (:value "\"NEW-LISP2\"" 0) "
+  " "Nick names: " "
+  " "Use list: " (:value "COMMON-LISP" 1) "
+  " "Used by list: " "
+  " (:value "4 present symbols." 2) "
+  " (:value "1 external symbol." 3) "
+  " (:value "3 internal symbols." 4) "
+  " "0 shadowed symbols.") 18 0 18))) 10)
+
+
+  <--(:return (:ok (:title "#<PACKAGE {223000F1}>" :id 10 :content (("" "Name: " (:value "\"COMMON-LISP-USER\"" 0) "
+  " "Nick names: " (:value "\"CL-USER\"" 1) "
+  " "Documentation:" "
+  " "public: the default package for user code and data" "
+  " "Use list: " (:value "COMMON-LISP" 2) ", " (:value "SB-ALIEN" 3) ", " (:value "SB-DEBUG" 4) ", " (:value "SB-EXT" 5) ", " (:value "SB-GRAY" 6) ", " (:value "SB-PROFILE" 7) "
+  " "Used by list: " "
+  " (:value "2 present symbols." 8) "
+  " "0 external symbols." "
+  " (:value "2 internal symbols." 9) "
+  " "0 shadowed symbols.") 33 0 33))) 14)
    */
   /**
    * @param target
     InspectInfo res = new InspectInfo(n.getf(":title").value,
         n.getf(":title").value);
     LispNode c = n.getf(":content").get(0);
+
     if( "Class: ".equalsIgnoreCase(c.get(0).value) )
     {
       res.content.add(new LispVariable(target,parent,"Class",
-          c.get(1).getf(":value").value,
-          new InspectNthPart(target, c.get(1).get(2).value)));
+          c.get(1).getf(":value").value, getInspect(target, c.get(1).get(2))));
       for( int i = 2; i < c.getParamsCount(); ++i )
       {
         if( c.get(i).value.equals(" = ") )
               parent,c.get(i-2).getf(":value").value,
               (c.get(i+1).isString ? c.get(i+1).value
                                    : c.get(i+1).getf(":value").value),
-              new InspectNthPart(target, c.get(i+1).get(2).value)));
+              getInspect(target, c.get(i+1).get(2))));
+        }
+      }
+      return res;
+    }
+
+    if( "#<PACKAGE".equalsIgnoreCase(res.title.substring(0,"#<PACKAGE".length())) )
+    {
+      PackageInfoState state = PackageInfoState.START;
+      String varName = "";
+      for( LispNode node : c.getParams() )
+      {
+        String str = node.value.trim();
+        PackageInfoState newState = PackageInfoState.getState(str);
+        if( newState != null )
+        {
+          varName = String.valueOf(newState);
+          res.content.add(
+              new LispVariable(target, parent, str, "", null));
+          state = newState;
+        }
+        else if( state != PackageInfoState.START )
+        {
+          if( state != PackageInfoState.DOC )
+          {
+            String val = node.getf(":value").value;
+            if( val != null && !val.equals("") )
+            {
+              res.content.add(new LispVariable(target, parent, varName,
+                  val, getInspect(target, node.get(2))));
+            }
+          }
+          else
+          {
+            res.content.add(
+                new LispVariable(target, parent, "Documentation", str, null));
+          }
         }
       }
       return res;
         res.content.add(new LispVariable(target,
             parent,c.get(j-1).value,
             c.get(j+1).getf(":value").value,
-            new InspectNthPart(target, c.get(j+1).get(2).value)));
+            getInspect(target, c.get(j+1).get(2))));
       }
     }
     return res;
   }
 
+  private enum PackageInfoState
+  {
+    START, NAME, NICK_NAMES, DOC, USE_LIST, USED_BY_LIST;
+
+    private static final Map<String,PackageInfoState> tagmap =
+      new HashMap<String, PackageInfoState>(){
+        private static final long serialVersionUID = 1L;
+        {
+          put("Name:",NAME);
+          put("Nick names:",NICK_NAMES);
+          put("Documentation:",DOC);
+          put("Use list:",USE_LIST);
+          put("Used by list:",USED_BY_LIST);
+        }};
+
+     public static PackageInfoState getState(String tag)
+     {
+       return tagmap.get(tag);
+     }
+  }
+
+  private static int startingState(LispNode c, InspectInfo info)
+  {
+    return 0;
+  }
+
+  private static InspectNthPart getInspect(LispDebugTarget target, LispNode c)
+  {
+    try
+    {
+      int n = Integer.parseInt(c.value);
+      return new InspectNthPart(target, n);
+    }
+    catch( NumberFormatException e )
+    {
+      return null;
+    }
+  }
+
 /*
 -->(:emacs-rex (swank:frame-locals-for-emacs 1) nil 0 4)
 <--(:return (:ok
   " (:value "VERSION" 28) "                " " = " (:value "\"0.1\"" 29) " " (:action "[set value]" 27) " " (:action "[make unbound]" 28) "
   ") 150 0 150))) 7)
 
+
+  <--(:return (:ok (:title "#<PACKAGE {2396E571}>" :id 5 :content (("" "Name: " (:value "\"NEW-LISP2\"" 0) "
+  " "Nick names: " "
+  " "Use list: " (:value "COMMON-LISP" 1) "
+  " "Used by list: " "
+  " (:value "4 present symbols." 2) "
+  " (:value "1 external symbol." 3) "
+  " (:value "3 internal symbols." 4) "
+  " "0 shadowed symbols.") 18 0 18))) 10)
+
+
+  <--(:return (:ok (:title "#<PACKAGE {223000F1}>" :id 10 :content (("" "Name: " (:value "\"COMMON-LISP-USER\"" 0) "
+  " "Nick names: " (:value "\"CL-USER\"" 1) "
+  " "Documentation:" "
+  " "public: the default package for user code and data" "
+  " "Use list: " (:value "COMMON-LISP" 2) ", " (:value "SB-ALIEN" 3) ", " (:value "SB-DEBUG" 4) ", " (:value "SB-EXT" 5) ", " (:value "SB-GRAY" 6) ", " (:value "SB-PROFILE" 7) "
+  " "Used by list: " "
+  " (:value "2 present symbols." 8) "
+  " "0 external symbols." "
+  " (:value "2 internal symbols." 9) "
+  " "0 shadowed symbols.") 33 0 33))) 14)
    */
   public LispVariable inspectReplResult(final LispDebugTarget target,
       final String name, final IPartitionData data)

org.lispdev.swank/src/org/lispdev/swank/LispNode.java

 package org.lispdev.swank;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import org.lispdev.log.Log;
 
 public class LispNode
 {
   public String value = "";
-  private final ArrayList<LispNode> params = new ArrayList<LispNode>();
+  private final List<LispNode> params = new ArrayList<LispNode>();
 
   public boolean isString = false;
 
     return new LispNode();
   }
 
-  public ArrayList<LispNode> getParams()
+  public List<LispNode> getParams()
   {
     return params;
   }

org.lispdev.swank/src/org/lispdev/swank/debug/LispValue.java

       {
         e.printStackTrace();
       }
-      info = inspect.inspect(this);
+      info = (inspect == null ? null : inspect.inspect(this));
     }
   }
 
   @Override
   public IVariable[] getVariables() throws DebugException
   {
-    if( info == null )
+    if( inspect != null && info == null )
     {
       runInspect();
     }
   @Override
   public boolean hasVariables() throws DebugException
   {
-    return true;
+    return inspect != null;
   }
 
   @Override
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.