maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] rfscholte closed pull request #2: [JXR-100] Fix cross reference generation where there are spaces befor..
Date Sun, 29 Jul 2018 18:52:38 GMT
rfscholte closed pull request #2: [JXR-100] Fix cross reference generation where there are
spaces befor..
URL: https://github.com/apache/maven-jxr/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java b/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
index 8357637..52bff21 100644
--- a/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
+++ b/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java
@@ -676,25 +676,6 @@ public final String xrLine( String line, String packageName, ClassType
classType
         return buff.toString();
     }
 
-    /**
-     * Highlight the package in this line.
-     *
-     * @param line input line
-     * @param packageName package name
-     * @return input line with linked package
-     */
-    public final String xrLine( String line, String packageName )
-    {
-        String href = this.getHREF( packageName );
-
-        String find = packageName;
-
-        // build out what the link would be.
-        String link = "<a href=\"" + href + "\">" + find + "</a>";
-
-        return StringUtils.replace( line, find, link );
-    }
-
     // ----------------------------------------------------------------------
     // private methods
     // ----------------------------------------------------------------------
diff --git a/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java b/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java
index aadf578..79a1550 100644
--- a/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java
+++ b/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java
@@ -19,7 +19,9 @@
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 import java.util.Vector;
 
 /**
@@ -89,35 +91,24 @@
      */
     private static StringEntry[] tokenize( String line, int start )
     {
+        List<StringEntry> entries = new ArrayList<>();
+        line = line.substring(start);
 
-        Vector<StringEntry> words = new Vector<StringEntry>();
-
-        // algorithm works like this... break the line out into segments
-        // that are separated by spaces, and if the entire String doesn't contain
-        // a non-Alpha char then assume it is a word.
-        while ( true )
+        for (char breaker : BREAKERS)
         {
+            line = line.replace(breaker + "", " ");
+        }
 
-            int next = getNextBreak( line, start );
-
-            if ( next < 0 || next <= start )
-            {
-                break;
-            }
-
-            String word = line.substring( start, next );
-
-            if ( isWord( word ) )
-            {
-                words.addElement( new StringEntry( word, start ) );
-            }
+        String[] split = line.split("\\s+");
+        entries.add(new StringEntry(split[0], line.indexOf(split[0],0)));
 
-            start = next + 1;
+        for (int i = 1; i < split.length; i++)
+        {
+            int index = line.indexOf(split[i], line.indexOf(split[i - 1]) + split[i - 1].length());
+            entries.add(new StringEntry(split[i], index));
         }
 
-        StringEntry[] found = new StringEntry[words.size()];
-        words.copyInto( found );
-        return found;
+        return entries.toArray(new StringEntry[entries.size()]);
     }
 
     /**
diff --git a/maven-jxr/src/test/java/org/apache/maven/jxr/util/SimpleWordTokenizerTest.java
b/maven-jxr/src/test/java/org/apache/maven/jxr/util/SimpleWordTokenizerTest.java
new file mode 100644
index 0000000..81af1f6
--- /dev/null
+++ b/maven-jxr/src/test/java/org/apache/maven/jxr/util/SimpleWordTokenizerTest.java
@@ -0,0 +1,96 @@
+package org.apache.maven.jxr.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class SimpleWordTokenizerTest
+{
+    @Test
+    public void testCompact()
+    {
+        StringEntry[] entries = SimpleWordTokenizer.tokenize( "public void withApp1(App app)"
);
+        assertEquals( 5, entries.length );
+
+        assertEquals( "public", entries[0].toString() );
+        assertEquals( 0, entries[0].getIndex() );
+
+        assertEquals( "void", entries[1].toString() );
+        assertEquals( 7, entries[1].getIndex() );
+
+        assertEquals( "withApp1", entries[2].toString() );
+        assertEquals( 12, entries[2].getIndex() );
+
+        assertEquals( "App", entries[3].toString() );
+        assertEquals( 21, entries[3].getIndex() );
+
+        assertEquals( "app", entries[4].toString() );
+        assertEquals( 25, entries[4].getIndex() );
+    }
+
+    @Test
+    public void testSpacesAroundParenOpen()
+    {
+        StringEntry[] entries = SimpleWordTokenizer.tokenize( "public void withApp2 ( App
app)" );
+        assertEquals( 5, entries.length );
+
+        assertEquals( "public", entries[0].toString() );
+        assertEquals( 0, entries[0].getIndex() );
+
+        assertEquals( "void", entries[1].toString() );
+        assertEquals( 7, entries[1].getIndex() );
+
+        assertEquals( "withApp2", entries[2].toString() );
+        assertEquals( 12, entries[2].getIndex() );
+
+        assertEquals( "App", entries[3].toString() );
+        assertEquals( 23, entries[3].getIndex() );
+
+        assertEquals( "app", entries[4].toString() );
+        assertEquals( 27, entries[4].getIndex() );
+    }
+
+    @Test
+    public void testSpaceBeforeParenOpen()
+    {
+        StringEntry[] entries = SimpleWordTokenizer.tokenize( "public void withApp3 (App
app)" );
+        assertEquals( 5, entries.length );
+
+        assertEquals( "public", entries[0].toString() );
+        assertEquals( 0, entries[0].getIndex() );
+
+        assertEquals( "void", entries[1].toString() );
+        assertEquals( 7, entries[1].getIndex() );
+
+        assertEquals( "withApp3", entries[2].toString() );
+        assertEquals( 12, entries[2].getIndex() );
+
+        assertEquals( "App", entries[3].toString() );
+        assertEquals( 22, entries[3].getIndex() );
+
+        assertEquals( "app", entries[4].toString() );
+        assertEquals( 26, entries[4].getIndex() );
+    }
+
+    @Test
+    public void testSpaceAfterParenOpen()
+    {
+        StringEntry[] entries = SimpleWordTokenizer.tokenize( "public void withApp4( App
app)" );
+        assertEquals( 5, entries.length );
+
+        assertEquals( "public", entries[0].toString() );
+        assertEquals( 0, entries[0].getIndex() );
+
+        assertEquals( "void", entries[1].toString() );
+        assertEquals( 7, entries[1].getIndex() );
+
+        assertEquals( "withApp4", entries[2].toString() );
+        assertEquals( 12, entries[2].getIndex() );
+
+        assertEquals( "App", entries[3].toString() );
+        assertEquals( 22, entries[3].getIndex() );
+
+        assertEquals( "app", entries[4].toString() );
+        assertEquals( 26, entries[4].getIndex() );
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message