New Javadoc style check from Chris Stillwell.
This commit is contained in:
parent
d917b95a01
commit
51dae59b8d
|
|
@ -256,6 +256,8 @@
|
|||
<classpath refid="run.classpath"/>
|
||||
<property key="checkstyle.cache.file" file="target/cachefile"/>
|
||||
<property key="checkstyle.header.file" file="docs/java.header"/>
|
||||
<property key="checkstyle.suppressions.file"
|
||||
file="docs/suppressions.xml"/>
|
||||
</checkstyle>
|
||||
</target>
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@
|
|||
|
||||
<property name="severity" value="error"/>
|
||||
|
||||
<module name="filter.SuppressionFilter">
|
||||
<property name="file" value="${checkstyle.suppressions.file}"/>
|
||||
</module>
|
||||
|
||||
<module name="PackageHtml"/>
|
||||
|
||||
<module name="Translation">
|
||||
|
|
@ -46,6 +50,9 @@
|
|||
<property name="allowThrowsTagsForSubclasses" value="true"/>
|
||||
</module>
|
||||
<module name="JavadocVariable"/>
|
||||
<module name="JavadocStyle">
|
||||
<property name="scope" value="public"/>
|
||||
</module>
|
||||
|
||||
<module name="LeftCurly">
|
||||
<property name="tokens" value="CLASS_DEF,INTERFACE_DEF,METHOD_DEF,CTOR_DEF"/>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@
|
|||
<li>
|
||||
<a href="#JavadocVariable">JavadocVariable</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#JavadocStyle">JavadocStyle</a>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
<!--Content-->
|
||||
|
|
@ -385,6 +388,125 @@ convention of using a
|
|||
<p class="body">
|
||||
<a href="config.html#treewalker">TreeWalker</a>
|
||||
</p>
|
||||
|
||||
|
||||
<a name="JavadocStyle"></a>
|
||||
<h2>JavadocStyle</h2>
|
||||
<h4>Description</h4>
|
||||
|
||||
<p class="body">
|
||||
Validates Javadoc comments to help ensure they are well formed.
|
||||
The following checks are performed:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
|
||||
<li> Ensures the first sentence ends with proper punctuation (That
|
||||
is a period, question mark, or exclaimation mark). Javadoc
|
||||
automatically places the first sentence in the method summary table
|
||||
and index. With out proper punctuation the Javadoc may be
|
||||
malformed.
|
||||
</li>
|
||||
|
||||
<li> Check text for incomplete HTML tags. Verifies that HTML tags
|
||||
have corresponding end tags and issues an "Unclosed HTML tag found:"
|
||||
error if not. An "Extra HTML tag found:" error is issued if an end
|
||||
tag is found without a previous open tag.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>These checks were patterned after the checks made by the <a
|
||||
href="http://java.sun.com/j2se/javadoc/doccheck/index.html">DocCheck</a>
|
||||
doclet available from Sun. </p>
|
||||
|
||||
<h4>Properties</h4>
|
||||
|
||||
<table width="100%" border="1" cellpadding="5" class="body">
|
||||
<tr class="header">
|
||||
<th>name</th>
|
||||
<th>description</th>
|
||||
<th>type</th>
|
||||
<th>default value</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>scope</td>
|
||||
<td>visibility scope where Javadoc comments are checked</td>
|
||||
<td><a href="property_types.html#scope">scope</a></td>
|
||||
<td><span class="default">private</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>checkFirstSentence</td>
|
||||
<td>Whether to check the first sentence for proper end of sentence.</td>
|
||||
<td><a href="property_types.html#boolean">boolean</a></td>
|
||||
<td><span class="default">true</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>checkHtml</td>
|
||||
<td>Whether to check for incomplete html tags.</td>
|
||||
<td><a href="property_types.html#boolean">boolean</a></td>
|
||||
<td><span class="default">true</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>tokens</td>
|
||||
<td>definitions to check</td>
|
||||
|
||||
<td>subset of tokens
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">INTERFACE_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">INTERFACE_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a>,
|
||||
<a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#VARIABLE_DEF">VARIABLE_DEF</a>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Examples</h4>
|
||||
|
||||
<p class="body">
|
||||
To configure the default check:
|
||||
</p>
|
||||
|
||||
<pre class="body">
|
||||
<module name="JavadocStyle"/>
|
||||
</pre>
|
||||
|
||||
<p class="body">
|
||||
To configure the check for <span class="default">public</span> scope:
|
||||
</p>
|
||||
|
||||
<pre class="body">
|
||||
<module name="JavadocStyle">
|
||||
<property name="scope" value="public"/>
|
||||
</module>
|
||||
</pre>
|
||||
|
||||
<p class="body">
|
||||
To configure the check to turn off first sentence checking:
|
||||
</p>
|
||||
<pre class="body">
|
||||
<module name="JavadocStyle">
|
||||
<property name="checkFirstSentence" value="false"/>
|
||||
</module>
|
||||
</pre>
|
||||
|
||||
<p class="body">
|
||||
|
||||
<h4>Package</h4>
|
||||
<p class="body">
|
||||
com.puppycrawl.tools.checkstyle.checks
|
||||
</p>
|
||||
<h4>Parent Module</h4>
|
||||
<p class="body">
|
||||
<a href="config.html#treewalker">TreeWalker</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@
|
|||
738205, 738388). Example listeners perform verbose and Commons Logging
|
||||
audits (request 737584).</li>
|
||||
|
||||
<li class="body">Added JavadocStyle check to ensure they are
|
||||
stylistically well formed. Nice patch from Chris Stillwell.</li>
|
||||
|
||||
<li class="body">Added check for trailing comma in array
|
||||
initialization (module ArrayTrailingComma, request
|
||||
696301).</li>
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
<module name="JavadocMethod"/>
|
||||
<module name="JavadocType"/>
|
||||
<module name="JavadocVariable"/>
|
||||
<module name="JavadocStyle">
|
||||
|
||||
|
||||
<!-- Checks for Naming Conventions. -->
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE suppressions PUBLIC
|
||||
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
|
||||
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
|
||||
|
||||
<suppressions>
|
||||
<suppress checks="JavadocStyleCheck"
|
||||
files="AbstractLoader.java"
|
||||
lines="86"/>
|
||||
<suppress checks="JavadocStyleCheck"
|
||||
files="AbstractComplexityCheck.java"
|
||||
lines="82,108,122"/>
|
||||
<suppress checks="JavadocStyleCheck"
|
||||
files="CyclomaticComplexityCheck.java"
|
||||
lines="48"/>
|
||||
<suppress checks="MagicNumberCheck"
|
||||
files="JavadocStyleCheck.java"
|
||||
lines="221"/>
|
||||
</suppressions>
|
||||
|
|
@ -121,7 +121,7 @@ public class CheckStyleTask
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a formatter
|
||||
* Add a formatter.
|
||||
* @param aFormatter the formatter to add for logging.
|
||||
*/
|
||||
public void addFormatter(Formatter aFormatter)
|
||||
|
|
@ -130,7 +130,7 @@ public class CheckStyleTask
|
|||
}
|
||||
|
||||
/**
|
||||
* Add an override property
|
||||
* Add an override property.
|
||||
* @param aProperty the property to add
|
||||
*/
|
||||
public void addProperty(Property aProperty)
|
||||
|
|
@ -139,7 +139,7 @@ public class CheckStyleTask
|
|||
}
|
||||
|
||||
/**
|
||||
* Add a custom listener
|
||||
* Add a custom listener.
|
||||
* @param aListener the listener to add
|
||||
*/
|
||||
public void addListener(Listener aListener)
|
||||
|
|
@ -610,7 +610,7 @@ public class CheckStyleTask
|
|||
}
|
||||
}
|
||||
|
||||
/** Represents a custom listener */
|
||||
/** Represents a custom listener. */
|
||||
public static class Listener
|
||||
{
|
||||
/** classname of the listener class */
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ public class Checker extends AutomaticBean
|
|||
private Context mChildContext;
|
||||
|
||||
/** The audit event filter chain */
|
||||
private FilterChain mFilterChain = new FilterChain();
|
||||
private final FilterChain mFilterChain = new FilterChain();
|
||||
|
||||
/**
|
||||
* The severity level of any violations found by submodules.
|
||||
|
|
@ -232,14 +232,14 @@ public class Checker extends AutomaticBean
|
|||
mFilterChain.addFilter(aFilter);
|
||||
}
|
||||
|
||||
/** Cleans up the object **/
|
||||
/** Cleans up the object. **/
|
||||
public void destroy()
|
||||
{
|
||||
mListeners.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the listener that will be used to receive events from the audit
|
||||
* Add the listener that will be used to receive events from the audit.
|
||||
* @param aListener the nosy thing
|
||||
*/
|
||||
public void addListener(AuditListener aListener)
|
||||
|
|
@ -321,7 +321,7 @@ public class Checker extends AutomaticBean
|
|||
}
|
||||
|
||||
/**
|
||||
* notify all listeners about the beginning of a file audit
|
||||
* Notify all listeners about the beginning of a file audit.
|
||||
* @param aFileName the file to be audited
|
||||
*/
|
||||
public void fireFileStarted(String aFileName)
|
||||
|
|
@ -338,7 +338,7 @@ public class Checker extends AutomaticBean
|
|||
}
|
||||
|
||||
/**
|
||||
* notify all listeners about the end of a file audit
|
||||
* Notify all listeners about the end of a file audit.
|
||||
* @param aFileName the audited file
|
||||
*/
|
||||
public void fireFileFinished(String aFileName)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public final class Defn
|
|||
}
|
||||
///CLOVER:ON
|
||||
|
||||
/** name of resource bundle for Checkstyle */
|
||||
/** Name of resource bundle for Checkstyle. */
|
||||
public static final String CHECKSTYLE_BUNDLE =
|
||||
"com.puppycrawl.tools.checkstyle.messages";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,37 +39,37 @@ public interface AuditListener
|
|||
extends EventListener
|
||||
{
|
||||
/**
|
||||
* notify that the audit is about to start
|
||||
* Notify that the audit is about to start.
|
||||
* @param aEvt the event details
|
||||
*/
|
||||
void auditStarted(AuditEvent aEvt);
|
||||
|
||||
/**
|
||||
* notify that the audit is finished
|
||||
* Notify that the audit is finished.
|
||||
* @param aEvt the event details
|
||||
*/
|
||||
void auditFinished(AuditEvent aEvt);
|
||||
|
||||
/**
|
||||
* notify that audit is about to start on a specific file
|
||||
* Notify that audit is about to start on a specific file.
|
||||
* @param aEvt the event details
|
||||
*/
|
||||
void fileStarted(AuditEvent aEvt);
|
||||
|
||||
/**
|
||||
* notify that audit is finished on a specific file
|
||||
* Notify that audit is finished on a specific file.
|
||||
* @param aEvt the event details
|
||||
*/
|
||||
void fileFinished(AuditEvent aEvt);
|
||||
|
||||
/**
|
||||
* notify that an audit error was discovered on a specific file
|
||||
* Notify that an audit error was discovered on a specific file.
|
||||
* @param aEvt the event details
|
||||
*/
|
||||
void addError(AuditEvent aEvt);
|
||||
|
||||
/**
|
||||
* notify that an exception happened while performing audit
|
||||
* Notify that an exception happened while performing audit.
|
||||
* @param aEvt the event details
|
||||
* @param aThrowable details of the exception
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ public abstract class Check extends AbstractViolationReporter
|
|||
}
|
||||
|
||||
/**
|
||||
* Set the tab width to report errors with
|
||||
* Set the tab width to report errors with.
|
||||
* @param aTabWidth an <code>int</code> value
|
||||
*/
|
||||
public final void setTabWidth(int aTabWidth)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public interface Configuration extends Serializable
|
|||
String[] getAttributeNames();
|
||||
|
||||
/**
|
||||
* The attribute value for an attribute name
|
||||
* The attribute value for an attribute name.
|
||||
* @param aName the attribute name
|
||||
* @return the value that is associated with aName
|
||||
* @throws CheckstyleException if aName is not a valid attribute name
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public final class DetailAST
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets this AST's first Child
|
||||
* Sets this AST's first Child.
|
||||
* @param aAST the new first child
|
||||
*/
|
||||
public void setFirstChild(AST aAST)
|
||||
|
|
@ -90,7 +90,7 @@ public final class DetailAST
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets AST's next sibling
|
||||
* Sets AST's next sibling.
|
||||
* @param aAST the new next sibling
|
||||
*/
|
||||
public void setNextSibling(AST aAST)
|
||||
|
|
@ -102,7 +102,7 @@ public final class DetailAST
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds new child to AST
|
||||
* Adds new child to AST.
|
||||
* @param aAST the new child
|
||||
*/
|
||||
public void addChild(AST aAST)
|
||||
|
|
@ -151,7 +151,7 @@ public final class DetailAST
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the parent token
|
||||
* Returns the parent token.
|
||||
* @return the parent token
|
||||
*/
|
||||
public DetailAST getParent()
|
||||
|
|
|
|||
|
|
@ -51,6 +51,6 @@ public interface FileSetCheck
|
|||
*/
|
||||
void process(File[] aFiles);
|
||||
|
||||
/** Cleans up the object **/
|
||||
/** Cleans up the object. **/
|
||||
void destroy();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ package com.puppycrawl.tools.checkstyle.api;
|
|||
public interface Filter
|
||||
|
||||
{
|
||||
/** The object is acceptable to this Filter */
|
||||
/** The object is acceptable to this filter. */
|
||||
int ACCEPT = -1;
|
||||
|
||||
/** The object is rejected by this filter. */
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ public final class LocalizedMessages
|
|||
mMessages.toArray(new LocalizedMessage[mMessages.size()]);
|
||||
}
|
||||
|
||||
/** Reset the object **/
|
||||
/** Reset the object. **/
|
||||
public void reset()
|
||||
{
|
||||
mMessages.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message to be reported
|
||||
* Logs a message to be reported.
|
||||
* @param aMsg the message to log
|
||||
**/
|
||||
public void add(LocalizedMessage aMsg)
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ package com.puppycrawl.tools.checkstyle.api;
|
|||
public interface MessageDispatcher
|
||||
{
|
||||
/**
|
||||
* Notify all listeners about the beginning of a file audit
|
||||
* Notify all listeners about the beginning of a file audit.
|
||||
* @param aFileName the file to be audited
|
||||
*/
|
||||
void fireFileStarted(String aFileName);
|
||||
|
||||
/**
|
||||
* Notify all listeners about the end of a file audit
|
||||
* Notify all listeners about the end of a file audit.
|
||||
* @param aFileName the audited file
|
||||
*/
|
||||
void fireFileFinished(String aFileName);
|
||||
|
|
|
|||
|
|
@ -59,27 +59,27 @@ public final class Scope implements Comparable, Serializable
|
|||
/** anon inner scopename */
|
||||
private static final String SCOPENAME_ANONINNER = "anoninner";
|
||||
|
||||
/** nothing scope */
|
||||
/** nothing scope. */
|
||||
public static final Scope NOTHING =
|
||||
new Scope(SCOPECODE_NOTHING, SCOPENAME_NOTHING);
|
||||
|
||||
/** public scope */
|
||||
/** public scope. */
|
||||
public static final Scope PUBLIC =
|
||||
new Scope(SCOPECODE_PUBLIC, SCOPENAME_PUBLIC);
|
||||
|
||||
/** protected scope */
|
||||
/** protected scope. */
|
||||
public static final Scope PROTECTED =
|
||||
new Scope(SCOPECODE_PROTECTED, SCOPENAME_PROTECTED);
|
||||
|
||||
/** package scope */
|
||||
/** package scope. */
|
||||
public static final Scope PACKAGE =
|
||||
new Scope(SCOPECODE_PACKAGE, SCOPENAME_PACKAGE);
|
||||
|
||||
/** private scope */
|
||||
/** private scope. */
|
||||
public static final Scope PRIVATE =
|
||||
new Scope(SCOPECODE_PRIVATE, SCOPENAME_PRIVATE);
|
||||
|
||||
/** anon inner scope */
|
||||
/** anon inner scope. */
|
||||
public static final Scope ANONINNER =
|
||||
new Scope(SCOPECODE_ANONINNER, SCOPENAME_ANONINNER);
|
||||
|
||||
|
|
@ -121,8 +121,8 @@ public final class Scope implements Comparable, Serializable
|
|||
*/
|
||||
public int compareTo(Object aObject)
|
||||
{
|
||||
Scope scope = (Scope) aObject;
|
||||
return this.mCode - scope.mCode;
|
||||
final Scope s = (Scope) aObject;
|
||||
return this.mCode - s.mCode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public final class SeverityLevel implements Comparable, Serializable
|
|||
public static final SeverityLevel INFO =
|
||||
new SeverityLevel(SEVERITYCODE_INFO, SEVERITYNAME_INFO);
|
||||
|
||||
/** Severity level: warning */
|
||||
/** Severity level: warning. */
|
||||
public static final SeverityLevel WARNING =
|
||||
new SeverityLevel(SEVERITYCODE_WARNING, SEVERITYNAME_WARNING);
|
||||
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ public final class TokenTypes
|
|||
* <p>For example:</p>
|
||||
* <pre>
|
||||
* implements Serializable, Comparable
|
||||
* <pre>
|
||||
* </pre>
|
||||
* <p>parses as:</p>
|
||||
* <pre>
|
||||
* +--IMPLEMENTS_CLAUSE
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
|||
* bad pratice such as calling
|
||||
* ex.printStacktrace(), System.out.println(), System.exit(), etc.
|
||||
* </p>
|
||||
* <p>
|
||||
* An example of how to configure the check for calls to
|
||||
* <code>System.out.println</code> is:
|
||||
* </p>
|
||||
|
|
@ -55,7 +56,7 @@ public class GenericIllegalRegexpCheck extends AbstractFormatCheck
|
|||
private boolean mIgnoreCase = false;
|
||||
|
||||
/**
|
||||
* Setter for message property
|
||||
* Setter for message property.
|
||||
* @param aMessage custom message which should be used
|
||||
* to report about violations.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -32,19 +32,19 @@ public final class LineSeparatorOption extends AbstractOption
|
|||
/** maps from a string representation to an option */
|
||||
private static final Map STR_TO_OPT = new HashMap();
|
||||
|
||||
/** Windows-style line separators **/
|
||||
/** Windows-style line separators. **/
|
||||
public static final LineSeparatorOption CRLF =
|
||||
new LineSeparatorOption("crlf", "\r\n");
|
||||
|
||||
/** Mac-style line separators **/
|
||||
/** Mac-style line separators. **/
|
||||
public static final LineSeparatorOption CR =
|
||||
new LineSeparatorOption("cr", "\r");
|
||||
|
||||
/** Unix-style line separators **/
|
||||
/** Unix-style line separators. **/
|
||||
public static final LineSeparatorOption LF =
|
||||
new LineSeparatorOption("lf", "\n");
|
||||
|
||||
/** System default line separators **/
|
||||
/** System default line separators. **/
|
||||
public static final LineSeparatorOption SYSTEM = new LineSeparatorOption(
|
||||
"system", System.getProperty("line.separator"));
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ import com.puppycrawl.tools.checkstyle.api.Utils;
|
|||
* characters. Line 4 enforces that the copyright notice includes a four digit
|
||||
* year. Line 5 is an example how to enforce revision control keywords in a file
|
||||
* header.</p>
|
||||
* An example of how to configure the check to use header file
|
||||
* <p>An example of how to configure the check to use header file
|
||||
* "java.header" and ignore lines 4 and 5 is:
|
||||
* </p>
|
||||
* <pre>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public final class NestedIfDepthCheck extends AbstractNestedDepthCheck
|
|||
/** default allowed nesting depth. */
|
||||
private static final int DEFAULT_MAX = 1;
|
||||
|
||||
/** Creates new check instance with default allowed nesting depth */
|
||||
/** Creates new check instance with default allowed nesting depth. */
|
||||
public NestedIfDepthCheck()
|
||||
{
|
||||
super(DEFAULT_MAX);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public final class NestedTryDepthCheck extends AbstractNestedDepthCheck
|
|||
/** default allowed nesting depth */
|
||||
private static final int DEFAULT_MAX = 1;
|
||||
|
||||
/** Creates new check instance with default allowed nesting depth */
|
||||
/** Creates new check instance with default allowed nesting depth. */
|
||||
public NestedTryDepthCheck()
|
||||
{
|
||||
super(DEFAULT_MAX);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class RedundantThrowsCheck
|
|||
private boolean mAllowSubclasses = false;
|
||||
|
||||
/**
|
||||
* Getter for allowUnchecked property
|
||||
* Getter for allowUnchecked property.
|
||||
* @param aAllowUnchecked whether unchecked excpetions in throws
|
||||
* are allowed or not
|
||||
*/
|
||||
|
|
@ -68,7 +68,7 @@ public class RedundantThrowsCheck
|
|||
}
|
||||
|
||||
/**
|
||||
* Getter for allowSubclasses property
|
||||
* Getter for allowSubclasses property.
|
||||
* @param aAllowSubclasses whether subclass of another declared
|
||||
* exception is allowed in throws clause
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class VisibilityModifierCheck
|
|||
/** regexp for public members that should be ignored */
|
||||
private RE mPublicMemberRE = null;
|
||||
|
||||
/** Constructor */
|
||||
/** Create an instance. */
|
||||
public VisibilityModifierCheck()
|
||||
{
|
||||
setPublicMemberPattern(mPublicMemberPattern);
|
||||
|
|
@ -91,7 +91,7 @@ public class VisibilityModifierCheck
|
|||
}
|
||||
|
||||
/**
|
||||
* Set whether package visible members are allowed
|
||||
* Set whether package visible members are allowed.
|
||||
* @param aPackageAllowed whether package visible members are allowed
|
||||
*/
|
||||
public void setPackageAllowed(boolean aPackageAllowed)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* are <a href="http://java.sun.com/products/jdk/faq/faq-sun-packages.html">
|
||||
* not 100% Pure Java</a>.
|
||||
* </p>
|
||||
* <p>
|
||||
* To reject other packages, set property illegalPkgs to a comma-separated
|
||||
* list of the illegal packages.
|
||||
* </p>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* is called</LI>
|
||||
* <LI>now all the repetitous code which checks for BOL, if curlys are on
|
||||
* same line, etc. can be collapsed into the superclass</LI>
|
||||
* </OL>
|
||||
* </UL>
|
||||
*
|
||||
* @author jrichard
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class HandlerFactory
|
|||
///CLOVER:ON
|
||||
}
|
||||
|
||||
/** creates a HandlerFactory */
|
||||
/** Creates a HandlerFactory. */
|
||||
public HandlerFactory()
|
||||
{
|
||||
register(TokenTypes.CASE_GROUP, CaseHandler.class);
|
||||
|
|
@ -110,7 +110,7 @@ public class HandlerFactory
|
|||
}
|
||||
|
||||
/**
|
||||
* returns true if this type (form TokenTypes) is handled
|
||||
* Returns true if this type (form TokenTypes) is handled.
|
||||
*
|
||||
* @param aType type from TokenTypes
|
||||
* @return true if handler is registered, false otherwise
|
||||
|
|
@ -122,7 +122,7 @@ public class HandlerFactory
|
|||
}
|
||||
|
||||
/**
|
||||
* gets list of registered handler types
|
||||
* Gets list of registered handler types.
|
||||
*
|
||||
* @return int[] of TokenType types
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class IndentationCheck
|
|||
/** factory from which handlers are distributed */
|
||||
private HandlerFactory mHandlerFactory = new HandlerFactory();
|
||||
|
||||
/** Creates a new instance of IndentationCheck */
|
||||
/** Creates a new instance of IndentationCheck. */
|
||||
public IndentationCheck()
|
||||
{
|
||||
}
|
||||
|
|
@ -192,7 +192,7 @@ public class IndentationCheck
|
|||
}
|
||||
|
||||
/**
|
||||
* Log an error message
|
||||
* Log an error message.
|
||||
*
|
||||
* @param aLine the line number where the error was found
|
||||
* @param aKey the message that describes the error
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
|||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
|
||||
/**
|
||||
* Abstract class for J2ee component checking
|
||||
* Abstract class for J2ee component checking.
|
||||
* @author Rick Giles
|
||||
*/
|
||||
public abstract class AbstractJ2eeCheck
|
||||
|
|
@ -90,4 +90,4 @@ public abstract class AbstractJ2eeCheck
|
|||
{
|
||||
mMethodChecker = aMethodChecker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
|||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
|
||||
/**
|
||||
* Root class for bean method checks
|
||||
* Root class for bean method checks.
|
||||
* @author Rick Giles
|
||||
*/
|
||||
public abstract class BeanMethodChecker
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class EntityBeanCheck
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the set <code>PersistenceOption</code>
|
||||
* Returns the set <code>PersistenceOption</code>.
|
||||
* @return the set <code>PersistenceOption</code>
|
||||
*/
|
||||
public PersistenceOption getPersistenceOption()
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ public class LocalInterfaceMethodChecker
|
|||
{
|
||||
|
||||
/**
|
||||
* Constructs a <code>LocalInterfaceMethodChecker for a
|
||||
* local interface check.
|
||||
* Constructs a <code>LocalInterfaceMethodChecker</code> for a local
|
||||
* interface check.
|
||||
* @param aCheck the local interface check.
|
||||
*/
|
||||
public LocalInterfaceMethodChecker(LocalInterfaceCheck aCheck)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ package com.puppycrawl.tools.checkstyle.checks.j2ee;
|
|||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
|
||||
/**
|
||||
* Checks methods of a remote interface
|
||||
* Checks methods of a remote interface.
|
||||
* @author Rick Giles
|
||||
*/
|
||||
public class RemoteInterfaceMethodChecker
|
||||
|
|
|
|||
|
|
@ -0,0 +1,108 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
// Copyright (C) 2001-2003 Oliver Burn
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.checks.javadoc;
|
||||
|
||||
/**
|
||||
* Used to keep track of a tag and the text that follows it.
|
||||
*
|
||||
* @author Chris Stillwell
|
||||
*/
|
||||
class HtmlTag
|
||||
{
|
||||
/** The maximum length of text to display with this tag. */
|
||||
private static final int MAX_TEXT_LEN = 60;
|
||||
|
||||
/** The HTML tag name. */
|
||||
private final String mId;
|
||||
|
||||
/** The line number in the source file where this tag was found. */
|
||||
private final int mLineNo;
|
||||
|
||||
/** The position within the line where this tag was found. */
|
||||
private final int mPosition;
|
||||
|
||||
/** The comment line of text where this tag appears. */
|
||||
private final String mText;
|
||||
|
||||
/**
|
||||
* Construct the HtmlTag.
|
||||
* @param aId the HTML tag name.
|
||||
* @param aLineNo the source line number of this tag.
|
||||
* @param aPosition the position within the text of this tag.
|
||||
* @param aText the line of comment text for this tag.
|
||||
*/
|
||||
HtmlTag(String aId, int aLineNo, int aPosition, String aText)
|
||||
{
|
||||
mId = (aId.charAt(0) == '/') ? aId.substring(1) : aId;
|
||||
mLineNo = aLineNo;
|
||||
mPosition = aPosition;
|
||||
mText = aText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id (name) of this tag.
|
||||
* @return a String id.
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if this tag is a close (end) tag.
|
||||
* @return <code>true</code> is this is a close tag.
|
||||
*/
|
||||
public boolean isCloseTag()
|
||||
{
|
||||
return (mText.charAt(mPosition + 1) == '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source line number where this tag was found.
|
||||
* Used for displaying a Checkstyle error.
|
||||
* @return an int line number.
|
||||
*/
|
||||
public int getLineno()
|
||||
{
|
||||
return mLineNo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position with in the comment line where this tag
|
||||
* was found. Used for displaying a Checkstyle error.
|
||||
* @return an int relative to zero.
|
||||
*/
|
||||
public int getPosition()
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this HTML tag and trailing text.
|
||||
* Used for displaying a Checkstyle error.
|
||||
* @return the String text of this tag.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
final int startOfText = mPosition;
|
||||
final int endOfText =
|
||||
Math.min(startOfText + HtmlTag.MAX_TEXT_LEN, mText.length());
|
||||
return mText.substring(startOfText, endOfText);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,445 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
// Copyright (C) 2001-2003 Oliver Burn
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.checks.javadoc;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FileContents;
|
||||
import com.puppycrawl.tools.checkstyle.api.Scope;
|
||||
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Stack;
|
||||
import org.apache.regexp.RE;
|
||||
import org.apache.regexp.RESyntaxException;
|
||||
|
||||
/**
|
||||
* <p>Custom Checkstyle Check to validate Javadoc.
|
||||
* The following checks are performed:
|
||||
* <ul>
|
||||
* <li>Ensures the first sentence ends with proper punctuation (That is
|
||||
* a period, question mark, or exclaimation mark). Javadoc automatically
|
||||
* places the first sentence in the method summary table and index. With out
|
||||
* proper punctuation the Javadoc may be malformed.
|
||||
* <li>Check text for incomplete html tags. Verifies that HTML tags have
|
||||
* corresponding end tags and issues an UNCLOSED_HTML error if not.
|
||||
* An EXTRA_HTML error is issued if an end tag is found without a previous
|
||||
* open tag.
|
||||
* </ul>
|
||||
* <p>These checks were patterned after the checks made by the doclet
|
||||
* <code>com.sun.tools.doclets.doccheck.DocCheck</code>
|
||||
*
|
||||
* @author Chris Stillwell
|
||||
* @version 1.1
|
||||
*/
|
||||
public class JavadocStyleCheck
|
||||
extends Check
|
||||
{
|
||||
/** Message property key for the Unclosed HTML message. */
|
||||
private static final String UNCLOSED_HTML = "javadoc.unclosedhtml";
|
||||
|
||||
/** Message property key for the Extra HTML message. */
|
||||
private static final String EXTRA_HTML = "javadoc.extrahtml";
|
||||
|
||||
/** HTML tags that do not require a close tag. */
|
||||
private static final String[] SINGLE_TAG =
|
||||
{"p", "br", "li", "dt", "dd", "td", "hr", "img", "tr", "th", "td"};
|
||||
|
||||
/** The scope to check. */
|
||||
private Scope mScope = Scope.PRIVATE;
|
||||
|
||||
/** Regular expression for matching the end of a sentence. */
|
||||
private RE mEndOfSentenceRE;
|
||||
|
||||
/**
|
||||
* Indicates if the first sentence should be checked for proper end of
|
||||
* sentence punctuation.
|
||||
*/
|
||||
private boolean mCheckFirstSentence = true;
|
||||
|
||||
/**
|
||||
* Indicates if the HTML within the comment should be checked.
|
||||
*/
|
||||
private boolean mCheckHtml = true;
|
||||
|
||||
/**
|
||||
* The default tokens this Check is used for.
|
||||
* @see com.puppycrawl.tools.checkstyle.api.Check#getDefaultTokens()
|
||||
*/
|
||||
public int[] getDefaultTokens()
|
||||
{
|
||||
return new int[] {
|
||||
TokenTypes.INTERFACE_DEF,
|
||||
TokenTypes.CLASS_DEF,
|
||||
TokenTypes.METHOD_DEF,
|
||||
TokenTypes.CTOR_DEF,
|
||||
TokenTypes.VARIABLE_DEF,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to process a token.
|
||||
* @see com.puppycrawl.tools.checkstyle.api.Check
|
||||
*/
|
||||
public void visitToken(DetailAST aAST)
|
||||
{
|
||||
if (!ScopeUtils.inCodeBlock(aAST)) {
|
||||
final DetailAST mods =
|
||||
aAST.findFirstToken(TokenTypes.MODIFIERS);
|
||||
final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
|
||||
final Scope variableScope =
|
||||
ScopeUtils.inInterfaceBlock(aAST)
|
||||
? Scope.PUBLIC
|
||||
: declaredScope;
|
||||
|
||||
if (variableScope.isIn(mScope)) {
|
||||
final Scope surroundingScope =
|
||||
ScopeUtils.getSurroundingScope(aAST);
|
||||
|
||||
if ((surroundingScope == null)
|
||||
|| surroundingScope.isIn(mScope))
|
||||
{
|
||||
final FileContents contents = getFileContents();
|
||||
final String[] cmt =
|
||||
contents.getJavadocBefore(aAST.getLineNo());
|
||||
|
||||
checkComment(aAST, cmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the various checks agains the Javadoc comment.
|
||||
*
|
||||
* @param aAST (Abstract Syntax Tree) the token to process.
|
||||
* @param aComment the source lines that make up the Javadoc comment.
|
||||
*
|
||||
* @see #checkFirstSentence(DetailAST, String[])
|
||||
*/
|
||||
private void checkComment(DetailAST aAST, String[] aComment)
|
||||
{
|
||||
if (aComment == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCheckFirstSentence) {
|
||||
checkFirstSentence(aAST, aComment);
|
||||
}
|
||||
|
||||
if (mCheckHtml) {
|
||||
checkHtml(aAST, aComment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the first sentence ends with proper puctuation. This method
|
||||
* uses a regular expression that checks for the presence of a period,
|
||||
* question mark, or exclaimation mark followed either by whitespace, an
|
||||
* HTML element, or the end of string.
|
||||
*
|
||||
* @param aAST (Abstract Syntax Tree) the token to process.
|
||||
* @param aComment the source lines that make up the Javadoc comment.
|
||||
*/
|
||||
private void checkFirstSentence(DetailAST aAST, String[] aComment)
|
||||
{
|
||||
final String commentText = getCommentText(aComment);
|
||||
|
||||
if ((commentText.length() != 0)
|
||||
&& !getEndOfSentenceRE().match(commentText))
|
||||
{
|
||||
log(aAST.getLineNo() - aComment.length, "javadoc.noperiod");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment text from the Javadoc.
|
||||
* @param aComments the lines of Javadoc.
|
||||
* @return a comment text String.
|
||||
*/
|
||||
private String getCommentText(String[] aComments)
|
||||
{
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
boolean foundTag = false;
|
||||
|
||||
for (int i = 0; i < aComments.length; i++) {
|
||||
String line = aComments[i];
|
||||
final int textStart = findTextStart(line);
|
||||
|
||||
if (textStart != -1) {
|
||||
// Look for Javadoc tag that's not a @link since can appear
|
||||
// within the comment text.
|
||||
final int ndx = line.indexOf('@');
|
||||
if ((ndx != -1)
|
||||
&& !line.regionMatches(ndx + 1, "link", 0, "link".length()))
|
||||
{
|
||||
foundTag = true;
|
||||
line = line.substring(0, ndx);
|
||||
}
|
||||
|
||||
buffer.append(line.substring(textStart));
|
||||
trimTail(buffer);
|
||||
buffer.append('\n');
|
||||
|
||||
if (foundTag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the index of the first non-whitespace character ignoring the
|
||||
* Javadoc comment start and end strings (/** and */) as well as any
|
||||
* leading asterisk.
|
||||
* @param aLine the Javadoc comment line of text to scan.
|
||||
* @return the int index relative to 0 for the start of text
|
||||
* or -1 if not found.
|
||||
*/
|
||||
private int findTextStart(String aLine)
|
||||
{
|
||||
int textStart = -1;
|
||||
for (int i = 0; i < aLine.length(); i++) {
|
||||
if (!Character.isWhitespace(aLine.charAt(i))) {
|
||||
if (aLine.regionMatches(i, "/**", 0, 3)) {
|
||||
i += 2;
|
||||
}
|
||||
else if (aLine.regionMatches(i, "*/", 0, 2)) {
|
||||
i++;
|
||||
}
|
||||
else if (aLine.charAt(i) != '*') {
|
||||
textStart = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return textStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims any trailing whitespace or the end of Javadoc comment string.
|
||||
* @param aBuffer the StringBuffer to trim.
|
||||
*/
|
||||
private void trimTail(StringBuffer aBuffer)
|
||||
{
|
||||
for (int i = aBuffer.length() - 1; i >= 0; i--) {
|
||||
if (Character.isWhitespace(aBuffer.charAt(i))) {
|
||||
aBuffer.deleteCharAt(i);
|
||||
}
|
||||
else if ((i > 0)
|
||||
&& (aBuffer.charAt(i - 1) == '*')
|
||||
&& (aBuffer.charAt(i) == '/'))
|
||||
{
|
||||
aBuffer.deleteCharAt(i);
|
||||
aBuffer.deleteCharAt(i - 1);
|
||||
i--;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the comment for HTML tags that do not have a corresponding close
|
||||
* tag or a close tage that has no previous open tag. This code was
|
||||
* primarily copied from the DocCheck checkHtml method.
|
||||
*
|
||||
* @param aAST (Abstract Syntax Tree) the token to process.
|
||||
* @param aComment the source lines that make up the Javadoc comment.
|
||||
*/
|
||||
private void checkHtml(DetailAST aAST, String[] aComment)
|
||||
{
|
||||
final int lineno = aAST.getLineNo() - aComment.length;
|
||||
final Stack htmlStack = new Stack();
|
||||
|
||||
for (int i = 0; i < aComment.length; i++) {
|
||||
final TagParser parser = new TagParser(aComment[i], lineno + i);
|
||||
while (parser.hasNextTag()) {
|
||||
final HtmlTag tag = parser.nextTag();
|
||||
|
||||
if (!tag.isCloseTag()) {
|
||||
htmlStack.push(tag);
|
||||
}
|
||||
else {
|
||||
// We have found a close tag.
|
||||
if (isExtraHtml(tag.getId(), htmlStack)) {
|
||||
// No corresponding open tag was found on the stack.
|
||||
log(tag.getLineno(),
|
||||
tag.getPosition(),
|
||||
EXTRA_HTML,
|
||||
tag);
|
||||
}
|
||||
else {
|
||||
// See if there are any unclosed tags that were opened
|
||||
// after this one.
|
||||
checkUnclosedTags(htmlStack, tag.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Identify any tags left on the stack.
|
||||
String lastFound = ""; // Skip multiples, like <b>...<b>
|
||||
for (int i = 0; i < htmlStack.size(); i++) {
|
||||
final HtmlTag htag = (HtmlTag) htmlStack.elementAt(i);
|
||||
if (!isSingleTag(htag) && !htag.getId().equals(lastFound)) {
|
||||
log(htag.getLineno(), htag.getPosition(), UNCLOSED_HTML, htag);
|
||||
lastFound = htag.getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if there are any unclosed tags on the stack. The token
|
||||
* represents a html tag that has been closed and has a corresponding open
|
||||
* tag on the stack. Any tags, except single tags, that were opened
|
||||
* (pushed on the stack) after the token are missing a close.
|
||||
*
|
||||
* @param aHtmlStack the stack of opened HTML tags.
|
||||
* @param aToken the current HTML tag name that has been closed.
|
||||
*/
|
||||
private void checkUnclosedTags(Stack aHtmlStack, String aToken)
|
||||
{
|
||||
final Stack unclosedTags = new Stack();
|
||||
HtmlTag lastOpenTag = (HtmlTag) aHtmlStack.pop();
|
||||
while (!aToken.equalsIgnoreCase(lastOpenTag.getId())) {
|
||||
// Find unclosed elements. Put them on a stack so the
|
||||
// output order won't be back-to-front.
|
||||
if (isSingleTag(lastOpenTag)) {
|
||||
lastOpenTag = (HtmlTag) aHtmlStack.pop();
|
||||
}
|
||||
else {
|
||||
unclosedTags.push(lastOpenTag);
|
||||
lastOpenTag = (HtmlTag) aHtmlStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
// Output the unterminated tags, if any
|
||||
String lastFound = ""; // Skip multiples, like <b>..<b>
|
||||
for (int i = 0; i < unclosedTags.size(); i++) {
|
||||
lastOpenTag = (HtmlTag) unclosedTags.get(i);
|
||||
if (lastOpenTag.getId().equals(lastFound)) {
|
||||
continue;
|
||||
}
|
||||
lastFound = lastOpenTag.getId();
|
||||
log(lastOpenTag.getLineno(),
|
||||
lastOpenTag.getPosition(),
|
||||
UNCLOSED_HTML,
|
||||
lastOpenTag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the HtmlTag is one which does not require a close tag.
|
||||
*
|
||||
* @param aTag the HtmlTag to check.
|
||||
* @return <code>true</code> if the HtmlTag is a single tag.
|
||||
*/
|
||||
private boolean isSingleTag(HtmlTag aTag)
|
||||
{
|
||||
boolean isSingleTag = false;
|
||||
for (int i = 0; i < SINGLE_TAG.length; i++) {
|
||||
// If its a singleton tag (<p>, <br>, etc.), ignore it
|
||||
// Can't simply not put them on the stack, since singletons
|
||||
// like <dt> and <dd> (unhappily) may either be terminated
|
||||
// or not terminated. Both options are legal.
|
||||
if (aTag.getId().equalsIgnoreCase(SINGLE_TAG[i])) {
|
||||
isSingleTag = true;
|
||||
}
|
||||
}
|
||||
return isSingleTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given token is an extra HTML tag. This indicates that
|
||||
* a close tag was found that does not have a corresponding open tag.
|
||||
*
|
||||
* @param aToken an HTML tag id for which a close was found.
|
||||
* @param aHtmlStack a Stack of previous open HTML tags.
|
||||
* @return <code>false</code> if a previous open tag was found
|
||||
* for the token.
|
||||
*/
|
||||
private boolean isExtraHtml(String aToken, Stack aHtmlStack)
|
||||
{
|
||||
boolean isExtra = true;
|
||||
for (int i = 0; i < aHtmlStack.size(); i++) {
|
||||
// Loop, looking for tags that are closed.
|
||||
// The loop is needed in case there are unclosed
|
||||
// tags on the stack. In that case, the stack would
|
||||
// not be empty, but this tag would still be extra.
|
||||
HtmlTag td = (HtmlTag) aHtmlStack.elementAt(i);
|
||||
if (aToken.equalsIgnoreCase(td.getId())) {
|
||||
isExtra = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isExtra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scope to check.
|
||||
* @param aFrom string to get the scope from
|
||||
*/
|
||||
public void setScope(String aFrom)
|
||||
{
|
||||
mScope = Scope.getInstance(aFrom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a regular expression for matching the end of a sentence.
|
||||
*
|
||||
* @return a regular expression for matching the end of a sentence.
|
||||
*/
|
||||
private RE getEndOfSentenceRE()
|
||||
{
|
||||
if (mEndOfSentenceRE == null) {
|
||||
try {
|
||||
mEndOfSentenceRE = new RE("([.?!][ \t\n\r\f<])|([.?!]$)");
|
||||
}
|
||||
catch (RESyntaxException e) {
|
||||
// This should never occur.
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mEndOfSentenceRE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag that determines if the first sentence is checked for
|
||||
* proper end of sentence punctuation.
|
||||
* @param aFlag <code>true</code> if the first sentence is to be checked
|
||||
*/
|
||||
public void setCheckFirstSentence(boolean aFlag)
|
||||
{
|
||||
mCheckFirstSentence = aFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag that determines if HTML checking is to be performed.
|
||||
* @param aFlag <code>true</code> if HTML checking is to be performed.
|
||||
*/
|
||||
public void setCheckHtml(boolean aFlag)
|
||||
{
|
||||
mCheckHtml = aFlag;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
|||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Checks that a variable has Javadoc comment.
|
||||
* The scope to verify is specified using the {@link Scope} class and
|
||||
* defaults to {@link Scope#PRIVATE}. To verify another scope,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,117 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
// Copyright (C) 2001-2003 Oliver Burn
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.checks.javadoc;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
||||
/**
|
||||
* Helper class used to parse HTML tags from a single line of text.
|
||||
* Just the beginning of the HTML tag is located. No attempt is made to
|
||||
* parse out the complete tag, particularly since some of the tag
|
||||
* parameters could be located on the following line of text. The
|
||||
* <code>hasNextTag</code> and <code>nextTag</code> methods are used
|
||||
* to iterate through the HTML tags that were found on the line of text.
|
||||
*
|
||||
* @author Chris Stillwell
|
||||
*/
|
||||
class TagParser
|
||||
{
|
||||
/** List of HtmlTags found on the input line of text. */
|
||||
private final List mTags = new LinkedList();
|
||||
|
||||
/**
|
||||
* Constructs a TagParser and finds the first tag if any.
|
||||
* @param aText the line of text to parse.
|
||||
* @param aLineNo the source line number.
|
||||
*/
|
||||
public TagParser(String aText, int aLineNo)
|
||||
{
|
||||
parseTags(aText, aLineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next available HtmlTag.
|
||||
* @return a HtmlTag or <code>null</code> if none available.
|
||||
* @throws IndexOutOfBoundsException if there are no HtmlTags
|
||||
* left to return.
|
||||
*/
|
||||
public HtmlTag nextTag()
|
||||
{
|
||||
return (HtmlTag) mTags.remove(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if there are any more HtmlTag to retrieve.
|
||||
* @return <code>true</code> if there are more tags.
|
||||
*/
|
||||
public boolean hasNextTag()
|
||||
{
|
||||
return (mTags.size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs lazy initialization on the internal tags List
|
||||
* and adds the tag.
|
||||
* @param aTag the HtmlTag to add.
|
||||
*/
|
||||
private void add(HtmlTag aTag)
|
||||
{
|
||||
mTags.add(aTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the text line for any HTML tags and adds them to the internal
|
||||
* List of tags.
|
||||
* @param aText the source line to parse.
|
||||
* @param aLineNo the source line number.
|
||||
*/
|
||||
private void parseTags(String aText, int aLineNo)
|
||||
{
|
||||
int position = 0;
|
||||
final StringTokenizer tokenizer =
|
||||
new StringTokenizer(aText, " \t\n\r\f<>", true);
|
||||
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String token = tokenizer.nextToken();
|
||||
position += token.length();
|
||||
|
||||
if (token.equals("<")) {
|
||||
token = tokenizer.nextToken();
|
||||
position += token.length();
|
||||
|
||||
if (((token.charAt(0) >= 'A')
|
||||
&& (token.charAt(0) <= 'Z'))
|
||||
|| ((token.charAt(0) >= 'a')
|
||||
&& (token.charAt(0) <= 'z'))
|
||||
|| (token.charAt(0) == '/'))
|
||||
{
|
||||
// If a character or / follows the < sign,
|
||||
// then assume its html.
|
||||
// The non-html version is "<"
|
||||
// Point before the angle bracket
|
||||
final int startOfTag = position - token.length() - 1;
|
||||
add(new HtmlTag(token, aLineNo, startOfTag, aText));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,14 @@
|
|||
javadoc.missing=Missing a Javadoc comment.
|
||||
javadoc.unusedTagGeneral=Unused Javadoc tag.
|
||||
javadoc.unusedTag=Unused {0} tag for ''{1}''.
|
||||
javadoc.classInfo=Unable to get class information for {0} tag ''{1}''.
|
||||
javadoc.expectedTag=Expected {0} tag for ''{1}''.
|
||||
javadoc.extrahtml=Extra HTML tag found: {0}
|
||||
javadoc.missing=Missing a Javadoc comment.
|
||||
javadoc.noperiod=First sentence should end with a period.
|
||||
javadoc.packageHtml=Missing package documentation file.
|
||||
javadoc.return.duplicate=Duplicate @return tag.
|
||||
javadoc.return.expected=Expected an @return tag.
|
||||
javadoc.classInfo=Unable to get class information for {0} tag ''{1}''.
|
||||
javadoc.packageHtml=Missing package documentation file.
|
||||
javadoc.unclosedhtml=Unclosed HTML tag found: {0}
|
||||
javadoc.unusedTag=Unused {0} tag for ''{1}''.
|
||||
javadoc.unusedTagGeneral=Unused Javadoc tag.
|
||||
|
||||
type.missingTag=Type Javadoc comment is missing an {0} tag.
|
||||
type.tagFormat=Type Javadoc tag {0} must match pattern ''{1}''.
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class CyclomaticComplexityCheck
|
|||
/** default allowed complexity */
|
||||
private static final int DEFAULT_VALUE = 10;
|
||||
|
||||
/** Create an instance */
|
||||
/** Create an instance. */
|
||||
public CyclomaticComplexityCheck()
|
||||
{
|
||||
super(DEFAULT_VALUE);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
|
|||
* and defaults to
|
||||
* <strong>^[a-z]+(\.[a-zA-Z_][a-zA-Z_0-9]*)*$</strong>.
|
||||
* </p>
|
||||
* <p>
|
||||
* The default format has been chosen to match the requirements in the
|
||||
* <a
|
||||
* href="http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html#40169">
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* <module name="ParameterName">
|
||||
* <property name="format" value="^^[a-z](_?[a-zA-Z0-9]+)*$"/>
|
||||
* </module>
|
||||
|
||||
* </pre>
|
||||
*
|
||||
* @author Oliver Burn
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class ParameterNumberCheck
|
|||
private int mMax = DEFAULT_MAX_PARAMETERS;
|
||||
|
||||
/**
|
||||
* Sets the maximum number of allowed parameters
|
||||
* Sets the maximum number of allowed parameters.
|
||||
* @param aMax the max allowed parameters
|
||||
*/
|
||||
public void setMax(int aMax)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
|||
* of this check.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* An example of how to configure the check is:
|
||||
* </p>
|
||||
* <pre>
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ public final class OperatorWrapOption
|
|||
/** maps from a string representation to an option */
|
||||
private static final Map STR_TO_OPT = new HashMap();
|
||||
|
||||
/** require that the operator is on a new line **/
|
||||
/** Require that the operator is on a new line. */
|
||||
public static final OperatorWrapOption NL = new OperatorWrapOption("nl");
|
||||
/** require that the operator is at the end of the line **/
|
||||
/** Require that the operator is at the end of the line. */
|
||||
public static final OperatorWrapOption EOL = new OperatorWrapOption("eol");
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Test case file for checkstyle.
|
||||
// Created: 2003
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package com.puppycrawl.tools.checkstyle;
|
||||
|
||||
/**
|
||||
* Test input for the JavadocStyleCheck. This check is used to perform
|
||||
* some additional Javadoc validations.
|
||||
*
|
||||
* @author Chris Stillwell
|
||||
* @version 1.0
|
||||
*/
|
||||
public class InputJavadocStyleCheck
|
||||
{
|
||||
// This is OK. We don't flag missing javadoc. That's left for other checks.
|
||||
private String first;
|
||||
|
||||
/** This Javadoc is missing an ending period */
|
||||
private String second;
|
||||
|
||||
/**
|
||||
* We don't want {@link com.puppycrawl.tools.checkstyle.checks.JavadocStyleCheck}
|
||||
* tags to stop the scan for the end of sentence.
|
||||
* @see Somthing
|
||||
*/
|
||||
public InputJavadocStyleCheck()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This is ok!
|
||||
*/
|
||||
private void method1()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This is ok?
|
||||
*/
|
||||
private void method2()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* And This is ok.<br>
|
||||
*/
|
||||
private void method3()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This should fail even.though.there are embedded periods
|
||||
*/
|
||||
private void method4()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test HTML in Javadoc comment
|
||||
* <dl>
|
||||
* <dt><b>This guy is missing end of bold tag
|
||||
* <dd>The dt and dd don't require end tags.
|
||||
* </dl>
|
||||
* </td>Extra tag shouldn't be here
|
||||
*
|
||||
* @param arg1 <code>dummy.
|
||||
*/
|
||||
private void method5(int arg1)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected check <b>should fail
|
||||
*/
|
||||
protected void method6()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Package protected check <b>should fail
|
||||
*/
|
||||
void method7()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Public check should fail</code>
|
||||
*/
|
||||
public void method8()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -60,6 +60,7 @@ import com.puppycrawl.tools.checkstyle.checks.j2ee.SessionBeanCheckTest;
|
|||
import com.puppycrawl.tools.checkstyle.checks.j2ee.ThisParameterCheckTest;
|
||||
import com.puppycrawl.tools.checkstyle.checks.j2ee.ThisReturnCheckTest;
|
||||
import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheckTest;
|
||||
import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheckTest;
|
||||
import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheckTest;
|
||||
import com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheckTest;
|
||||
import com.puppycrawl.tools.checkstyle.checks.javadoc.PackageHtmlCheckTest;
|
||||
|
|
@ -142,6 +143,7 @@ public class AllTests {
|
|||
suite.addTest(new TestSuite(InnerAssignmentCheckTest.class));
|
||||
suite.addTest(new TestSuite(InterfaceIsTypeCheckTest.class));
|
||||
suite.addTest(new TestSuite(JavadocMethodCheckTest.class));
|
||||
suite.addTest(new TestSuite(JavadocStyleCheckTest.class));
|
||||
suite.addTest(new TestSuite(JavadocTypeCheckTest.class));
|
||||
suite.addTest(new TestSuite(JavadocVariableCheckTest.class));
|
||||
suite.addTest(new TestSuite(LineLengthCheckTest.class));
|
||||
|
|
|
|||
|
|
@ -49,14 +49,13 @@ public class SuppressionsLoaderTest extends TestCase
|
|||
public void testNoFile()
|
||||
throws CheckstyleException
|
||||
{
|
||||
try
|
||||
{
|
||||
final FilterChain fc =
|
||||
SuppressionsLoader.loadSuppressions(
|
||||
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_file.xml");
|
||||
try {
|
||||
SuppressionsLoader.loadSuppressions(
|
||||
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_file.xml");
|
||||
}
|
||||
catch (CheckstyleException ex) {
|
||||
assertEquals("unable to parse src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_file.xml - Attribute \"files\" is required and must be specified for element type \"suppress\".",
|
||||
assertEquals(
|
||||
"unable to parse src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_file.xml - Attribute \"files\" is required and must be specified for element type \"suppress\".",
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -64,14 +63,13 @@ public class SuppressionsLoaderTest extends TestCase
|
|||
public void testNoCheck()
|
||||
throws CheckstyleException
|
||||
{
|
||||
try
|
||||
{
|
||||
final FilterChain fc =
|
||||
SuppressionsLoader.loadSuppressions(
|
||||
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_check.xml");
|
||||
try {
|
||||
SuppressionsLoader.loadSuppressions(
|
||||
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_check.xml");
|
||||
}
|
||||
catch (CheckstyleException ex) {
|
||||
assertEquals("unable to parse src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_check.xml - Attribute \"checks\" is required and must be specified for element type \"suppress\".",
|
||||
assertEquals(
|
||||
"unable to parse src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_no_check.xml - Attribute \"checks\" is required and must be specified for element type \"suppress\".",
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
@ -79,14 +77,13 @@ public class SuppressionsLoaderTest extends TestCase
|
|||
public void testBadInt()
|
||||
throws CheckstyleException
|
||||
{
|
||||
try
|
||||
{
|
||||
final FilterChain fc =
|
||||
SuppressionsLoader.loadSuppressions(
|
||||
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_bad_int.xml");
|
||||
try {
|
||||
SuppressionsLoader.loadSuppressions(
|
||||
"src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_bad_int.xml");
|
||||
}
|
||||
catch (CheckstyleException ex) {
|
||||
assertEquals("number format exception src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_bad_int.xml - For input string: \"a\"",
|
||||
assertEquals(
|
||||
"number format exception src/testinputs/com/puppycrawl/tools/checkstyle/suppressions_bad_int.xml - For input string: \"a\"",
|
||||
ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.javadoc;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
|
||||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
|
||||
|
||||
|
||||
public class JavadocStyleCheckTest
|
||||
extends BaseCheckTestCase
|
||||
{
|
||||
public void testDefaultSettings()
|
||||
throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(JavadocStyleCheck.class);
|
||||
final String[] expected =
|
||||
{
|
||||
"20: First sentence should end with a period.",
|
||||
"53: First sentence should end with a period.",
|
||||
"63:11: Unclosed HTML tag found: <b>This guy is missing end of bold tag",
|
||||
"66:7: Extra HTML tag found: </td>Extra tag shouldn't be here",
|
||||
"68:19: Unclosed HTML tag found: <code>dummy.",
|
||||
"74: First sentence should end with a period.",
|
||||
"75:23: Unclosed HTML tag found: <b>should fail",
|
||||
"81: First sentence should end with a period.",
|
||||
"82:31: Unclosed HTML tag found: <b>should fail",
|
||||
"88: First sentence should end with a period.",
|
||||
"89:31: Extra HTML tag found: </code>"
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
|
||||
}
|
||||
|
||||
public void testFirstSentence() throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(JavadocStyleCheck.class);
|
||||
checkConfig.addAttribute("checkFirstSentence", "true");
|
||||
checkConfig.addAttribute("checkHtml", "false");
|
||||
final String[] expected =
|
||||
{
|
||||
"20: First sentence should end with a period.",
|
||||
"53: First sentence should end with a period.",
|
||||
"74: First sentence should end with a period.",
|
||||
"81: First sentence should end with a period.",
|
||||
"88: First sentence should end with a period.",
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
|
||||
}
|
||||
|
||||
public void testHtml() throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(JavadocStyleCheck.class);
|
||||
checkConfig.addAttribute("checkFirstSentence", "false");
|
||||
checkConfig.addAttribute("checkHtml", "true");
|
||||
final String[] expected =
|
||||
{
|
||||
"63:11: Unclosed HTML tag found: <b>This guy is missing end of bold tag",
|
||||
"66:7: Extra HTML tag found: </td>Extra tag shouldn't be here",
|
||||
"68:19: Unclosed HTML tag found: <code>dummy.",
|
||||
"75:23: Unclosed HTML tag found: <b>should fail",
|
||||
"82:31: Unclosed HTML tag found: <b>should fail",
|
||||
"89:31: Extra HTML tag found: </code>"
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
|
||||
}
|
||||
|
||||
public void testScopePublic()
|
||||
throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(JavadocStyleCheck.class);
|
||||
checkConfig.addAttribute("checkFirstSentence", "true");
|
||||
checkConfig.addAttribute("checkHtml", "true");
|
||||
checkConfig.addAttribute("scope", "public");
|
||||
final String[] expected =
|
||||
{
|
||||
"88: First sentence should end with a period.",
|
||||
"89:31: Extra HTML tag found: </code>"
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
|
||||
}
|
||||
|
||||
public void testScopeProtected()
|
||||
throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(JavadocStyleCheck.class);
|
||||
checkConfig.addAttribute("checkFirstSentence", "true");
|
||||
checkConfig.addAttribute("checkHtml", "true");
|
||||
checkConfig.addAttribute("scope", "protected");
|
||||
final String[] expected =
|
||||
{
|
||||
"74: First sentence should end with a period.",
|
||||
"75:23: Unclosed HTML tag found: <b>should fail",
|
||||
"88: First sentence should end with a period.",
|
||||
"89:31: Extra HTML tag found: </code>"
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
|
||||
}
|
||||
|
||||
public void testScopePackage()
|
||||
throws Exception
|
||||
{
|
||||
final DefaultConfiguration checkConfig =
|
||||
createCheckConfig(JavadocStyleCheck.class);
|
||||
checkConfig.addAttribute("checkFirstSentence", "true");
|
||||
checkConfig.addAttribute("checkHtml", "true");
|
||||
checkConfig.addAttribute("scope", "package");
|
||||
final String[] expected =
|
||||
{
|
||||
"74: First sentence should end with a period.",
|
||||
"75:23: Unclosed HTML tag found: <b>should fail",
|
||||
"81: First sentence should end with a period.",
|
||||
"82:31: Unclosed HTML tag found: <b>should fail",
|
||||
"88: First sentence should end with a period.",
|
||||
"89:31: Extra HTML tag found: </code>"
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("InputJavadocStyleCheck.java"), expected);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue