diff --git a/docs/anttask.html b/docs/anttask.html index 9e95ab66b..ab7467689 100644 --- a/docs/anttask.html +++ b/docs/anttask.html @@ -251,6 +251,11 @@ This task is included in the checkstyle distribution.

Specifies whether to ignore checking braces. Defaults to "false". No + + ignoreLongEll + Specifies whether to ignore checking the L in long integer literals. Defaults to "false". + No + ignorePublicInInterface Specifies whether to ignore the public keyword in interface definitions. Defaults to "false". diff --git a/docs/cmdline.html b/docs/cmdline.html index 4b755e32a..351159817 100644 --- a/docs/cmdline.html +++ b/docs/cmdline.html @@ -208,6 +208,10 @@ This command line tool is included in the checkstyle distribution.

checkstyle.ignore.braces Specifies whether to ignore checking braces. Defaults to "no". + + checkstyle.ignore.longell + Specifies whether to ignore checking the L in long integer literals. Defaults to "false". + checkstyle.ignore.public.in.interface Specifies whether to ignore the public keyword in interface definitions. Defaults to "no". diff --git a/docs/engine.html b/docs/engine.html index dfa1f605d..1c9517d66 100644 --- a/docs/engine.html +++ b/docs/engine.html @@ -272,6 +272,10 @@

Verifies that the format of local variables conform to a specified regular expression. The default is ^[a-z][a-zA-Z0-9]*$.

+

Integer Literals

+

Verifies that long integer literals use an uppercase L. For example 40L instead of 40l. This is in accordance to the Java Language Specification, Section 3.10.1. This check can be turned off.

+ +

Modifiers

Checks that the order of modifiers conforms to the suggestions in the Java Language specification, sections 8.1.1, 8.3.1 and 8.4.3. The correct order is public protected private abstract static final transient volatile synchronized native strictfp.

diff --git a/docs/index.html b/docs/index.html index c7dd147f0..1850f4734 100644 --- a/docs/index.html +++ b/docs/index.html @@ -87,6 +87,10 @@
  • Unused or duplicate import statements.
  • Javadoc comments are defined for class, interface, variable and method declarations. Note: This can be made to check only public and protected declarations.
  • Javadoc tags for a method match the actual code.
  • +
  • Detect instantiations of classes that should not be instantiated (e.g. java.lang.Boolean).
  • +
  • Content of try, catch and finally blocks.
  • +
  • Enforce line wrapping on operators.
  • +
  • Presence of to-do comments.
  • The package.html package documentation file is available.
  • The file starts with a specified header. This is useful to ensure that a file has a copyright notice.
  • An @author tag exists for class and interface Javadoc comments.
  • @@ -105,6 +109,7 @@
  • Lines are not longer than a specified length.
  • Methods/Constructors are not longer than a specified number of lines.
  • Files are not longer than a specified number of lines.
  • +
  • Long integer literals use an uppercase L. For example 40L instead of 40l.
  • diff --git a/docs/releasenotes.html b/docs/releasenotes.html index 729b4c0bc..5022453b0 100644 --- a/docs/releasenotes.html +++ b/docs/releasenotes.html @@ -47,6 +47,7 @@
  • Detect empty catch blocks (request 516255).
  • Detect empty finally blocks.
  • Detect to-do comments (request 504275).
  • +
  • Detect use of lowercase l ("ell") in long integer literals.
  • Include column number in the XML output (request 555262).
  • diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/BlockOption.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/BlockOption.java index f11b59a99..335b0c30f 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/BlockOption.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/BlockOption.java @@ -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 diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java index 9b709b0be..6ebf6e6ae 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/CheckStyleTask.java @@ -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) { diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java index 43f80853d..c7741d5e3 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Configuration.java @@ -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 */ diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java index b0178736b..fea06a7bb 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Defn.java @@ -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 **/ diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/LeftCurlyOption.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/LeftCurlyOption.java index b034b0ad7..a81ebe424 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/LeftCurlyOption.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/LeftCurlyOption.java @@ -27,7 +27,7 @@ import java.util.HashMap; * Represents the options for placing the left curly brace '{'. * * @author Oliver Burn - * @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 diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/PadOption.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/PadOption.java index 253c10324..2bebbe385 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/PadOption.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/PadOption.java @@ -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 diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/RightCurlyOption.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/RightCurlyOption.java index e8029f301..8729bfe11 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/RightCurlyOption.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/RightCurlyOption.java @@ -27,7 +27,7 @@ import java.util.HashMap; * Represents the options for placing the right curly brace '}'. * * @author Oliver Burn - * @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 diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java index 160c8e84c..060e4f623 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Verifier.java @@ -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)) { diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g index 6ebe01476..dc9b9cdc8 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/java.g @@ -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}? diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index 40cfeff0a..c574128d2 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -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"); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputSemantic.java b/src/tests/com/puppycrawl/tools/checkstyle/InputSemantic.java index dbc8929a6..e1e2472f0 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/InputSemantic.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/InputSemantic.java @@ -88,4 +88,7 @@ class InputSemantic ; // statement } } + + /** test **/ + private static final long IGNORE = 666l + 666L; }