Added check to ensure that long integer literals use L, not l. Also fixed bug

by my over zealous removal of toString() methods.
This commit is contained in:
Oliver Burn 2002-06-06 11:45:40 +00:00
parent 4018efa9fe
commit 3da466b9bf
16 changed files with 99 additions and 5 deletions

View File

@ -251,6 +251,11 @@ This task is included in the checkstyle distribution.</p>
<td valign="top">Specifies whether to ignore checking braces. Defaults to <span class="default">&quot;false&quot;</span>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">ignoreLongEll</td>
<td valign="top">Specifies whether to ignore checking the <span class="code">L</span> in long integer literals. Defaults to <span class="default">&quot;false&quot;</span>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">ignorePublicInInterface</td>
<td valign="top">Specifies whether to ignore the public keyword in interface definitions. Defaults to <span class="default">&quot;false&quot;</span>.</td>

View File

@ -208,6 +208,10 @@ This command line tool is included in the checkstyle distribution.</p>
<td valign="top">checkstyle.ignore.braces</td>
<td valign="top">Specifies whether to ignore checking braces. Defaults to <span class="default">&quot;no&quot;</span>.</td>
</tr>
<tr>
<td valign="top">checkstyle.ignore.longell</td>
<td valign="top">Specifies whether to ignore checking the <span class="code">L</span> in long integer literals. Defaults to <span class="default">&quot;false&quot;</span>.</td>
</tr>
<tr>
<td valign="top">checkstyle.ignore.public.in.interface</td>
<td valign="top">Specifies whether to ignore the public keyword in interface definitions. Defaults to <span class="default">&quot;no&quot;</span>.</td>

View File

@ -272,6 +272,10 @@
<p>Verifies that the format of local variables conform to a specified regular expression. The default is <span class="code">^[a-z][a-zA-Z0-9]*$</span>.</p>
<h3>Integer Literals</h3>
<p>Verifies that long integer literals use an uppercase <span class="code">L</span>. For example <span class="code">40L</span> instead of <span class="code">40l</span>. This is in accordance to the Java Language Specification, <a href="http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#48282">Section 3.10.1</a>. This check can be turned off.</p>
<h3>Modifiers</h3>
<p>Checks that the order of modifiers conforms to the suggestions in the <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html">Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3</a>. The correct order is <span class="code">public protected private abstract static final transient volatile synchronized native strictfp</span>.</p>

View File

@ -87,6 +87,10 @@
<li class="body">Unused or duplicate <span class="code">import</span> statements.</li>
<li class="body">Javadoc comments are defined for class, interface, variable and method declarations. Note: This can be made to check only <span class="code">public</span> and <span class="code">protected</span> declarations.</li>
<li class="body">Javadoc tags for a method match the actual code.</li>
<li class="body">Detect instantiations of classes that should not be instantiated (e.g. java.lang.Boolean).</li>
<li class="body">Content of <span class="code">try</span>, <span class="code">catch</span> and <span class="code">finally</span> blocks.</li>
<li class="body">Enforce line wrapping on operators.</li>
<li class="body">Presence of to-do comments.</li>
<li class="body">The <span class="code">package.html</span> package documentation file is available.</li>
<li class="body">The file starts with a specified header. This is useful to ensure that a file has a copyright notice.</li>
<li class="body">An <span class="code">@author</span> tag exists for class and interface Javadoc comments.</li>
@ -105,6 +109,7 @@
<li class="body">Lines are not longer than a specified length.</li>
<li class="body">Methods/Constructors are not longer than a specified number of lines.</li>
<li class="body">Files are not longer than a specified number of lines.</li>
<li class="body">Long integer literals use an uppercase <span class="code">L</span>. For example <span class="code">40L</span> instead of <span class="code">40l</span>.</li>
</ul>
<a name="download"></a>

View File

@ -47,6 +47,7 @@
<li class="body">Detect empty <span class="code">catch</span> blocks (request 516255).</li>
<li class="body">Detect empty <span class="code">finally</span> blocks.</li>
<li class="body">Detect to-do comments (request 504275).</li>
<li class="body">Detect use of lowercase l ("ell") in long integer literals.</li>
<li class="body">Include column number in the XML output (request 555262).</li>
</ul>
</p>

View File

@ -65,6 +65,12 @@ public final class BlockOption implements Serializable
return (BlockOption) STR_TO_OPT.get(aStrRep.trim().toLowerCase());
}
/** @see Object **/
public String toString()
{
return mStrRep;
}
/**
* Ensures that we don't get multiple instances of one BlockOption
* during deserialization. See Section 3.6 of the Java Object

View File

@ -597,6 +597,18 @@ public class CheckStyleTask
});
}
/** @param aIgnore whether to ignore long 'L' **/
public void setIgnoreLongEll(final boolean aIgnore)
{
mOptionMemory.add(new Runnable()
{
public void run()
{
mConfig.setIgnoreLongEll(aIgnore);
}
});
}
/** @param aIgnore whether to ignore 'public' in interfaces **/
public void setIgnorePublicInInterface(final boolean aIgnore)
{

View File

@ -166,6 +166,8 @@ public class Configuration
private boolean mIgnoreOpWrap = false;
/** whether to ignore braces **/
private boolean mIgnoreBraces = false;
/** whether to ignore long 'L' **/
private boolean mIgnoreLongEll = false;
/** whether to ignore 'public' keyword in interface definitions **/
private boolean mIgnorePublicInInterface = false;
/** name of the cache file **/
@ -274,6 +276,9 @@ public class Configuration
setIgnoreBraces(getBooleanProperty(aProps,
IGNORE_BRACES_PROP,
mIgnoreBraces));
setIgnoreLongEll(getBooleanProperty(aProps,
IGNORE_LONG_ELL_PROP,
mIgnoreLongEll));
setIgnorePublicInInterface(getBooleanProperty(
aProps, IGNORE_PUBLIC_IN_INTERFACE_PROP, mIgnorePublicInInterface));
setCacheFile(aProps.getProperty(CACHE_FILE_PROP));
@ -610,6 +615,12 @@ public class Configuration
return mIgnoreBraces;
}
/** @return whether to ignore long 'L' **/
public boolean isIgnoreLongEll()
{
return mIgnoreLongEll;
}
/** @return whether to ignore 'public' keyword in interface definitions **/
public boolean isIgnorePublicInInterface()
{
@ -920,6 +931,14 @@ public class Configuration
mIgnoreBraces = aTo;
}
/**
* @param aTo whether to ignore long 'L'
*/
public void setIgnoreLongEll(boolean aTo)
{
mIgnoreLongEll = aTo;
}
/**
* @param aTo whether to ignore 'public' in interface definitions
*/

View File

@ -84,6 +84,8 @@ public interface Defn
String IGNORE_CAST_WHITESPACE_PROP = "checkstyle.ignore.whitespace.cast";
/** property name for ignoring braces **/
String IGNORE_BRACES_PROP = "checkstyle.ignore.braces";
/** property name for ignoring long 'L' **/
String IGNORE_LONG_ELL_PROP = "checkstyle.ignore.longell";
/** property name for ignoring wrapping lines on operators **/
String IGNORE_OP_WRAP_PROP = "checkstyle.ignore.opwrap";
/** property name for ignoring 'public' in interface definitions **/

View File

@ -27,7 +27,7 @@ import java.util.HashMap;
* Represents the options for placing the left curly brace '{'.
*
* @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
* @version $Id: LeftCurlyOption.java,v 1.5 2002-05-31 13:55:52 oburn Exp $
* @version $Id: LeftCurlyOption.java,v 1.6 2002-06-06 11:45:40 oburn Exp $
*/
public final class LeftCurlyOption implements Serializable
{
@ -71,6 +71,12 @@ public final class LeftCurlyOption implements Serializable
return (LeftCurlyOption) STR_TO_OPT.get(aStrRep.trim().toLowerCase());
}
/** @see Object **/
public String toString()
{
return mStrRep;
}
/**
* Ensures that we don't get multiple instances of one LeftCurlyOption
* during deserialization. See Section 3.6 of the Java Object

View File

@ -65,6 +65,12 @@ public final class PadOption
return (PadOption) STR_TO_OPT.get(aStrRep.trim().toLowerCase());
}
/** @see Object **/
public String toString()
{
return mStrRep;
}
/**
* Ensures that we don't get multiple instances of one PadOption
* during deserialization. See Section 3.6 of the Java Object

View File

@ -27,7 +27,7 @@ import java.util.HashMap;
* Represents the options for placing the right curly brace '}'.
*
* @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
* @version $Id: RightCurlyOption.java,v 1.3 2002-05-31 13:55:52 oburn Exp $
* @version $Id: RightCurlyOption.java,v 1.4 2002-06-06 11:45:40 oburn Exp $
*/
public final class RightCurlyOption implements Serializable
{
@ -67,6 +67,12 @@ public final class RightCurlyOption implements Serializable
return (RightCurlyOption) STR_TO_OPT.get(aStrRep.trim().toLowerCase());
}
/** @see Object **/
public String toString()
{
return mStrRep;
}
/**
* Ensures that we don't get multiple instances of one RightCurlyOption
* during deserialization. See Section 3.6 of the Java Object

View File

@ -953,6 +953,19 @@ class Verifier
}
}
/**
* Verify that the 'L' on a long is uppercase. E.g. 40L, not 40l.
* @param aLineNo number of line to check
* @param aColNo column where the 'ell' is
*/
void verifyLongEll(int aLineNo, int aColNo)
{
if (!mConfig.isIgnoreLongEll()
&& (mLines[aLineNo - 1].charAt(aColNo) == 'l'))
{
log(aLineNo, aColNo, "Should use uppercase 'L'.");
}
}
// }}}
@ -1432,10 +1445,9 @@ class Verifier
final Iterator illIter = illegalInsts.iterator();
while (illIter.hasNext()) {
final String illegal = (String) illIter.next();
final String illegalBase = basename(illegal);
// class from java.lang
if (illegal.length() - javaLang.length() == aClassName.length()
if (((illegal.length() - javaLang.length()) == aClassName.length())
&& illegal.endsWith(aClassName)
&& illegal.startsWith(javaLang))
{

View File

@ -1353,7 +1353,7 @@ NUM_INT
)?
| ('1'..'9') ('0'..'9')* {isDecimal=true;} // non-zero decimal
)
( ('l'|'L') { _ttype = NUM_LONG; }
( ('l'|'L') { _ttype = NUM_LONG; ver.verifyLongEll(getLine(), getColumn()-2); }
// only check to see if it's a float if looks like decimal so far
| {isDecimal}?

View File

@ -772,6 +772,7 @@ public class CheckerTest
mConfig.setCatchBlock(BlockOption.STMT);
mConfig.setFinallyBlock(BlockOption.STMT);
mConfig.setIgnoreImports(true);
mConfig.setIgnoreLongEll(false);
mConfig.setIllegalInstantiations(
"java.lang.Boolean," +
"com.puppycrawl.tools.checkstyle.InputModifier," +
@ -797,6 +798,7 @@ public class CheckerTest
filepath + ":76:17: Must have at least one statement.",
filepath + ":78:13: Must have at least one statement.",
filepath + ":81:17: Must have at least one statement.",
filepath + ":93:43: Should use uppercase 'L'.",
};
verify(c, filepath, expected);
}
@ -809,6 +811,7 @@ public class CheckerTest
mConfig.setCatchBlock(BlockOption.TEXT);
mConfig.setFinallyBlock(BlockOption.TEXT);
mConfig.setIgnoreImports(true);
mConfig.setIgnoreLongEll(true);
mConfig.setIllegalInstantiations("");
final Checker c = createChecker();
final String filepath = getPath("InputSemantic.java");

View File

@ -88,4 +88,7 @@ class InputSemantic
; // statement
}
}
/** test **/
private static final long IGNORE = 666l + 666L;
}