[ https://issues.apache.org/jira/browse/JXR-100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16561231#comment-16561231 ]
ASF GitHub Bot commented on JXR-100: ------------------------------------ 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: us...@infra.apache.org > Method declaration: using spaces before or after parenthesis prevents cross > references generation > ------------------------------------------------------------------------------------------------- > > Key: JXR-100 > URL: https://issues.apache.org/jira/browse/JXR-100 > Project: Maven JXR > Issue Type: Bug > Components: jxr > Affects Versions: 2.3 > Reporter: Davide Cavestro > Assignee: Robert Scholte > Priority: Major > Fix For: 3.0.0 > > Attachments: missinglinks.png, my-app.zip > > > Launching JXR on a file containing method declarations with no spaces between > the method name and the parenthesis also generates links to method parameters > types. > Adding a whitespace before or after method declaration prevents link > generation, i.e. I get the method declaration in plain text, with no > clickable reference to _App_ type. > !missinglinks.png! > I've attached the example project as [^my-app.zip]. -- This message was sent by Atlassian JIRA (v7.6.3#76005)