Author: khmarbaise Date: Sun Oct 26 17:53:17 2014 New Revision: 1634366 URL: http://svn.apache.org/r1634366 Log: [JXR-118] - Fixed checkstyle reported errors. Currently excluded JavaCodeTransform.java based on the different license header.
Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrReport.java maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrTestReport.java maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrTestReportTest.java maven/jxr/trunk/maven-jxr/pom.xml maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AbstractJxrReport.java Sun Oct 26 17:53:17 2014 @@ -92,23 +92,25 @@ public abstract class AbstractJxrReport @Parameter( defaultValue = "${project.name} ${project.version} Reference" ) private String docTitle; + // CHECKSTYLE_OFF: LineLength /** * String used at the bottom of the Xref HTML files. */ @Parameter( property = "bottom", defaultValue = "Copyright © {inceptionYear}–{currentYear} {organizationName}. All rights reserved." ) private String bottom; + // CHECKSTYLE_ON: LineLength + /** - * Directory where Velocity templates can be found to generate overviews, - * frames and summaries. - * Should not be used. If used, should be an absolute path, like <code>"${basedir}/myTemplates"</code>. + * Directory where Velocity templates can be found to generate overviews, frames and summaries. Should not be used. + * If used, should be an absolute path, like <code>"${basedir}/myTemplates"</code>. */ @Parameter( defaultValue = "templates" ) private String templateDir; /** - * Style sheet used for the Xref HTML files. - * Should not be used. If used, should be an absolute path, like <code>"${basedir}/myStyles.css"</code>. + * Style sheet used for the Xref HTML files. Should not be used. If used, should be an absolute path, like + * <code>"${basedir}/myStyles.css"</code>. */ @Parameter( defaultValue = "stylesheet.css" ) private String stylesheet; @@ -152,8 +154,8 @@ public abstract class AbstractJxrReport protected boolean skip; /** - * Link the Javadoc from the Source XRef. Defaults to true and will link - * automatically if javadoc plugin is being used. + * Link the Javadoc from the Source XRef. Defaults to true and will link automatically if javadoc plugin is being + * used. */ @Parameter( defaultValue = "true" ) private boolean linkJavadoc; @@ -161,8 +163,8 @@ public abstract class AbstractJxrReport /** * Gets the effective reporting output files encoding. * - * @return The effective reporting output file encoding, never <code>null</code>: defaults to - * <code>UTF-8</code> instead. + * @return The effective reporting output file encoding, never <code>null</code>: defaults to <code>UTF-8</code> + * instead. */ protected String getOutputEncoding() { @@ -241,15 +243,14 @@ public abstract class AbstractJxrReport } /** - * Creates the Xref for the Java files found in the given source directory and puts - * them in the given destination directory. + * Creates the Xref for the Java files found in the given source directory and puts them in the given destination + * directory. * - * @param locale The user locale to use for the Xref generation + * @param locale The user locale to use for the Xref generation * @param destinationDirectory The output folder - * @param sourceDirs The source directories + * @param sourceDirs The source directories * @throws java.io.IOException * @throws org.apache.maven.jxr.JxrException - * */ private void createXref( Locale locale, String destinationDirectory, List<String> sourceDirs ) throws IOException, JxrException @@ -332,9 +333,11 @@ public abstract class AbstractJxrReport { if ( StringUtils.isNotEmpty( project.getOrganization().getUrl() ) ) { - theBottom = StringUtils.replace( theBottom, "{organizationName}", - "<a href=\"" + project.getOrganization().getUrl() + "\">" - + project.getOrganization().getName() + "</a>" ); + // CHECKSTYLE_OFF: LineLength + theBottom = + StringUtils.replace( theBottom, "{organizationName}", "<a href=\"" + + project.getOrganization().getUrl() + "\">" + project.getOrganization().getName() + "</a>" ); + // CHECKSTYLE_ON: LineLength } else { @@ -352,8 +355,7 @@ public abstract class AbstractJxrReport } /** - * Copy some required resources (like the stylesheet) to the - * given directory + * Copy some required resources (like the stylesheet) to the given directory * * @param dir the directory to copy the resources to */ @@ -432,9 +434,9 @@ public abstract class AbstractJxrReport } /* - * This is called for a standalone execution. Well, that's the claim. It also ends up called for the aggregate mojo, since - * that is configured as an execution, not in the reporting section, at least by some people on some days. We do NOT want - * the default behavior. + * This is called for a standalone execution. Well, that's the claim. It also ends up called for the aggregate mojo, + * since that is configured as an execution, not in the reporting section, at least by some people on some days. We + * do NOT want the default behavior. */ public void execute() throws MojoExecutionException Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrReport.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrReport.java?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrReport.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrReport.java Sun Oct 26 17:53:17 2014 @@ -1,3 +1,5 @@ +package org.apache.maven.plugin.jxr; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -17,8 +19,6 @@ * under the License. */ -package org.apache.maven.plugin.jxr; - import org.apache.maven.plugins.annotations.Mojo; /** Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrTestReport.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrTestReport.java?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrTestReport.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/AggregatorJxrTestReport.java Sun Oct 26 17:53:17 2014 @@ -1,3 +1,5 @@ +package org.apache.maven.plugin.jxr; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,7 +18,6 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugin.jxr; import org.apache.maven.plugins.annotations.Mojo; Modified: maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/main/java/org/apache/maven/plugin/jxr/JxrReportUtil.java Sun Oct 26 17:53:17 2014 @@ -51,14 +51,15 @@ import org.xml.sax.SAXException; */ public class JxrReportUtil { - + private static final String MAVEN_JAVADOC_PLUGIN_GROUP_ID = "org.apache.maven.plugins"; + private static final String MAVEN_JAVADOC_PLUGIN_ARTIFACT_ID = "maven-javadoc-plugin"; /** - * Determine if javadoc is aggregated in this project, paying attention to both - * TODO: take cognizance of javadoc versus test-javadoc - * the old parameter and the new mojo. + * Determine if javadoc is aggregated in this project, paying attention to both TODO: take cognizance of javadoc + * versus test-javadoc the old parameter and the new mojo. + * * @param project * @return * @throws IOException @@ -67,14 +68,16 @@ public class JxrReportUtil throws IOException { // first check conf for obsolete aggregate param. - boolean javadocAggregate = Boolean - .valueOf( JxrReportUtil.getMavenJavadocPluginBasicOption( project, "aggregate", "false" ) ) - .booleanValue(); - if ( javadocAggregate ) + // CHECKSTYLE_OFF: LineLength + boolean javadocAggregate = + Boolean.valueOf( JxrReportUtil.getMavenJavadocPluginBasicOption( project, "aggregate", "false" ) ).booleanValue(); + // CHECKSTYLE_ON: LineLength + + if ( javadocAggregate ) { return true; } - for ( Object pluginObject : getMavenJavadocPlugins ( project ) ) + for ( Object pluginObject : getMavenJavadocPlugins( project ) ) { if ( pluginObject instanceof Plugin ) { @@ -91,11 +94,11 @@ public class JxrReportUtil } } } - } + } } return false; } - + /** * Return the <code>optionName</code> value defined in a project for the "maven-javadoc-plugin" plugin. * @@ -128,9 +131,10 @@ public class JxrReportUtil { Plugin plugin = (Plugin) next; + // CHECKSTYLE_OFF: LineLength // using out-of-box Maven plugins - if ( !( ( plugin.getGroupId().equals( MAVEN_JAVADOC_PLUGIN_GROUP_ID ) ) && ( plugin.getArtifactId() - .equals( pluginArtifactId ) ) ) ) + if ( !isReportPluginMavenJavadoc( pluginArtifactId, plugin ) ) + // CHECKSTYLE_ON: LineLength { continue; } @@ -143,8 +147,7 @@ public class JxrReportUtil ReportPlugin reportPlugin = (ReportPlugin) next; // using out-of-box Maven plugins - if ( !( ( reportPlugin.getGroupId().equals( MAVEN_JAVADOC_PLUGIN_GROUP_ID ) ) && ( reportPlugin - .getArtifactId().equals( pluginArtifactId ) ) ) ) + if ( !isReportPluginJavaDocPlugin( pluginArtifactId, reportPlugin ) ) { continue; } @@ -159,8 +162,8 @@ public class JxrReportUtil try { - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .parse( new StringInputStream( pluginConf.toString() ) ); + StringInputStream stringInputStream = new StringInputStream( pluginConf.toString() ); + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( stringInputStream ); XObject obj = XPathAPI.eval( doc, "//configuration/" + optionName ); @@ -189,7 +192,7 @@ public class JxrReportUtil return defaultValue; } - + /** * Return the plugin references for the javadoc plugin in a project. * @@ -208,7 +211,7 @@ public class JxrReportUtil { plugins.add( it.next() ); } - + List<Object> result = new ArrayList<Object>(); String pluginArtifactId = MAVEN_JAVADOC_PLUGIN_ARTIFACT_ID; @@ -219,8 +222,7 @@ public class JxrReportUtil Plugin plugin = (Plugin) next; // using out-of-box Maven plugins - if ( !( ( plugin.getGroupId().equals( MAVEN_JAVADOC_PLUGIN_GROUP_ID ) ) && ( plugin.getArtifactId() - .equals( pluginArtifactId ) ) ) ) + if ( !isReportPluginMavenJavadoc( pluginArtifactId, plugin ) ) { continue; } @@ -233,8 +235,7 @@ public class JxrReportUtil ReportPlugin reportPlugin = (ReportPlugin) next; // using out-of-box Maven plugins - if ( !( ( reportPlugin.getGroupId().equals( MAVEN_JAVADOC_PLUGIN_GROUP_ID ) ) && ( reportPlugin - .getArtifactId().equals( pluginArtifactId ) ) ) ) + if ( !isReportPluginJavaDocPlugin( pluginArtifactId, reportPlugin ) ) { continue; } @@ -244,13 +245,25 @@ public class JxrReportUtil return result; } + private static boolean isReportPluginMavenJavadoc( String pluginArtifactId, Plugin plugin ) + { + return ( plugin.getGroupId().equals( MAVEN_JAVADOC_PLUGIN_GROUP_ID ) ) + && ( plugin.getArtifactId().equals( pluginArtifactId ) ); + } + + private static boolean isReportPluginJavaDocPlugin( String pluginArtifactId, ReportPlugin reportPlugin ) + { + return ( reportPlugin.getGroupId().equals( MAVEN_JAVADOC_PLUGIN_GROUP_ID ) ) + && ( reportPlugin.getArtifactId().equals( pluginArtifactId ) ); + } + /** * Generates the site structure using the project hierarchy (project and its modules) or using the * distributionManagement elements from the pom.xml. * * @todo come from site plugin! - * @see org.apache.maven.plugins.site.SiteStageMojo#getStructure( MavenProject project, boolean ignoreMissingSiteUrl ) - * + * @see org.apache.maven.plugins.site.SiteStageMojo#getStructure(MavenProject project, boolean ignoreMissingSiteUrl + * ) * @param project * @param ignoreMissingSiteUrl * @return the structure relative path @@ -278,9 +291,8 @@ public class JxrReportUtil { if ( !ignoreMissingSiteUrl ) { - throw new IOException( - "Missing site information in the distribution management element in the project: '" - + project.getName() + "'." ); + throw new IOException( "Missing site information in the distribution management " + + "element in the project: '" + project.getName() + "'." ); } return null; Modified: maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrTestReportTest.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrTestReportTest.java?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrTestReportTest.java (original) +++ maven/jxr/trunk/maven-jxr-plugin/src/test/java/org/apache/maven/plugin/jxr/JxrTestReportTest.java Sun Oct 26 17:53:17 2014 @@ -19,14 +19,13 @@ package org.apache.maven.plugin.jxr; * under the License. */ -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.codehaus.plexus.util.FileUtils; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; + /** * @author <a href="mailto:och...@apache.org">Maria Odea Ching</a> */ @@ -52,9 +51,9 @@ public class JxrTestReportTest JxrTestReport mojo = (JxrTestReport) lookupMojo( "test-jxr", testPom ); mojo.execute(); - File xrefTestDir = new File( getBasedir(), "target/test/unit/testsourcedir-test/target/site/xref-test" ); + File xrefTestDir = new File( getBasedir(), "target/test/unit/testsourcedir-test/target/site/xref-test" ); - //check if the jxr docs were generated + // check if the jxr docs were generated assertTrue( new File( xrefTestDir, "testsourcedir/test/AppSampleTest.html" ).exists() ); assertTrue( new File( xrefTestDir, "testsourcedir/test/AppTest.html" ).exists() ); assertTrue( new File( xrefTestDir, "testsourcedir/test/package-frame.html" ).exists() ); @@ -65,7 +64,7 @@ public class JxrTestReportTest assertTrue( new File( xrefTestDir, "overview-summary.html" ).exists() ); assertTrue( new File( xrefTestDir, "stylesheet.css" ).exists() ); - //check if there's a link to the javadoc files + // check if there's a link to the javadoc files String str = readFile( new File( xrefTestDir, "testsourcedir/test/AppSampleTest.html" ) ); assertTrue( str.toLowerCase().indexOf( "/apidocs/testsourcedir/test/AppSample.html\"".toLowerCase() ) == -1 ); Modified: maven/jxr/trunk/maven-jxr/pom.xml URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr/pom.xml?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr/pom.xml (original) +++ maven/jxr/trunk/maven-jxr/pom.xml Sun Oct 26 17:53:17 2014 @@ -19,7 +19,10 @@ specific language governing permissions under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -37,6 +40,13 @@ under the License. <pluginManagement> <plugins> <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <configuration> + <excludes>**/JavaCodeTransform.java</excludes> + </configuration> + </plugin> + <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> <configuration> Modified: maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java (original) +++ maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/JavaCodeTransform.java Sun Oct 26 17:53:17 2014 @@ -60,14 +60,13 @@ import java.util.Locale; import java.util.Vector; /** - * Syntax highlights java by turning it into html. A codeviewer object is - * created and then keeps state as lines are passed in. Each line passed in as - * java test, is returned as syntax highlighted html text. Users of the class - * can set how the java code will be highlighted with setter methods. Only valid - * java lines should be passed in since the object maintains state and may not - * handle illegal code gracefully. The actual system is implemented as a series - * of filters that deal with specific portions of the java code. The filters are - * as follows: <pre> + * Syntax highlights java by turning it into html. A codeviewer object is created and then keeps state as lines are + * passed in. Each line passed in as java test, is returned as syntax highlighted html text. Users of the class can set + * how the java code will be highlighted with setter methods. Only valid java lines should be passed in since the object + * maintains state and may not handle illegal code gracefully. The actual system is implemented as a series of filters + * that deal with specific portions of the java code. The filters are as follows: + * + * <pre> * htmlFilter * |__ * ongoingMultiLineCommentFilter -> uriFilter @@ -147,14 +146,14 @@ public class JavaCodeTransform /** * Description of the Field */ - public static final String[] VALID_URI_SCHEMES = {"http://", "mailto:"}; + public static final String[] VALID_URI_SCHEMES = { "http://", "mailto:" }; /** - * Specify the only characters that are allowed in a URI besides alpha and - * numeric characters. Refer RFC2396 - http://www.ietf.org/rfc/rfc2396.txt + * Specify the only characters that are allowed in a URI besides alpha and numeric characters. Refer RFC2396 - + * http://www.ietf.org/rfc/rfc2396.txt */ - public static final char[] VALID_URI_CHARS = {'?', '+', '%', '&', ':', '/', '.', '@', '_', ';', '=', '$', ',', '-', - '!', '~', '*', '\'', '(', ')'}; + public static final char[] VALID_URI_CHARS = { '?', '+', '%', '&', ':', '/', '.', '@', '_', ';', '=', '$', ',', + '-', '!', '~', '*', '\'', '(', ')' }; // ---------------------------------------------------------------------- // private fields @@ -251,8 +250,7 @@ public class JavaCodeTransform // ---------------------------------------------------------------------- /** - * Now different method of seeing if at end of input stream, closes inputs - * stream at end. + * Now different method of seeing if at end of input stream, closes inputs stream at end. * * @param line String * @return filtered line of code @@ -264,8 +262,8 @@ public class JavaCodeTransform /** * Gets the header attribute of the JavaCodeTransform object + * * @param out the writer where the header is appended to - * * @return String */ public void appendHeader( PrintWriter out ) @@ -277,8 +275,8 @@ public class JavaCodeTransform } // header - out.println( - "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" ); + out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" ); out.print( "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" ); out.print( locale ); out.print( "\" lang=\"" ); @@ -297,11 +295,11 @@ public class JavaCodeTransform // Use the name of the file instead of the class to handle inner classes properly if ( javaFile.getClassType() != null && javaFile.getClassType().getFilename() != null ) { - out.print( javaFile.getClassType().getFilename() ); + out.print( javaFile.getClassType().getFilename() ); } else { - out.print( this.getCurrentFilename() ); + out.print( this.getCurrentFilename() ); } out.print( " " ); } @@ -330,6 +328,7 @@ public class JavaCodeTransform /** * Gets the footer attribute of the JavaCodeTransform object + * * @param out the writer where the header is appended to * @param bottom the bottom text * @return String @@ -381,8 +380,8 @@ public class JavaCodeTransform { if ( LINE_NUMBERS ) { - out.print( "<a class=\"jxr_linenumber\" name=\"L" + linenumber + "\" " + "href=\"#L" + linenumber + "\">" + linenumber - + "</a>" + getLineWidth( linenumber ) ); + out.print( "<a class=\"jxr_linenumber\" name=\"L" + linenumber + "\" " + "href=\"#L" + linenumber + + "\">" + linenumber + "</a>" + getLineWidth( linenumber ) ); } out.println( this.syntaxHighlight( line ) ); @@ -417,7 +416,7 @@ public class JavaCodeTransform this.sourcefile = sourcefile; this.destfile = destfile; - //make sure that the parent directories exist... + // make sure that the parent directories exist... new File( new File( destfile ).getParent() ).mkdirs(); Reader fr = null; @@ -496,8 +495,7 @@ public class JavaCodeTransform } /** - * From the current file, determine the package root based on the current - * path. + * From the current file, determine the package root based on the current path. * * @return String */ @@ -561,20 +559,21 @@ public class JavaCodeTransform end = j; } - //now you should have the full URI so you can replace this - //in the current buffer + // now you should have the full URI so you can replace this + // in the current buffer if ( end != -1 ) { String uri = line.substring( start, end ); - line = StringUtils.replace( line, uri, - "<a href=\"" + uri + "\" target=\"alexandria_uri\">" + uri + "</a>" ); + line = + StringUtils.replace( line, uri, "<a href=\"" + uri + "\" target=\"alexandria_uri\">" + uri + + "</a>" ); } } } - //if we are in a multiline comment we should not call JXR here. + // if we are in a multiline comment we should not call JXR here. if ( !inMultiLineComment && !inJavadocComment ) { return jxrFilter( line ); @@ -650,13 +649,13 @@ public class JavaCodeTransform find = packageName; } - //build out what the link would be. + // build out what the link would be. link = "<a href=\"" + href + "\">" + find + "</a>"; - //use the SimpleWordTokenizer to find all entries - //that match word. Then replace these with the link + // use the SimpleWordTokenizer to find all entries + // that match word. Then replace these with the link - //now replace the word in the buffer with the link + // now replace the word in the buffer with the link String replace = link; StringEntry[] tokens = SimpleWordTokenizer.tokenize( buff.toString(), find ); @@ -687,7 +686,7 @@ public class JavaCodeTransform String find = packageName; - //build out what the link would be. + // build out what the link would be. String link = "<a href=\"" + href + "\">" + find + "</a>"; return StringUtils.replace( line, find, link ); @@ -703,7 +702,7 @@ public class JavaCodeTransform * @param line String * @return html encoded line */ - private final String htmlFilter( String line ) + private String htmlFilter( String line ) { if ( line == null || line.equals( "" ) ) { @@ -719,29 +718,25 @@ public class JavaCodeTransform } /** - * Handle ongoing multi-line comments, detecting ends if present. - * State is maintained in private boolean members, + * Handle ongoing multi-line comments, detecting ends if present. State is maintained in private boolean members, * one each for javadoc and (normal) multiline comments. * * @param line String * @return String */ - private final String ongoingMultiLineCommentFilter( String line ) + private String ongoingMultiLineCommentFilter( String line ) { if ( line == null || line.equals( "" ) ) { return ""; } final String[] tags = - inJavadocComment - ? new String[] { JAVADOC_COMMENT_START, JAVADOC_COMMENT_END } : - inMultiLineComment - ? new String[] { COMMENT_START, COMMENT_END } : - null; + inJavadocComment ? new String[] { JAVADOC_COMMENT_START, JAVADOC_COMMENT_END } + : inMultiLineComment ? new String[] { COMMENT_START, COMMENT_END } : null; if ( tags == null ) { - //pass the line down to the next filter for processing. + // pass the line down to the next filter for processing. return inlineCommentFilter( line ); } @@ -754,8 +749,7 @@ public class JavaCodeTransform inJavadocComment = false; inMultiLineComment = false; } - StringBuilder buf = new StringBuilder( tags[0] ).append( - comment ); + StringBuilder buf = new StringBuilder( tags[0] ).append( comment ); if ( index >= 0 ) { @@ -771,80 +765,71 @@ public class JavaCodeTransform } /** - * Filter inline comments from a line and formats them properly. One problem - * we'll have to solve here: comments contained in a string should be - * ignored... this is also true of the multi-line comments. So, we could - * either ignore the problem, or implement a function called something like - * isInsideString(line, index) where index points to some point in the line - * that we need to check... started doing this function below. + * Filter inline comments from a line and formats them properly. One problem we'll have to solve here: comments + * contained in a string should be ignored... this is also true of the multi-line comments. So, we could either + * ignore the problem, or implement a function called something like isInsideString(line, index) where index points + * to some point in the line that we need to check... started doing this function below. * * @param line String * @return String */ - private final String inlineCommentFilter( String line ) + private String inlineCommentFilter( String line ) { - //assert !inJavadocComment; - //assert !inMultiLineComment; + // assert !inJavadocComment; + // assert !inMultiLineComment; if ( line == null || line.equals( "" ) ) { return ""; } - int index; - if ( ( index = line.indexOf( "//" ) ) >= 0 && !isInsideString( line, index ) ) + int index = line.indexOf( "//" ); + if ( ( index >= 0 ) && !isInsideString( line, index ) ) { - return new StringBuffer( - beginMultiLineCommentFilter( line.substring( 0, index ) ) ) - .append( COMMENT_START ) - .append( line.substring( index ) ) - .append( COMMENT_END ) - .toString(); + return new StringBuffer( beginMultiLineCommentFilter( line.substring( 0, index ) ) ).append( COMMENT_START ).append( line.substring( index ) ).append( COMMENT_END ).toString(); } return beginMultiLineCommentFilter( line ); } /** - * Detect and handle the start of multiLine comments. - * State is maintained in private boolean members - * one each for javadoc and (normal) multiline comments. + * Detect and handle the start of multiLine comments. State is maintained in private boolean members one each for + * javadoc and (normal) multiline comments. * * @param line String * @return String */ - private final String beginMultiLineCommentFilter( String line ) + private String beginMultiLineCommentFilter( String line ) { - //assert !inJavadocComment; - //assert !inMultiLineComment; + // assert !inJavadocComment; + // assert !inMultiLineComment; if ( line == null || line.equals( "" ) ) { return ""; } - int index; - //check to see if a multi-line comment starts on this line: - if ( ( index = line.indexOf( "/*" ) ) > -1 && !isInsideString( line, index ) ) + int index = line.indexOf( "/*" ); + // check to see if a multi-line comment starts on this line: + if ( ( index > -1 ) && !isInsideString( line, index ) ) { String fromIndex = line.substring( index ); - if ( fromIndex.startsWith( "/**" ) - && !( fromIndex.startsWith( "/**/" ) ) ) + if ( fromIndex.startsWith( "/**" ) && !( fromIndex.startsWith( "/**/" ) ) ) { inJavadocComment = true; - } else { + } + else + { inMultiLineComment = true; } - //Return result of other filters + everything after the start - //of the multiline comment. We need to pass the through the - //to the ongoing multiLineComment filter again in case the comment - //ends on the same line. - return new StringBuilder( - stringFilter( line.substring( 0, index ) ) ).append( - ongoingMultiLineCommentFilter( fromIndex ) ).toString(); + // Return result of other filters + everything after the start + // of the multiline comment. We need to pass the through the + // to the ongoing multiLineComment filter again in case the comment + // ends on the same line. + return new StringBuilder( stringFilter( line.substring( 0, index ) ) ).append( ongoingMultiLineCommentFilter( fromIndex ) ).toString(); } - //Otherwise, no useful multi-line comment information was found so - //pass the line down to the next filter for processesing. + // Otherwise, no useful multi-line comment information was found so + // pass the line down to the next filter for processesing. else { return stringFilter( line ); @@ -857,7 +842,7 @@ public class JavaCodeTransform * @param line String * @return String */ - private final String stringFilter( String line ) + private String stringFilter( String line ) { if ( line == null || line.equals( "" ) ) { @@ -872,10 +857,10 @@ public class JavaCodeTransform int startStringIndex = -1; int endStringIndex = -1; int tempIndex; - //Keep moving through String characters until we want to stop... + // Keep moving through String characters until we want to stop... while ( ( tempIndex = line.indexOf( "\"" ) ) > -1 ) { - //We found the beginning of a string + // We found the beginning of a string if ( startStringIndex == -1 ) { startStringIndex = 0; @@ -883,7 +868,7 @@ public class JavaCodeTransform buf.append( STRING_START ).append( "\"" ); line = line.substring( tempIndex + 1 ); } - //Must be at the end + // Must be at the end else { startStringIndex = -1; @@ -905,9 +890,9 @@ public class JavaCodeTransform * @param line String * @return String */ - private final String keywordFilter( String line ) + private String keywordFilter( String line ) { - final String CLASS_KEYWORD = "class"; + final String classKeyword = "class"; if ( line == null || line.equals( "" ) ) { @@ -921,7 +906,7 @@ public class JavaCodeTransform { temp.setLength( 0 ); ch = line.charAt( i ); - while ( i < line.length() && ( ( ch >= 65 && ch <= 90 ) || ( ch >= 97 && ch <= 122 ) ) ) + while ( i < line.length() && ( ( ch >= 'a' && ch <= 'z' ) || ( ch >= 'A' && ch <= 'Z' ) ) ) { temp.append( ch ); i++; @@ -933,7 +918,7 @@ public class JavaCodeTransform String tempString = temp.toString(); // Special handling of css style class definitions - if ( CLASS_KEYWORD.equals( tempString ) && ch == '=' ) + if ( classKeyword.equals( tempString ) && ch == '=' ) { i++; } @@ -965,27 +950,28 @@ public class JavaCodeTransform * @param newString String * @return String */ - private final String replace( String line, String oldString, String newString ) + private String replace( String line, String oldString, String newString ) { int i = 0; while ( ( i = line.indexOf( oldString, i ) ) >= 0 ) { - line = ( new StringBuffer().append( line.substring( 0, i ) ).append( newString ).append( - line.substring( i + oldString.length() ) ) ).toString(); + line = + ( new StringBuffer().append( line.substring( 0, i ) ).append( newString ).append( line.substring( i + + oldString.length() ) ) ).toString(); i += newString.length(); } return line; } /** - * Checks to see if some position in a line is between String start and - * ending characters. Not yet used in code or fully working :) + * Checks to see if some position in a line is between String start and ending characters. Not yet used in code or + * fully working :) * * @param line String * @param position int * @return boolean */ - private final boolean isInsideString( String line, int position ) + private boolean isInsideString( String line, int position ) { if ( line.indexOf( '"' ) < 0 ) { @@ -1012,7 +998,7 @@ public class JavaCodeTransform /** * Description of the Method */ - private final void loadHash() + private void loadHash() { reservedWords.put( "abstract", "abstract" ); reservedWords.put( "do", "do" ); @@ -1101,7 +1087,7 @@ public class JavaCodeTransform * * @return String */ - private final String getFileOverview() + private String getFileOverview() { StringBuffer overview = new StringBuffer(); @@ -1109,7 +1095,7 @@ public class JavaCodeTransform if ( javadocLinkDir != null ) { overview.append( "<div id=\"overview\">" ); - //get the URI to get Javadoc info. + // get the URI to get Javadoc info. StringBuffer javadocURI = new StringBuffer().append( javadocLinkDir ); try @@ -1137,7 +1123,7 @@ public class JavaCodeTransform String javadocHREF = "<a href=\"" + javadocURI + "\">View Javadoc</a>"; - //get the generation time... + // get the generation time... overview.append( javadocHREF ); overview.append( "</div>" ); @@ -1147,13 +1133,12 @@ public class JavaCodeTransform } /** - * Handles line width which may need to change depending on which line - * number you are on. + * Handles line width which may need to change depending on which line number you are on. * * @param linenumber int * @return String */ - private final String getLineWidth( int linenumber ) + private String getLineWidth( int linenumber ) { if ( linenumber < 10 ) { @@ -1170,19 +1155,18 @@ public class JavaCodeTransform } /** - * Handles finding classes based on the current filename and then makes - * HREFs for you to link to them with. + * Handles finding classes based on the current filename and then makes HREFs for you to link to them with. * * @param line String * @return String */ - private final String jxrFilter( String line ) + private String jxrFilter( String line ) { JavaFile jf = null; try { - //if the current file isn't set then just return + // if the current file isn't set then just return if ( this.getCurrentFilename() == null ) { return line; @@ -1198,14 +1182,14 @@ public class JavaCodeTransform Vector<String> v = new Vector<String>(); - //get the imported packages + // get the imported packages ImportType[] imports = jf.getImportTypes(); for ( int j = 0; j < imports.length; ++j ) { v.addElement( imports[j].getPackage() ); } - //add the current package. + // add the current package. v.addElement( jf.getPackageType().getName() ); String[] packages = new String[v.size()]; @@ -1213,72 +1197,72 @@ public class JavaCodeTransform StringEntry[] words = SimpleWordTokenizer.tokenize( line ); - //go through each word and then match them to the correct class if necessary. + // go through each word and then match them to the correct class if necessary. for ( int i = 0; i < words.length; ++i ) { - //each word + // each word StringEntry word = words[i]; for ( int j = 0; j < packages.length; ++j ) { - //get the package from the PackageManager because this will hold - //the version with the classes also. + // get the package from the PackageManager because this will hold + // the version with the classes also. PackageType currentImport = packageManager.getPackageType( packages[j] ); - //the package here might in fact be null because it wasn't parsed out - //this might be something that is either not included or is part - //of another package and wasn't parsed out. + // the package here might in fact be null because it wasn't parsed out + // this might be something that is either not included or is part + // of another package and wasn't parsed out. if ( currentImport == null ) { continue; } - //see if the current word is within the package + // see if the current word is within the package - //at this point the word could be a fully qualified package name - //(FQPN) or an imported package name. + // at this point the word could be a fully qualified package name + // (FQPN) or an imported package name. String wordName = word.toString(); if ( wordName.indexOf( "." ) != -1 ) { - //if there is a "." in the string then we have to assume - //it is a package. + // if there is a "." in the string then we have to assume + // it is a package. - String fqpn_package = null; - String fqpn_class = null; + String fqpnPackage = null; + String fqpnClass = null; - fqpn_package = wordName.substring( 0, wordName.lastIndexOf( "." ) ); - fqpn_class = wordName.substring( wordName.lastIndexOf( "." ) + 1, wordName.length() ); + fqpnPackage = wordName.substring( 0, wordName.lastIndexOf( "." ) ); + fqpnClass = wordName.substring( wordName.lastIndexOf( "." ) + 1, wordName.length() ); - //note. since this is a reference to a full package then - //it doesn't have to be explicitly imported so this information - //is useless. Instead just see if it was parsed out. + // note. since this is a reference to a full package then + // it doesn't have to be explicitly imported so this information + // is useless. Instead just see if it was parsed out. - PackageType pt = packageManager.getPackageType( fqpn_package ); + PackageType pt = packageManager.getPackageType( fqpnPackage ); if ( pt != null ) { - ClassType ct = pt.getClassType( fqpn_class ); + ClassType ct = pt.getClassType( fqpnClass ); if ( ct != null ) { - //OK. the user specified a full package to be imported - //that is in the package manager so it is time to - //link to it. + // OK. the user specified a full package to be imported + // that is in the package manager so it is time to + // link to it. line = xrLine( line, pt.getName(), ct ); } } - if ( fqpn_package.equals( currentImport.getName() ) - && currentImport.getClassType( fqpn_class ) != null ) + if ( fqpnPackage.equals( currentImport.getName() ) + && currentImport.getClassType( fqpnClass ) != null ) { - //then the package we are currently in is the one specified in the string - //and the import class is correct. - line = xrLine( line, packages[j], currentImport.getClassType( fqpn_class ) ); + // then the package we are currently in is the one specified in the string + // and the import class is correct. + line = xrLine( line, packages[j], currentImport.getClassType( fqpnClass ) ); } } else if ( currentImport.getClassType( wordName ) != null ) @@ -1298,14 +1282,14 @@ public class JavaCodeTransform * @param jc ClassType * @return String */ - private final String getHREF( String dest, ClassType jc ) + private String getHREF( String dest, ClassType jc ) { StringBuffer href = new StringBuffer(); - //find out how to go back to the root + // find out how to go back to the root href.append( this.getPackageRoot() ); - //now find out how to get to the dest package + // now find out how to get to the dest package dest = StringUtils.replace( dest, ".*", "" ); dest = StringUtils.replace( dest, ".", "/" ); @@ -1328,20 +1312,23 @@ public class JavaCodeTransform * @param dest String * @return String */ - private final String getHREF( String dest ) + private String getHREF( String dest ) { return getHREF( dest, null ); } /** - * <p>Given the name of a package... get the number of - * subdirectories/subpackages there would be. </p> - * <p>EX: <code>org.apache.maven == 3</code> </p> + * <p> + * Given the name of a package... get the number of subdirectories/subpackages there would be. + * </p> + * <p> + * EX: <code>org.apache.maven == 3</code> + * </p> * * @param packageName String * @return int */ - private final int getPackageCount( String packageName ) + private int getPackageCount( String packageName ) { if ( packageName == null ) { @@ -1363,29 +1350,26 @@ public class JavaCodeTransform ++count; } - //need to increment this by one + // need to increment this by one ++count; return count; } /** - * Parse out the current link and look for package/import statements and - * then create HREFs for them + * Parse out the current link and look for package/import statements and then create HREFs for them * * @param line String * @return String */ - private final String importFilter( String line ) + private String importFilter( String line ) { int start = -1; /* - Used for determining if this is a package declaration. If it is - then we can make some additional assumptions: - - that this isn't a Class import so the full String is valid - - that it WILL be on the disk since this is based on the current - - file. + * Used for determining if this is a package declaration. If it is then we can make some additional assumptions: + * - that this isn't a Class import so the full String is valid - that it WILL be on the disk since this is + * based on the current - file. */ boolean isPackage = line.trim().startsWith( "package " ); boolean isImport = line.trim().startsWith( "import " ); @@ -1397,10 +1381,10 @@ public class JavaCodeTransform if ( start != -1 ) { - //filter out this packagename... + // filter out this packagename... String pkg = line.substring( start, line.length() ).trim(); - //specify the classname of this import if any. + // specify the classname of this import if any. String classname = null; if ( pkg.indexOf( ".*" ) != -1 ) @@ -1409,14 +1393,14 @@ public class JavaCodeTransform } else if ( !isPackage ) { - //this is an explicit Class import + // this is an explicit Class import String packageLine = pkg.toString(); // This catches a boundary problem where you have something like: // // Foo foo = FooMaster.getFooInstance(). - // danceLittleFoo(); + // danceLittleFoo(); // // This breaks Jxr and won't be a problem when we hook // in the real parser. @@ -1440,20 +1424,22 @@ public class JavaCodeTransform pkg = StringUtils.replace( pkg, ";", "" ); String pkgHREF = getHREF( pkg ); - //if this package is within the PackageManager then you can create an HREF for it. + // if this package is within the PackageManager then you can create an HREF for it. if ( packageManager.getPackageType( pkg ) != null || isPackage ) { - //Create an HREF for explicit classname imports + // Create an HREF for explicit classname imports if ( classname != null ) { - line = StringUtils.replace( line, classname, "<a href=\"" + pkgHREF + "/" + classname + ".html" - + "\">" + classname + "</a>" ); + line = + StringUtils.replace( line, classname, "<a href=\"" + pkgHREF + "/" + classname + ".html" + + "\">" + classname + "</a>" ); } - //now replace the given package with a href - line = StringUtils.replace( line, pkg, "<a href=\"" + pkgHREF + "/" + DirectoryIndexer.INDEX + "\">" - + pkg + "</a>" ); + // now replace the given package with a href + line = + StringUtils.replace( line, pkg, "<a href=\"" + pkgHREF + "/" + DirectoryIndexer.INDEX + "\">" + pkg + + "</a>" ); } } @@ -1461,15 +1447,13 @@ public class JavaCodeTransform return line; } - /** - * if the given char is not one of the following in VALID_URI_CHARS then - * return true + * if the given char is not one of the following in VALID_URI_CHARS then return true * * @param c char to check against VALID_URI_CHARS list * @return <code>true</code> if c is a valid URI char */ - private final boolean isInvalidURICharacter( char c ) + private boolean isInvalidURICharacter( char c ) { for ( int i = 0; i < VALID_URI_CHARS.length; ++i ) { Modified: maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java URL: http://svn.apache.org/viewvc/maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java?rev=1634366&r1=1634365&r2=1634366&view=diff ============================================================================== --- maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java (original) +++ maven/jxr/trunk/maven-jxr/src/main/java/org/apache/maven/jxr/util/SimpleWordTokenizer.java Sun Oct 26 17:53:17 2014 @@ -23,10 +23,9 @@ import java.util.Collections; import java.util.Vector; /** - * This is a small and fast word tokenizer. It has different characteristics - * from the normal Java tokenizer. It only considers clear words that are only - * ended with spaces as strings. EX: "Flight" would be a word but "Flight()" - * would not. + * This is a small and fast word tokenizer. It has different characteristics from the normal Java tokenizer. It only + * considers clear words that are only ended with spaces as strings. EX: "Flight" would be a word but "Flight()" would + * not. */ public class SimpleWordTokenizer { @@ -34,7 +33,7 @@ public class SimpleWordTokenizer /** * Description of the Field */ - public static final char[] BREAKERS = {'(', ')', '[', ' ', '{', '}'}; + public static final char[] BREAKERS = { '(', ')', '[', ' ', '{', '}' }; /** * Break the given line into multiple StringUtils @@ -43,12 +42,12 @@ public class SimpleWordTokenizer { /* - determine where to start processing this String... this could - either be the start of the line or just keep going until the first - */ + * determine where to start processing this String... this could either be the start of the line or just keep + * going until the first + */ int start = getStart( line ); - //find the first non-BREAKER char and assume that is where you want to start + // find the first non-BREAKER char and assume that is where you want to start if ( line == null || line.length() == 0 || start == -1 ) { @@ -58,10 +57,8 @@ public class SimpleWordTokenizer return tokenize( line, start ); } - /** - * Tokenize the given line but only return StringUtils that match the parameter - * find. + * Tokenize the given line but only return StringUtils that match the parameter find. * * @param line String to search in * @param find String to match. @@ -95,9 +92,9 @@ public class SimpleWordTokenizer 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. + // 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 ) { @@ -123,10 +120,9 @@ public class SimpleWordTokenizer return found; } - /** - * Go through the entire String and if any character is not a Java identifier part (_, a, b, - * c, d, etc) then return false. + * Go through the entire String and if any character is not a Java identifier part (_, a, b, c, d, etc) then return + * false. */ private static boolean isWord( String string ) { @@ -174,7 +170,7 @@ public class SimpleWordTokenizer } - //if the breakPoint is still -1 go to the end of the string + // if the breakPoint is still -1 go to the end of the string if ( breakPoint == -1 ) { breakPoint = string.length(); @@ -192,7 +188,7 @@ public class SimpleWordTokenizer for ( int i = 0; i < string.length(); ++i ) { - if ( isBreaker( string.charAt( i ) ) == false ) + if ( !isBreaker( string.charAt( i ) ) ) { return i; } @@ -202,7 +198,6 @@ public class SimpleWordTokenizer return -1; } - /** * Return true if the given char is considered a breaker. */ @@ -223,4 +218,3 @@ public class SimpleWordTokenizer } } -