Added multiLines property for RegexpHeaderCheck. Added AbstractHeaderCheck - superclass for header checks.
This commit is contained in:
parent
0340dcb26d
commit
d298d68e67
|
|
@ -112,18 +112,29 @@ line 5: ////////////////////////////////////////////////////////////////////
|
|||
For example, consider the following header file:
|
||||
</p>
|
||||
<pre class="body">
|
||||
line 1: /{71}
|
||||
line 2: // checkstyle:
|
||||
line 3: // Checks Java source code for adherence to a set of rules\.
|
||||
line 4: // Copyright \(C\) \d\d\d\d Oliver Burn
|
||||
line 5: // Last modification by \$Author.*\$
|
||||
line 6: /{71}
|
||||
line 1: ^/{71}$
|
||||
line 2: ^// checkstyle:$
|
||||
line 3: ^// Checks Java source code for adherence to a set of rules\.$
|
||||
line 4: ^// Copyright \(C\) \d\d\d\d Oliver Burn$
|
||||
line 5: ^// Last modification by \$Author.*\$$
|
||||
line 6: ^/{71}$
|
||||
line 7:
|
||||
line 8: ^package
|
||||
line 9:
|
||||
line 10: ^import
|
||||
line 11:
|
||||
line 12: ^/\*\*
|
||||
line 13: ^ \*([^/]|$)
|
||||
line 14: ^ \*/
|
||||
</pre>
|
||||
|
||||
<p class="body">
|
||||
Lines 1 and 6 demonstrate a more compact notation for 71 '/' 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.
|
||||
Lines 1 and 6 demonstrate a more compact notation for 71 '/'
|
||||
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. Lines 12-14 is a template for
|
||||
javadoc (line 13 is so complecated to remove conflict with
|
||||
and of javadoc comment).
|
||||
</p>
|
||||
<h4>Properties</h4>
|
||||
<table width="100%" border="1" cellpadding="5" class="body">
|
||||
|
|
@ -140,8 +151,8 @@ line 6: /{71}
|
|||
<td><span class="default">null</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ignoreLines</td>
|
||||
<td>line numbers to ignore</td>
|
||||
<td>multiLines</td>
|
||||
<td>line numbers to repeat (zero or more times)</td>
|
||||
<td><a href="property_types.html#intSet">list of integers</a></td>
|
||||
<td><span class="default">{}</span></td>
|
||||
</tr>
|
||||
|
|
@ -149,16 +160,22 @@ line 6: /{71}
|
|||
|
||||
<h4>Example</h4>
|
||||
<p class="body">
|
||||
To configure the check to use header file <span class="code">"java.header"</span>
|
||||
and ignore lines <span class="code">2</span>, <span class="code">3</span>, and <span class="code">
|
||||
4</span>:
|
||||
To configure the check to use header file <span
|
||||
class="code">"java.header"</span> and <span
|
||||
class="code">10</span> and <span class="code">13</span>
|
||||
muli-lines:
|
||||
</p>
|
||||
<pre class="body">
|
||||
<module name="RegexpHeader">
|
||||
<property name="headerFile" value="java.header"/>
|
||||
<property name="ignoreLines" value="2, 3, 4"/>
|
||||
<property name="multiLines" value="10, 13"/>
|
||||
</module>
|
||||
</pre>
|
||||
<p class="body">
|
||||
<u>Note</u>: <span class="code">ignoreLines</span> property has been
|
||||
removed from this check to simplify it. To make some line
|
||||
optional use "^.*$" regexp for this line.
|
||||
</p>
|
||||
<h4>Package</h4>
|
||||
<p class="body">
|
||||
com.puppycrawl.tools.checkstyle.checks
|
||||
|
|
@ -177,4 +194,4 @@ Copyright © 2002-2003 Oliver Burn. All rights Reserved.
|
|||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -107,6 +107,9 @@
|
|||
(module RequireThis, contributed by Stephen Bloch, requests
|
||||
755550, 696295).</li>
|
||||
|
||||
<li class="body">Added multiLines property to regexpCheck
|
||||
(request 597676)</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p class="body">
|
||||
|
|
@ -126,6 +129,15 @@
|
|||
|
||||
</ul>
|
||||
|
||||
<p class="body">
|
||||
Removed features:
|
||||
</p>
|
||||
<ul>
|
||||
<li class="body">Removed ignoreLines property of
|
||||
RegexpHeader check. To make some line optional use
|
||||
"^.*$" regexp for this line.</li>
|
||||
</ul>
|
||||
|
||||
<a name="release3_3"></a>
|
||||
<h2>Release 3.3</h2>
|
||||
<p class="body">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
|
||||
/**
|
||||
* Abstract super class for header checks.
|
||||
* Provides support for headerFile property.
|
||||
* @author o_sukhosolsky
|
||||
*/
|
||||
public abstract class AbstractHeaderCheck extends Check
|
||||
{
|
||||
/** empty array to avoid instantiations. */
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
|
||||
/** the lines of the header file. */
|
||||
private String[] mHeaderLines;
|
||||
|
||||
/**
|
||||
* Return the header lines to check against.
|
||||
* @return the header lines to check against.
|
||||
*/
|
||||
protected String[] getHeaderLines()
|
||||
{
|
||||
return mHeaderLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the header file to check against.
|
||||
* @param aFileName the file that contains the header to check against.
|
||||
* @throws ConversionException if the file cannot be loaded
|
||||
*/
|
||||
public void setHeaderFile(String aFileName)
|
||||
throws ConversionException
|
||||
{
|
||||
// Handle empty param
|
||||
if ((aFileName == null) || (aFileName.trim().length() == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// load the file
|
||||
try {
|
||||
final LineNumberReader lnr =
|
||||
new LineNumberReader(new FileReader(aFileName));
|
||||
final ArrayList lines = new ArrayList();
|
||||
while (true) {
|
||||
final String l = lnr.readLine();
|
||||
if (l == null) {
|
||||
break;
|
||||
}
|
||||
lines.add(l);
|
||||
}
|
||||
mHeaderLines = (String[]) lines.toArray(new String[0]);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new ConversionException(
|
||||
"unable to load header file " + aFileName, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that required args were specified.
|
||||
* @see com.puppycrawl.tools.checkstyle.api.AutomaticBean#finishLocalSetup
|
||||
*/
|
||||
protected final void finishLocalSetup() throws CheckstyleException
|
||||
{
|
||||
if (mHeaderLines == null) {
|
||||
throw new CheckstyleException(
|
||||
"property 'headerFile' is missing or invalid in module "
|
||||
+ getConfiguration().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public final int[] getDefaultTokens()
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package blah;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Some doc.
|
||||
*/
|
||||
|
||||
public class InputRegexpHeader1
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package blah;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* blah blah
|
||||
* @see foo
|
||||
*/
|
||||
public class InputRegexpHeader2
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package blah;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class InputRegexpHeader3
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package blah;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.*;
|
||||
import java.awt.*;
|
||||
import java.awt.*;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package blah;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public class InputRegexpSmallHeader {}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
^/*$
|
||||
// .*
|
||||
^.*$
|
||||
^.*$
|
||||
^.*$
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
^package
|
||||
^$
|
||||
^import
|
||||
^$
|
||||
^/\*\*
|
||||
^ \*([^/]|$)
|
||||
^ \*/
|
||||
Loading…
Reference in New Issue