From 411cf2826f99398910b23e2155f7a57a7f67beaa Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Sun, 27 Apr 2008 23:47:59 +0000 Subject: [PATCH] Fixed parsing bug: constant fields in annotation classes git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6071 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + pmd/etc/grammar/Java.jjt | 2 +- .../sourceforge/pmd/ast/JDKVersionTest.java | 7 + .../net/sourceforge/pmd/ast/JavaParser.java | 146 +++++++++--------- 4 files changed, 79 insertions(+), 77 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 0c40804082..b2830a2420 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,6 +1,7 @@ ???? - 4.2.2: Fixed false positive in UnusedImports: javadoc comments are parsed to check @see and other tags +Fixed parsing bug: constant fields in annotation classes April 11, 2008 - 4.2.1: diff --git a/pmd/etc/grammar/Java.jjt b/pmd/etc/grammar/Java.jjt index cd2168c94f..9c2b0fdcf8 100644 --- a/pmd/etc/grammar/Java.jjt +++ b/pmd/etc/grammar/Java.jjt @@ -2076,7 +2076,7 @@ void AnnotationTypeMemberDeclaration(): | ClassOrInterfaceDeclaration(modifiers) | - LOOKAHEAD ( ) EnumDeclaration(modifiers) + LOOKAHEAD(3) EnumDeclaration(modifiers) | AnnotationTypeDeclaration(modifiers) | diff --git a/pmd/regress/test/net/sourceforge/pmd/ast/JDKVersionTest.java b/pmd/regress/test/net/sourceforge/pmd/ast/JDKVersionTest.java index 5d719778e6..5cceaf6e09 100644 --- a/pmd/regress/test/net/sourceforge/pmd/ast/JDKVersionTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/ast/JDKVersionTest.java @@ -117,6 +117,8 @@ public class JDKVersionTest { p.CompilationUnit(); p = new TargetJDK1_5().createParser(new StringReader(ANNOTATIONS_BUG)); p.CompilationUnit(); + p = new TargetJDK1_5().createParser(new StringReader(CONSTANT_FIELD_IN_ANNOTATION_BUG)); + p.CompilationUnit(); p = new TargetJDK1_5().createParser(new StringReader(GENERIC_IN_FIELD)); p.CompilationUnit(); } @@ -286,6 +288,11 @@ public class JDKVersionTest { "public @interface Foo {" + PMD.EOL + "}"; + private static final String CONSTANT_FIELD_IN_ANNOTATION_BUG = + "public @interface Foo {" + PMD.EOL + + " String CONST = \"foo\";" + PMD.EOL + + "}"; + private static final String GENERIC_IN_FIELD = "public class Foo {" + PMD.EOL + " Class foo = (Class)clazz;" + PMD.EOL + diff --git a/pmd/src/net/sourceforge/pmd/ast/JavaParser.java b/pmd/src/net/sourceforge/pmd/ast/JavaParser.java index add76d8ac2..566c4257a6 100644 --- a/pmd/src/net/sourceforge/pmd/ast/JavaParser.java +++ b/pmd/src/net/sourceforge/pmd/ast/JavaParser.java @@ -5784,7 +5784,7 @@ jjtn000.setModifiers(modifiers); break; default: jj_la1[134] = jj_gen; - if (jj_2_51(2147483647)) { + if (jj_2_51(3)) { EnumDeclaration(modifiers); } else { switch (jj_nt.kind) { @@ -6614,8 +6614,8 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_362() { - if (jj_3R_372()) return true; + private boolean jj_3R_361() { + if (jj_3R_371()) return true; return false; } @@ -6840,18 +6840,12 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_372() { + private boolean jj_3R_371() { if (jj_scan_token(_DEFAULT)) return true; if (jj_3R_97()) return true; return false; } - private boolean jj_3_51() { - if (jj_scan_token(IDENTIFIER)) return true; - if (jj_scan_token(IDENTIFIER)) return true; - return false; - } - private boolean jj_3_9() { if (jj_scan_token(COMMA)) return true; if (jj_3R_72()) return true; @@ -6874,17 +6868,17 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_359() { + private boolean jj_3R_358() { if (jj_3R_289()) return true; return false; } - private boolean jj_3R_358() { + private boolean jj_3R_357() { if (jj_3R_291()) return true; return false; } - private boolean jj_3R_357() { + private boolean jj_3_51() { if (jj_3R_68()) return true; return false; } @@ -6901,7 +6895,7 @@ jjtn000.setModifiers(modifiers); if (jj_scan_token(RPAREN)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_362()) jj_scanpos = xsp; + if (jj_3R_361()) jj_scanpos = xsp; if (jj_scan_token(SEMICOLON)) return true; return false; } @@ -6925,11 +6919,11 @@ jjtn000.setModifiers(modifiers); jj_scanpos = xsp; if (jj_3R_356()) { jj_scanpos = xsp; + if (jj_3_51()) { + jj_scanpos = xsp; if (jj_3R_357()) { jj_scanpos = xsp; - if (jj_3R_358()) { - jj_scanpos = xsp; - if (jj_3R_359()) return true; + if (jj_3R_358()) return true; } } } @@ -7589,7 +7583,7 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_379() { + private boolean jj_3R_378() { if (jj_scan_token(FINALLY)) return true; if (jj_3R_183()) return true; return false; @@ -7611,7 +7605,7 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_378() { + private boolean jj_3R_377() { if (jj_scan_token(CATCH)) return true; if (jj_scan_token(LPAREN)) return true; if (jj_3R_329()) return true; @@ -7631,13 +7625,13 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_371() { - if (jj_3R_379()) return true; + private boolean jj_3R_370() { + if (jj_3R_378()) return true; return false; } - private boolean jj_3R_370() { - if (jj_3R_378()) return true; + private boolean jj_3R_369() { + if (jj_3R_377()) return true; return false; } @@ -7664,10 +7658,10 @@ jjtn000.setModifiers(modifiers); Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_370()) { jj_scanpos = xsp; break; } + if (jj_3R_369()) { jj_scanpos = xsp; break; } } xsp = jj_scanpos; - if (jj_3R_371()) jj_scanpos = xsp; + if (jj_3R_370()) jj_scanpos = xsp; return false; } @@ -7695,12 +7689,12 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_369() { + private boolean jj_3R_368() { if (jj_3R_88()) return true; return false; } - private boolean jj_3R_368() { + private boolean jj_3R_367() { if (jj_scan_token(IDENTIFIER)) return true; return false; } @@ -7730,7 +7724,7 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_390() { + private boolean jj_3R_389() { if (jj_scan_token(COMMA)) return true; if (jj_3R_185()) return true; return false; @@ -7740,12 +7734,12 @@ jjtn000.setModifiers(modifiers); if (jj_scan_token(RETURN)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_369()) jj_scanpos = xsp; + if (jj_3R_368()) jj_scanpos = xsp; if (jj_scan_token(SEMICOLON)) return true; return false; } - private boolean jj_3R_367() { + private boolean jj_3R_366() { if (jj_scan_token(IDENTIFIER)) return true; return false; } @@ -7754,7 +7748,7 @@ jjtn000.setModifiers(modifiers); if (jj_scan_token(CONTINUE)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_368()) jj_scanpos = xsp; + if (jj_3R_367()) jj_scanpos = xsp; if (jj_scan_token(SEMICOLON)) return true; return false; } @@ -7763,13 +7757,13 @@ jjtn000.setModifiers(modifiers); if (jj_scan_token(BREAK)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_367()) jj_scanpos = xsp; + if (jj_3R_366()) jj_scanpos = xsp; if (jj_scan_token(SEMICOLON)) return true; return false; } - private boolean jj_3R_384() { - if (jj_3R_389()) return true; + private boolean jj_3R_383() { + if (jj_3R_388()) return true; return false; } @@ -7782,12 +7776,12 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_389() { + private boolean jj_3R_388() { if (jj_3R_185()) return true; Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_390()) { jj_scanpos = xsp; break; } + if (jj_3R_389()) { jj_scanpos = xsp; break; } } return false; } @@ -7807,7 +7801,7 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_364() { + private boolean jj_3R_363() { if (jj_scan_token(ELSE)) return true; if (jj_3R_91()) return true; return false; @@ -7823,8 +7817,8 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_388() { - if (jj_3R_389()) return true; + private boolean jj_3R_387() { + if (jj_3R_388()) return true; return false; } @@ -7843,17 +7837,17 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_387() { + private boolean jj_3R_386() { if (jj_3R_168()) return true; return false; } - private boolean jj_3R_383() { + private boolean jj_3R_382() { Token xsp; xsp = jj_scanpos; - if (jj_3R_387()) { + if (jj_3R_386()) { jj_scanpos = xsp; - if (jj_3R_388()) return true; + if (jj_3R_387()) return true; } return false; } @@ -7886,12 +7880,12 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_377() { - if (jj_3R_384()) return true; + private boolean jj_3R_376() { + if (jj_3R_383()) return true; return false; } - private boolean jj_3R_376() { + private boolean jj_3R_375() { if (jj_3R_88()) return true; return false; } @@ -7936,8 +7930,8 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_375() { - if (jj_3R_383()) return true; + private boolean jj_3R_374() { + if (jj_3R_382()) return true; return false; } @@ -7950,20 +7944,20 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_366() { + private boolean jj_3R_365() { Token xsp; xsp = jj_scanpos; + if (jj_3R_374()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + xsp = jj_scanpos; if (jj_3R_375()) jj_scanpos = xsp; if (jj_scan_token(SEMICOLON)) return true; xsp = jj_scanpos; if (jj_3R_376()) jj_scanpos = xsp; - if (jj_scan_token(SEMICOLON)) return true; - xsp = jj_scanpos; - if (jj_3R_377()) jj_scanpos = xsp; return false; } - private boolean jj_3R_365() { + private boolean jj_3R_364() { if (jj_3R_94()) return true; if (jj_3R_70()) return true; if (jj_scan_token(IDENTIFIER)) return true; @@ -7977,9 +7971,9 @@ jjtn000.setModifiers(modifiers); if (jj_scan_token(LPAREN)) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_365()) { + if (jj_3R_364()) { jj_scanpos = xsp; - if (jj_3R_366()) return true; + if (jj_3R_365()) return true; } if (jj_scan_token(RPAREN)) return true; if (jj_3R_91()) return true; @@ -8039,35 +8033,35 @@ jjtn000.setModifiers(modifiers); if (jj_3R_91()) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_364()) jj_scanpos = xsp; + if (jj_3R_363()) jj_scanpos = xsp; return false; } - private boolean jj_3R_382() { + private boolean jj_3R_381() { if (jj_scan_token(_DEFAULT)) return true; if (jj_scan_token(COLON)) return true; return false; } - private boolean jj_3R_381() { + private boolean jj_3R_380() { if (jj_scan_token(CASE)) return true; if (jj_3R_88()) return true; if (jj_scan_token(COLON)) return true; return false; } - private boolean jj_3R_374() { + private boolean jj_3R_373() { Token xsp; xsp = jj_scanpos; - if (jj_3R_381()) { + if (jj_3R_380()) { jj_scanpos = xsp; - if (jj_3R_382()) return true; + if (jj_3R_381()) return true; } return false; } - private boolean jj_3R_363() { - if (jj_3R_374()) return true; + private boolean jj_3R_362() { + if (jj_3R_373()) return true; Token xsp; while (true) { xsp = jj_scanpos; @@ -8101,13 +8095,13 @@ jjtn000.setModifiers(modifiers); Token xsp; while (true) { xsp = jj_scanpos; - if (jj_3R_363()) { jj_scanpos = xsp; break; } + if (jj_3R_362()) { jj_scanpos = xsp; break; } } if (jj_scan_token(RBRACE)) return true; return false; } - private boolean jj_3R_373() { + private boolean jj_3R_372() { if (jj_3R_231()) return true; if (jj_3R_88()) return true; return false; @@ -8127,7 +8121,7 @@ jjtn000.setModifiers(modifiers); if (jj_3R_75()) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_373()) jj_scanpos = xsp; + if (jj_3R_372()) jj_scanpos = xsp; return false; } @@ -8614,7 +8608,7 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_386() { + private boolean jj_3R_385() { if (jj_scan_token(DECR)) return true; return false; } @@ -8823,17 +8817,17 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_385() { + private boolean jj_3R_384() { if (jj_scan_token(INCR)) return true; return false; } - private boolean jj_3R_380() { + private boolean jj_3R_379() { Token xsp; xsp = jj_scanpos; - if (jj_3R_385()) { + if (jj_3R_384()) { jj_scanpos = xsp; - if (jj_3R_386()) return true; + if (jj_3R_385()) return true; } return false; } @@ -8876,7 +8870,7 @@ jjtn000.setModifiers(modifiers); return false; } - private boolean jj_3R_361() { + private boolean jj_3R_360() { if (jj_scan_token(LPAREN)) return true; if (jj_3R_70()) return true; if (jj_scan_token(RPAREN)) return true; @@ -8887,14 +8881,14 @@ jjtn000.setModifiers(modifiers); private boolean jj_3R_350() { Token xsp; xsp = jj_scanpos; - if (jj_3R_360()) { + if (jj_3R_359()) { jj_scanpos = xsp; - if (jj_3R_361()) return true; + if (jj_3R_360()) return true; } return false; } - private boolean jj_3R_360() { + private boolean jj_3R_359() { if (jj_scan_token(LPAREN)) return true; if (jj_3R_70()) return true; if (jj_scan_token(RPAREN)) return true; @@ -8913,7 +8907,7 @@ jjtn000.setModifiers(modifiers); if (jj_3R_75()) return true; Token xsp; xsp = jj_scanpos; - if (jj_3R_380()) jj_scanpos = xsp; + if (jj_3R_379()) jj_scanpos = xsp; return false; }