J. Ryan Stinnett avatar J. Ryan Stinnett committed a0f8da5

Reduced line breaks in xref output

Comments (0)

Files changed (1)

 # HG changeset patch
 # User J. Ryan Stinnett <jryans@gmail.com>
-# Date 1295431261 21600
+# Date 1295431689 21600
 # Node ID e531bb8f756c408c77f86fd719de68ad2fe83aba
 # Parent 707f770da7e0c050e63b8385abcd946a196df739
 Change to a table for xrefs for easier copying
  import java.util.TreeSet;
  
  /**
-@@ -52,9 +54,14 @@
+@@ -48,13 +50,20 @@
+  */
+ public abstract class JFlexXref {
+     public Writer out;
++    private StringWriter stringOut;
++    private int lastOutSize;
+     public String urlPrefix = RuntimeEnvironment.getInstance().getUrlPrefix();
      public Annotation annotation;
      public Project project;
      protected Definitions defs;
      /**
       * Description of styles to use for different types of definitions. Each
       * element in the array contains a three-element string array with the
-@@ -114,6 +121,7 @@
+@@ -114,6 +123,7 @@
      public void reInit(char[] contents, int length) {
          yyreset(new CharArrayReader(contents, 0, length));
          annotation = null;
      }
  
      public void setDefs(Definitions defs) {
-@@ -146,17 +154,31 @@
+@@ -146,17 +156,31 @@
      /**
       * Write xref to the specified {@code Writer}.
       *
 -        this.out = out;
 +    public void write(Writer xrefOut) throws IOException {
 +        this.xrefOut = xrefOut; // line numbers are written directly
-+        out = new StringWriter(); // xref of actual file contents is buffered and then written after the line numbers
++        out = stringOut = new StringWriter(); // xref of actual file contents is buffered and then written after the line numbers
 +
 +        // Write out the symbol table
          writeSymbolTable();
      }
  
      /**
-@@ -201,41 +223,41 @@
+@@ -201,41 +225,41 @@
              }
          }
  
      }
  
      /**
-@@ -263,9 +285,37 @@
+@@ -263,9 +287,41 @@
       * @throws IOException on error when writing the xref
       */
      protected void startNewLine() throws IOException {
 +                out.append("<span class=\"").append(spanClass).append("\">");
 +            }
 +        }
++
++        lastOutSize = stringOut.getBuffer().length();
 +    }
 +
 +    private void endCurrentLine() throws IOException {
-+        // Ensure every line has at least some output
-+        out.write("<br/>");
++        // Blank lines need some output
++        if (stringOut.getBuffer().length() == lastOutSize) {
++            out.write("<br/>");
++        }
 +
 +        // Temporarily close any open spans
 +        for (String spanClass : spanClasses) {
      }
  
      /**
-@@ -375,4 +425,28 @@
+@@ -375,4 +431,28 @@
              out.write(address);
          }
      }
 +    /**
 +     * This is what we expect to find after the content of a single line input.
 +     */
-+    private static final String SINGLE_LINE_SUFFIX = "<br/></div>" +
++    private static final String SINGLE_LINE_SUFFIX = "</div>" +
 +            "</td></tr></table>";
  
      @BeforeClass
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.