PMD 4.3.x Java 7 is now default and better 1.5 targetJdk handling

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.3.x@7412 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Dinesh Bolkensteyn 2011-11-01 13:56:31 +00:00
parent 3dea951e0c
commit 8bbca10f73
3 changed files with 11 additions and 4 deletions

View File

@ -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) ";")?

View File

@ -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"});

View File

@ -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 +