diff --git a/pmd/etc/grammar/Java.jjt b/pmd/etc/grammar/Java.jjt index 0d1a5b4e2c..949ed255ee 100644 --- a/pmd/etc/grammar/Java.jjt +++ b/pmd/etc/grammar/Java.jjt @@ -2,7 +2,7 @@ * * Added support for Java 7 language constructs * - * Dinesh Bolkensteyn (SonarSource), 06/11 + * Dinesh Bolkensteyn (SonarSource), 10/2011 * =================================================================== * Added in support for assert as a name using lookaheads * @@ -145,6 +145,12 @@ public class JavaParser { throw new ParseException("Cannot use the diamond generic notation when running in JDK inferior to 1.7 mode!"); } } + + private void checkForBadTryWithResourcesUsage() { + if (jdkVersion < 7) { + throw new ParseException("Cannot use the try-with-resources notation when running in JDK inferior to 1.7 mode!"); + } + } // This is a semantic LOOKAHEAD to determine if we're dealing with an assert // Note that this can't be replaced with a syntactic lookahead @@ -1968,6 +1974,7 @@ void TryStatement() : void ResourceSpecification() : {} { + {checkForBadTryWithResourcesUsage();} "(" Resources() (LOOKAHEAD(2) ";")? diff --git a/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java b/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java index c35d14d7f8..0e2f68b038 100644 --- a/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/CommandLineOptionsTest.java @@ -26,7 +26,7 @@ public class CommandLineOptionsTest { @Test public void testTargetJDKVersion() { CommandLineOptions opt = new CommandLineOptions(new String[]{"file", "format", "basic"}); - assertEquals("1.5", opt.getTargetJDK()); + assertEquals("1.7", opt.getTargetJDK()); opt = new CommandLineOptions(new String[]{"file", "format", "ruleset", "-targetjdk", "1.3"}); assertEquals("1.3", opt.getTargetJDK()); opt = new CommandLineOptions(new String[]{"file", "format", "ruleset", "-targetjdk", "1.5"}); diff --git a/pmd/src/net/sourceforge/pmd/CommandLineOptions.java b/pmd/src/net/sourceforge/pmd/CommandLineOptions.java index 4079c6fc06..e115c7ea0e 100644 --- a/pmd/src/net/sourceforge/pmd/CommandLineOptions.java +++ b/pmd/src/net/sourceforge/pmd/CommandLineOptions.java @@ -23,7 +23,7 @@ public class CommandLineOptions { private boolean debugEnabled; private boolean stressTestEnabled; - private String targetJDK = "1.5"; + private String targetJDK = "1.7"; private boolean shortNamesEnabled; private int cpus = Runtime.getRuntime().availableProcessors(); @@ -223,7 +223,7 @@ public class CommandLineOptions { PMD.EOL + "Optional arguments that may be put before or after the mandatory arguments: " + PMD.EOL + "-debug: prints debugging information" + PMD.EOL + - "-targetjdk: specifies a language version to target - 1.3, 1.4, 1.5, 1.6 or 1.7; default is 1.5" + PMD.EOL + + "-targetjdk: specifies a language version to target - 1.3, 1.4, 1.5, 1.6 or 1.7; default is 1.7" + PMD.EOL + "-cpus: specifies the number of threads to create" + PMD.EOL + "-encoding: specifies the character set encoding of the source code files PMD is reading (i.e., UTF-8)" + PMD.EOL + "-excludemarker: specifies the String that marks the a line which PMD should ignore; default is NOPMD" + PMD.EOL +