[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-CVS ] plugins/JBrowse/src/jbrowse/tiger AnotherTestClass.java,1.1,1.2 JBrowseActionPane.java
From:       Dale Anson <daleanson () users ! sourceforge ! net>
Date:       2005-12-31 18:06:06
Message-ID: E1Esl7M-0001nG-Eb () mail ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10909/src/jbrowse/tiger

Modified Files:
	AnotherTestClass.java JBrowseActionPane.java 
	JBrowseStatusPane.java TestClass.java TigerBrowserParser.java 
	TigerCellRenderer.java 
Log Message:
updates



Index: AnotherTestClass.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/AnotherTestClass.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- AnotherTestClass.java	20 Dec 2005 23:44:01 -0000	1.1
+++ AnotherTestClass.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -1,5 +1,126 @@
 package jbrowse.tiger;
 
+// static import
+import static java.lang.Math.*;
+
+import java.util.*;
+
+// NOT public
 class AnotherTestClass {
+   // some fields
+    public int x = 2;
+    
+    public int a = 9, b = 4;
+    String s = "foo";
+    public final static int width = 800;
+    
+    public static String abc;
+    
+    // static initializer
+    static {
+        abc = "def";   
+    }
+
+    // enum
+    public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }
 
+    // generics
+    public HashMap<String, Suit> lu = new HashMap<String, Suit>();
+    static {
+        // foreach
+        for ( Suit suit : Suit.values() ) {
+            System.out.println(suit);
+        }
+        
+        // using static import
+        double r = cos(PI * 2);
+    }
+
+    // throws in constructor
+    public AnotherTestClass() throws NullPointerException, IllegalArgumentException \
{ +        throw new IllegalArgumentException();   
+    }
+    
+    // generics and abstract, uncomment to test, these won't compile
+    /*
+    public TestClass(Collection<? extends E> c){
+        
+    }
+    
+    public abstract void justDoIt(String doItNow);
+    */
+
+    // auto-boxing and generics    
+    public class Frequency {
+       public void mainMethod(String[] args) {
+          Map<String, Integer> m = new TreeMap<String, Integer>();
+          for (String word : args) {
+              Integer freq = m.get(word);
+              m.put(word, (freq == null ? 1 : freq + 1));
+          }
+          System.out.println(m);
+       }
+    }    
+
+    // more generics    
+    static void expurgate(Collection<String> c) {
+        for (Iterator<String> i = c.iterator(); i.hasNext(); )
+          if (i.next().length() == 4)
+            i.remove();
+    }
+    
+    // throws in method
+    public int firstMethod() throws NullPointerException, IllegalArgumentException {
+        if (true)
+            throw new NullPointerException();
+        return 0;
+    }
+    
+    public int compareTo(Object o) {
+        return -1;   
+    }
+    
+    // vararg
+    public static String format(String pattern,
+                                Object... arguments){
+        return null;
+    }
+    
+    // final in parameter
+    public final void munge(final int six) {
+        
+    }
+    
+    // inner class
+    public class MyInnerClass {
+        public MyInnerClass() {
+            
+        }
+        
+        public String toString() {
+            return "MyInnerClass";   
+        }
+    }
+    
+    // fully qualified return type
+    java.lang.String getSomeString() {
+        return "";   
+    }
+    
+//// caused parse errors with previous version of JBrowse, this is bug 637859,
+//// these examples are copied from that bug.
+    // trailing dots
+java.
+lang.
+String x() {
+return null;
+}
+
+// leading dots
+java
+.lang
+.String y() {
+return null;
+}
+////
 }

Index: TestClass.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/TestClass.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TestClass.java	20 Dec 2005 23:44:01 -0000	1.1
+++ TestClass.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -10,6 +10,8 @@
     
     // some fields
     public int x = 2;
+    
+    public int a = 9, b = 4;
     String s = "foo";
     public final static int width = 800;
     
@@ -103,7 +105,14 @@
     
     // fully qualified return type
     java.lang.String getSomeString() {
-        return "";   
+        return "";
+    }
+    
+    
+    
+    
+    String aNewMethod() {
+        return "blah";
     }
     
 //// caused parse errors with previous version of JBrowse, this is bug 637859,
@@ -127,4 +136,12 @@
 // reasons for C programmers.  This class compiles, so it must be allowed.
 };
 
-
+class OneMoreClass {
+    public OneMoreClass() {
+        
+    }
+    
+    public String toString() {
+        return "OneMoreClass";   
+    }
+};

Index: JBrowseActionPane.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/JBrowseActionPane.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- JBrowseActionPane.java	20 Dec 2005 23:44:01 -0000	1.1
+++ JBrowseActionPane.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -112,7 +112,7 @@
                         public void actionPerformed( ActionEvent evt ) {
                             java.net.URL helpUrl = \
JBrowseActionPane.this.getClass().getResource( "/docs/index.html" );  //if ( helpUrl \
                != null ) {
-                              //  new org.gjt.sp.jedit.help.HelpViewer( \
helpUrl.toString() ); +                            //    new \
org.gjt.sp.jedit.help.HelpViewer( helpUrl.toString() );  //}
                             //else
                                 JOptionPane.showMessageDialog(null, "Unable to \
locate help file.", "Unable to locate help file.", JOptionPane.ERROR_MESSAGE); @@ \
-129,7 +129,7 @@  parseAction = new ActionListener(){
                 public void actionPerformed(ActionEvent ae) {
                     if (jbrowse != null)
-                        jbrowse.parse(jEdit.getActiveView().getBuffer());
+                        jbrowse.parse();
                 }
             };
         }

Index: TigerCellRenderer.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/TigerCellRenderer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TigerCellRenderer.java	20 Dec 2005 23:44:01 -0000	1.1
+++ TigerCellRenderer.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -7,10 +7,11 @@
 import javax.swing.event.*;
 import javax.swing.tree.*;
 
-import jbrowse.tiger.parser.ModifierSet;
 import jbrowse.tiger.node.*;
 import jbrowse.tiger.options.*;
 
+import org.gjt.sp.jedit.GUIUtilities;
+
 /**
  * Most of the display settings (how to show) are handled here.
  */
@@ -23,6 +24,7 @@
     private DisplayOptions inverseOptions = null;
 
     // various icons for display
+    private static Icon cuIcon = GUIUtilities.loadIcon( "OpenFile.png" );
     private static ImageIcon classIcon = new ImageIcon( \
TigerCellRenderer.class.getClassLoader().getResource( "jbrowse/tiger/icons/Class.gif" \
                ) );
     private static ImageIcon extendsIcon = new ImageIcon( \
TigerCellRenderer.class.getClassLoader().getResource( \
                "jbrowse/tiger/icons/Extends.gif" ) );
     private static ImageIcon implementsIcon = new ImageIcon( \
TigerCellRenderer.class.getClassLoader().getResource( \
"jbrowse/tiger/icons/Implements.gif" ) ); @@ -73,46 +75,50 @@
 
                     // set the icon
                     Icon icon = null;
-                    switch ( tn.getOrdinal() ) {
-                        case TigerNode.CLASS:
-                            icon = classIcon;
-                            break;
-                        case TigerNode.EXTENDS:
-                            icon = extendsIcon;
-                            break;
-                        case TigerNode.IMPLEMENTS:
-                            icon = implementsIcon;
-                            break;
-                        case TigerNode.INTERFACE:
-                            icon = interfaceIcon;
-                            break;
-                        case TigerNode.CONSTRUCTOR:
-                            icon = constructorIcon;
-                            break;
-                        case TigerNode.METHOD:
-                            icon = methodIcon;
-                            break;
-                        case TigerNode.THROWS:
-                            icon = throwsIcon;
-                            break;
-                        case TigerNode.FIELD:
-                            icon = fieldIcon;
-                            break;
-                        case TigerNode.ENUM:
-                            icon = enumIcon;
-                            break;
-                        default:
-                            icon = defaultIcon;
-                            break;
-                    }
-                    if ( icon != null ) {
-                        lab.setIcon( icon ) ;
+                    if ( options.getShowIcons() ) {
+                        switch ( tn.getOrdinal() ) {
+                            case TigerNode.COMPILATION_UNIT:
+                                icon = cuIcon;
+                                break;
+                            case TigerNode.CLASS:
+                                icon = classIcon;
+                                break;
+                            case TigerNode.EXTENDS:
+                                icon = extendsIcon;
+                                break;
+                            case TigerNode.IMPLEMENTS:
+                                icon = implementsIcon;
+                                break;
+                            case TigerNode.INTERFACE:
+                                icon = interfaceIcon;
+                                break;
+                            case TigerNode.CONSTRUCTOR:
+                                icon = constructorIcon;
+                                break;
+                            case TigerNode.METHOD:
+                                icon = methodIcon;
+                                break;
+                            case TigerNode.THROWS:
+                                icon = throwsIcon;
+                                break;
+                            case TigerNode.FIELD:
+                                icon = fieldIcon;
+                                break;
+                            case TigerNode.ENUM:
+                                icon = enumIcon;
+                                break;
+                            default:
+                                icon = defaultIcon;
+                                break;
+                        }
                     }
+                    // may be null to not show an icon
+                    lab.setIcon( icon ) ;
 
 
                     // build the string for the label
                     StringBuffer sb = new StringBuffer();
-                    
+
                     // maybe add the line number
                     if ( options.getShowLineNum() )
                         sb.append( tn.getLineNumber() ).append( ": " );
@@ -140,20 +146,20 @@
                         else
                             sb.append( " " );
                     }
-                    
+
                     // maybe show keywords, this is the "Keywords specified by \
                icons" setting,
                     // which seems like an odd choice of words to me.  I was \
                expecting icons,
                     // but I think it means more like "show keywords beside icons"
-                    if (options.getShowIconKeywords()) {
-                        switch(tn.getOrdinal()) {
+                    if ( options.getShowIconKeywords() ) {
+                        switch ( tn.getOrdinal() ) {
                             case TigerNode.CLASS:
-                                sb.append("class ");
+                                sb.append( "class " );
                                 break;
                             case TigerNode.EXTENDS:
-                                sb.append("extends ");
+                                sb.append( "extends " );
                                 break;
                             case TigerNode.IMPLEMENTS:
-                                sb.append("implements ");
+                                sb.append( "implements " );
                                 break;
                         }
                     }
@@ -161,15 +167,15 @@
                     // maybe add misc. modifiers, e.g. synchronized, native, \
transient, etc  if ( options.getShowMiscMod() ) {
                         String mods = ModifierSet.modifiersAsString( modifiers );
-                        if (mods != null && mods.length() > 0)
+                        if ( mods != null && mods.length() > 0 )
                             sb.append( mods ).append( " " );
                     }
 
                     // for methods and fields, maybe add return type before node \
name  if ( !options.getTypeIsSuffixed() ) {
-                        switch(tn.getOrdinal()) {
+                        switch ( tn.getOrdinal() ) {
                             case TigerNode.CONSTRUCTOR:
-                                sb.append("/*constructor*/");
+                                sb.append( "/*constructor*/" );
                                 break;
                             case TigerNode.METHOD:
                                 sb.append( ( ( MethodNode ) tn ).getReturnType() \
).append( " " ); @@ -178,7 +184,7 @@
                                 sb.append( ( ( FieldNode ) tn ).getType() ).append( \
" " );  break;
                             case TigerNode.ENUM:
-                                sb.append("enum ");
+                                sb.append( "enum " );
                                 break;
                         }
                     }
@@ -192,50 +198,50 @@
 
 
                     // add the node name
-                    switch (tn.getOrdinal()) {
+                    switch ( tn.getOrdinal() ) {
                         case TigerNode.EXTENDS:
-                            sb.append("class ");
+                            sb.append( "class " );
                             break;
                         case TigerNode.IMPLEMENTS:
-                            sb.append("interface ");
+                            sb.append( "interface " );
                             break;
                     }
-                    sb.append( tn.getName() );  
-                    
+                    sb.append( tn.getName() );
+
                     // maybe show generics type arguments
-                    if (options.getShowTypeArgs()){
+                    if ( options.getShowTypeArgs() ) {
                         String typeParams = null;
-                        if (tn.getOrdinal() == TigerNode.CLASS) {
-                            typeParams = ((ClassNode)tn).getTypeParams();
+                        if ( tn.getOrdinal() == TigerNode.CLASS ) {
+                            typeParams = ( ( ClassNode ) tn ).getTypeParams();
                         }
-                        else if (tn.getOrdinal() == TigerNode.EXTENDS) {
-                            typeParams = ((ExtendsNode)tn).getTypeParams();
+                        else if ( tn.getOrdinal() == TigerNode.EXTENDS ) {
+                            typeParams = ( ( ExtendsNode ) tn ).getTypeParams();
                         }
-                        else if (tn.getOrdinal() == TigerNode.IMPLEMENTS) {
-                            typeParams = ((ImplementsNode)tn).getTypeParams();
+                        else if ( tn.getOrdinal() == TigerNode.IMPLEMENTS ) {
+                            typeParams = ( ( ImplementsNode ) tn ).getTypeParams();
                         }
-                        else if (tn.getOrdinal() == TigerNode.FIELD) {
-                            typeParams = ((FieldNode)tn).getTypeParams();
+                        else if ( tn.getOrdinal() == TigerNode.FIELD ) {
+                            typeParams = ( ( FieldNode ) tn ).getTypeParams();
                         }
-                        if (typeParams != null)
-                            sb.append(typeParams);
+                        if ( typeParams != null )
+                            sb.append( typeParams );
                     }
 
                     // for constructors and methods, maybe add the arguments
                     if ( options.getShowArguments() ) {
                         if ( tn.getOrdinal() == TigerNode.CONSTRUCTOR ) {
-                            sb.append("(").append( ( ( ConstructorNode ) tn \
).getFormalParams(options.getShowArgumentNames(), options.getTypeIsSuffixed(), \
options.getShowMiscMod(), options.getShowTypeArgs()) ).append(")"); +                 \
sb.append( "(" ).append( ( ( ConstructorNode ) tn ).getFormalParams( \
options.getShowArgumentNames(), options.getTypeIsSuffixed(), \
options.getShowMiscMod(), options.getShowTypeArgs() ) ).append( ")" );  }
                         else if ( tn.getOrdinal() == TigerNode.METHOD ) {
-                            sb.append("(").append( ( ( MethodNode ) tn \
).getFormalParams(options.getShowArgumentNames(), options.getTypeIsSuffixed(), \
options.getShowMiscMod(), options.getShowTypeArgs()) ).append(")"); +                 \
sb.append( "(" ).append( ( ( MethodNode ) tn ).getFormalParams( \
options.getShowArgumentNames(), options.getTypeIsSuffixed(), \
options.getShowMiscMod(), options.getShowTypeArgs() ) ).append( ")" );  }
                     }
 
                     // for methods and fields, maybe add return type after node name
                     if ( options.getTypeIsSuffixed() ) {
-                        switch(tn.getOrdinal()) {
+                        switch ( tn.getOrdinal() ) {
                             case TigerNode.CONSTRUCTOR:
-                                sb.append(": &lt;init&gt;");
+                                sb.append( ": &lt;init&gt;" );
                                 break;
                             case TigerNode.METHOD:
                                 sb.append( " : " ).append( ( ( MethodNode ) tn \
).getReturnType() ); @@ -244,13 +250,13 @@
                                 sb.append( " : " ).append( ( ( FieldNode ) tn \
).getType() );  break;
                             case TigerNode.ENUM:
-                                sb.append(" : enum");
+                                sb.append( " : enum" );
                                 break;
                         }
                     }
 
-                    
-                    String labelText = toHtml(sb.toString());
+
+                    String labelText = toHtml( sb.toString() );
                     sb = new StringBuffer();
                     sb.append( "<html>" );
 
@@ -263,8 +269,8 @@
                     if ( options.getAbstractItalic() && ModifierSet.isAbstract( \
tn.getModifiers() ) ) {  sb.append( "<i>" );
                     }
-                    sb.append(labelText);
-                    
+                    sb.append( labelText );
+
                     lab.setText( sb.toString() );
 
                     // tool tips
@@ -277,10 +283,10 @@
 
         return r;
     }
-    
-    private String toHtml(String s) {
-        s = s.replaceAll("<", "&lt;");
-        s = s.replaceAll(">", "&gt;");
+
+    private String toHtml( String s ) {
+        s = s.replaceAll( "<", "&lt;" );
+        s = s.replaceAll( ">", "&gt;" );
         return s;
     }
 

Index: JBrowseStatusPane.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/JBrowseStatusPane.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- JBrowseStatusPane.java	20 Dec 2005 23:44:01 -0000	1.1
+++ JBrowseStatusPane.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -95,7 +95,7 @@
             this.classLabel.setText( "" + results.getClassCount() );
             this.interfaceLabel.setText( "" + results.getInterfaceCount() );
             this.fieldLabel.setText(
-                "" + ( results.getObjAttrCount() + results.getPrimAttrCount() )
+                "" + ( results.getReferenceFieldCount() + \
results.getPrimitiveFieldCount() )  );
             this.methodLabel.setText( "" + results.getMethodCount() );
         }

Index: TigerBrowserParser.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/TigerBrowserParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TigerBrowserParser.java	20 Dec 2005 23:44:01 -0000	1.1
+++ TigerBrowserParser.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -4,8 +4,10 @@
 import java.awt.*;
 import java.awt.event.*;
 import java.util.*;
+import java.util.regex.*;
 import javax.swing.tree.*;
 import javax.swing.*;
+import java.io.*;
 
 // from jEdit:
 import org.gjt.sp.jedit.*;
@@ -61,6 +63,10 @@
         add( new JBrowseActionPane( this ), BorderLayout.NORTH );
     }
 
+    public void parse() {
+        parse( view.getBuffer() );
+    }
+    
     /**
      * Parse the contents of the given buffer.
      * @param buffer the buffer to parse
@@ -69,11 +75,21 @@
         String filename = buffer.getPath();
         DefaultMutableTreeNode root = new DefaultMutableTreeNode( buffer.getName() \
);  if ( filename.endsWith( ".java" ) ) {
-            TigerParser parser = new TigerParser( filename );
+            if ( buffer.getLength() <= 0 )
+                return ;
+            // read the source code directly from the Buffer rather than from the
+            // file.  This means:
+            // 1) a modifed buffer can be parsed without a save
+            // 2) reading the buffer should be faster than reading from the file, \
and +            // 3) jEdit has that 'gzip file on disk' option which won't parse.
+            ByteArrayInputStream input = new ByteArrayInputStream( buffer.getText( \
0, buffer.getLength() ).getBytes() ); +            TigerParser parser = new \
TigerParser( input );  try {
                 CUNode cu = parser.CompilationUnit();
+                cu.setName( buffer.getName() );
+                root.setUserObject( cu );
                 if ( cu.getChildren() != null ) {
-                    Collections.sort(cu.getChildren(), nodeSorter);
+                    Collections.sort( cu.getChildren(), nodeSorter );
                     for ( Iterator it = cu.getChildren().iterator(); it.hasNext(); ) \
{  TigerNode child = ( TigerNode ) it.next();
                         if ( canShow( child ) ) {
@@ -85,14 +101,43 @@
                 }
                 if ( statusPanel != null )
                     statusPanel.showResults( parser.getResults() );
+                try {
+                    input.close();
+                }
+                catch ( Exception e ) {
+                    // not to worry
+                }
+            }
+            catch ( ParseException pe ) {
+                CUNode cu = new CUNode();
+                cu.setName( buffer.getName() );
+                root.setUserObject( cu );
+                root.add( new DefaultMutableTreeNode( "<html><font color=red>" + \
pe.getMessage() ) ); +                /*
+                /// this works well, but can be annoying when editing a file.  Need \
to +                /// add a configuration option for this.
+                Point p = getExceptionLocation( pe );
+                if ( p != null ) {
+                    int column = p.x;
+                    int line_number = p.y;
+                    int offset = view.getTextArea().getLineStartOffset( line_number \
- 1 ) + column; +                    scrollTo( offset );
+                }
+                */
             }
             catch ( Throwable e ) {
-                root = new DefaultMutableTreeNode( "<html><font color=red>" + \
e.getMessage() ); +                CUNode cu = new CUNode();
+                cu.setName( buffer.getName() );
+                root.setUserObject( cu );
+                root.add( new DefaultMutableTreeNode( "<html><font color=red>" + \
e.getMessage() ) );  }
 
         }
         else {
-            root.add( new DefaultMutableTreeNode( "Not a java file." ) );
+            CUNode cu = new CUNode();
+            cu.setName( buffer.getName() );
+            root.setUserObject( cu );
+            root.add( new DefaultMutableTreeNode( "<html><font color=red>Not a java \
file." ) );  }
         if ( scroller != null )
             remove( scroller );
@@ -100,11 +145,10 @@
 
         // expand the tree
         //expandAll(tree, true);    // maybe not the whole thing...
-        // expand the compilation unit and the top class
-        // should expand all top level classes, there could be more than one
+        // expand the compilation unit and the top classes
         tree.expandRow( 0 );
-        if ( tree.getRowCount() > 1 )
-            tree.expandRow( 1 );
+        for ( int i = tree.getRowCount() - 1; i > 0; i-- )
+            tree.expandRow( i );
 
         scroller = new JScrollPane( tree );
 
@@ -116,7 +160,7 @@
 
     private void addChildren( DefaultMutableTreeNode parent, TigerNode tn ) {
         if ( tn.getChildren() != null ) {
-            Collections.sort(tn.getChildren(), nodeSorter);
+            Collections.sort( tn.getChildren(), nodeSorter );
             for ( Iterator it = tn.getChildren().iterator(); it.hasNext(); ) {
                 TigerNode child = ( TigerNode ) it.next();
                 if ( canShow( child ) ) {
@@ -131,38 +175,38 @@
     }
 
     private Comparator nodeSorter = new Comparator() {
-        /**
-         * Compares a TigerNode to another TigerNode for sorting. Sorting may be by
-         * line number or node type as determined by the value of "sorted".
-         * @param o a TigerNode to compare to this node.
-         * @return a negative integer, zero, or a positive integer as this TigerNode \
                is 
-         * less than, equal to, or greater than the specified TigerNode.
-         */
-        public int compare( Object a, Object b ) {
-            if ( ! ( a instanceof TigerNode ) )
-                return -1;
-            if ( ! ( b instanceof TigerNode ) )
-                return 1;
-            TigerNode tna = (TigerNode)a;
-            TigerNode tnb = (TigerNode)b;
-            if ( sorted ) {
-                // sort by type
-                Integer my_ordinal = new Integer( tna.getOrdinal() );
-                Integer other_ordinal = new Integer( tnb.getOrdinal() );
-                if ( my_ordinal.equals( other_ordinal ) ) {
-                    return tna.getName().compareTo( tnb.getName() );
+                /**
+                 * Compares a TigerNode to another TigerNode for sorting. Sorting \
may be by +                 * line number or node type as determined by the value of \
"sorted". +                 * @param o a TigerNode to compare to this node.
+                 * @return a negative integer, zero, or a positive integer as this \
TigerNode is  +                 * less than, equal to, or greater than the specified \
TigerNode. +                 */
+                public int compare( Object a, Object b ) {
+                    if ( ! ( a instanceof TigerNode ) )
+                        return -1;
+                    if ( ! ( b instanceof TigerNode ) )
+                        return 1;
+                    TigerNode tna = ( TigerNode ) a;
+                    TigerNode tnb = ( TigerNode ) b;
+                    if ( sorted ) {
+                        // sort by type
+                        Integer my_ordinal = new Integer( tna.getOrdinal() );
+                        Integer other_ordinal = new Integer( tnb.getOrdinal() );
+                        if ( my_ordinal.equals( other_ordinal ) ) {
+                            return tna.getName().compareTo( tnb.getName() );
+                        }
+                        else
+                            return my_ordinal.compareTo( other_ordinal );
+                    }
+                    else {
+                        // sort by line
+                        Integer my_line = new Integer( tna.getLineNumber() );
+                        Integer other_line = new Integer( tnb.getLineNumber() );
+                        return my_line.compareTo( other_line );
+                    }
                 }
-                else
-                    return my_ordinal.compareTo( other_ordinal );
-            }
-            else {
-                // sort by line
-                Integer my_line = new Integer( tna.getLineNumber() );
-                Integer other_line = new Integer( tnb.getLineNumber() );
-                return my_line.compareTo( other_line );
-            }
-        }
-    };
+            };
 
 
     // single place to check the filter settings, that is, check to see if it
@@ -170,7 +214,7 @@
     private boolean canShow( TigerNode node ) {
         if ( !isVisible( node ) )
             return false;
-        if (node.getOrdinal() == TigerNode.INITIALIZER)
+        if ( node.getOrdinal() == TigerNode.INITIALIZER )
             return filterOpt.getShowInitializers();
         if ( node.getOrdinal() == TigerNode.EXTENDS )
             return filterOpt.getShowGeneralizations();
@@ -188,17 +232,17 @@
 
     // check if a node should be visible based on the 'top level' or 'member \
visible' settings  private boolean isVisible( TigerNode tn ) {
-        if ((tn.getOrdinal() == TigerNode.CLASS || tn.getOrdinal() == \
TigerNode.INTERFACE) && tn.getParent() != null && tn.getParent().getOrdinal() == \
TigerNode.COMPILATION_UNIT) { +        if ( ( tn.getOrdinal() == TigerNode.CLASS || \
tn.getOrdinal() == TigerNode.INTERFACE ) && tn.getParent() != null && \
tn.getParent().getOrdinal() == TigerNode.COMPILATION_UNIT ) {  int visible_level = \
                filterOpt.getTopLevelVisIndex();
-            switch(visible_level) {
+            switch ( visible_level ) {
                 case MutableModifier.TOPLEVEL_VIS_PUBLIC:
-                    return ModifierSet.isPublic(tn.getModifiers());
-                    
+                    return ModifierSet.isPublic( tn.getModifiers() );
+
                 case MutableModifier.TOPLEVEL_VIS_PACKAGE:
                     return true;
             }
         }
-        
+
         int visible_level = filterOpt.getMemberVisIndex();
         switch ( visible_level ) {
             case MutableModifier.MEMBER_VIS_PACKAGE:
@@ -227,16 +271,7 @@
                                 if ( node != null ) {
                                     int line_number = node.getLineNumber();
                                     final int offset = \
                view.getTextArea().getLineStartOffset( line_number - 1 );
-                                    SwingUtilities.invokeLater(
-                                        new Runnable() {
-                                            public void run() {
-                                                view.getTextArea().requestFocus();
-                                                view.getTextArea().setCaretPosition( \
                offset, true );
-                                                view.getTextArea().scrollToCaret( \
                true );
-                                                tree.repaint();
-                                            }
-                                        }
-                                    );
+                                    scrollTo( offset );
                                 }
                             }
                             catch ( ClassCastException cce ) {
@@ -248,6 +283,19 @@
             }
             ;
 
+    private void scrollTo( final int offset ) {
+        SwingUtilities.invokeLater(
+            new Runnable() {
+                public void run() {
+                    view.getTextArea().requestFocus();
+                    view.getTextArea().setCaretPosition( offset, true );
+                    view.getTextArea().scrollToCaret( true );
+                    tree.repaint();
+                }
+            }
+        );
+    }
+
     /**
      * Expand or collapse all nodes in a tree.
      * @param tree the tree
@@ -290,32 +338,75 @@
         EditBus.removeFromBus( this );
     }
 
+    /**
+     * Required by EBComponent, handles EditBus messages. Does nothing if
+     * the auto-reparse setting is false, otherwise, reparses the current
+     * buffer if the buffer saved or loaded, if the edit pane is changed,
+     * or if the buffer that the edit pane is editing is changed.
+     */
     public void handleMessage( EBMessage message ) {
         // check for auto-parse
         if ( !options.getAutomaticParse() )
             return ;
 
+
         /* Original JBrowse only auto-parses on EditPaneUpdate */
         // parse on buffer update
         if ( message instanceof BufferUpdate ) {
             BufferUpdate msg = ( BufferUpdate ) message;
-            if ( msg.getView() != null && msg.getView().equals( view ) ) {
-                parse( msg.getBuffer() );
+            if ( msg.getWhat().equals( BufferUpdate.SAVED ) || msg.getWhat().equals( \
BufferUpdate.LOADED ) ) { +                parse();
             }
         }
         // parse on view update
         else if ( message instanceof ViewUpdate ) {
             ViewUpdate msg = ( ViewUpdate ) message;
             if ( msg.getWhat().equals( ViewUpdate.EDIT_PANE_CHANGED ) ) {
-                parse( view.getBuffer() );
+                parse();
             }
         }
         // parse on edit pane update
         else if ( message instanceof EditPaneUpdate ) {
             EditPaneUpdate msg = ( EditPaneUpdate ) message;
             if ( msg.getWhat().equals( EditPaneUpdate.BUFFER_CHANGED ) ) {
-                parse( msg.getEditPane().getBuffer() );
+                parse();
+            }
+        }
+    }
+
+    /**
+     * @return attempts to return a Point indicating the location of a parser
+     * exception.  If the ParseException contains a Token reference, all is well,
+     * otherwise, this method attempts to parse the message string for the 
+     * exception.  The Point has x set to the column offset, y to the line offset.
+     */
+    private Point getExceptionLocation( ParseException pe ) {
+        Token t = pe.currentToken;
+        if ( t != null ) {
+            return new Point( t.next.beginLine, t.next.beginColumn );
+        }
+
+        // ParseException message look like: "Parse error at line 116, column 5.  \
Encountered: }" +        try {
+            Pattern p = Pattern.compile( "(.*?)(\\d+)(.*?)(\\d+)(.*?)" );
+            Matcher m = p.matcher( pe.getMessage() );
+            if ( m.matches() ) {
+                System.out.println( m.group( 0 ) );
+                String ln = m.group( 2 );
+                String cn = m.group( 4 );
+                int line_number = -1;
+                int column_number = 0;
+                if ( ln != null )
+                    line_number = Integer.parseInt( ln );
+                if ( cn != null )
+                    column_number = Integer.parseInt( cn );
+                return line_number > -1 ? new Point( column_number, line_number ) : \
null;  }
+            return null;
+        }
+        catch ( Exception e ) {
+            e.printStackTrace();
+            return null;
         }
     }
 
@@ -364,6 +455,11 @@
 
     // sorting is by line or by node type, with node type being the initial default.
     // The sort type is signalled by setting a System property.
+
+
+
+
+
     private ActionListener sortOptionAction = null;
     public ActionListener getSortOptionAction() {
         if ( sortOptionAction == null ) {



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic