diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 8511bbf890..688acd1cc1 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,8 @@ /** + * Add support for new Java 8 annotation locations. + * Bugs #414, #415, #417 + * @Snap252 06/2017 + *==================================================================== * Allow empty statements (";") between package, import * and type declarations. * Bug #378 @@ -1416,7 +1420,7 @@ void TypeParameter(): void TypeBound(): {} { - "extends" ((Annotation() {checkForBadTypeAnnotations();})*) ClassOrInterfaceType() ( "&" ((Annotation() {checkForBadTypeAnnotations();})*) ClassOrInterfaceType() )* + "extends" (Annotation() {checkForBadTypeAnnotations();})* ClassOrInterfaceType() ( "&" (Annotation() {checkForBadTypeAnnotations();})* ClassOrInterfaceType() )* } void ClassOrInterfaceBody(): @@ -1488,7 +1492,7 @@ void MethodDeclaration(int modifiers) : {jjtThis.setModifiers(modifiers);} { [ TypeParameters() ] - [(Annotation() {checkForBadTypeAnnotations();})+] ResultType() MethodDeclarator() [ "throws" NameList() ] + (Annotation() {checkForBadTypeAnnotations();})* ResultType() MethodDeclarator() [ "throws" NameList() ] ( Block() | ";" ) } @@ -1564,9 +1568,9 @@ void Type(): void ReferenceType(): {} { - PrimitiveType() ((Annotation() {checkForBadTypeAnnotations();})*) ( LOOKAHEAD(2) "[" "]" { jjtThis.bumpArrayDepth(); })+ + PrimitiveType() (Annotation() {checkForBadTypeAnnotations();})* ( LOOKAHEAD(2) "[" "]" { jjtThis.bumpArrayDepth(); })+ | - ( ClassOrInterfaceType()) ((Annotation() {checkForBadTypeAnnotations();})*) ( LOOKAHEAD(2) "[" "]" { jjtThis.bumpArrayDepth(); })* + ( ClassOrInterfaceType()) (Annotation() {checkForBadTypeAnnotations();})* ( LOOKAHEAD(2) "[" "]" { jjtThis.bumpArrayDepth(); })* } void ClassOrInterfaceType(): @@ -1939,7 +1943,7 @@ void ArrayDimsAndInits() : { LOOKAHEAD(2) - ( LOOKAHEAD(2) ((Annotation() {checkForBadTypeAnnotations();})*) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )* + ( LOOKAHEAD(2) (Annotation() {checkForBadTypeAnnotations();})* "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )* | ( "[" "]" )+ ArrayInitializer() } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java b/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java index 76e310dd98..fb2e74321b 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java @@ -166,33 +166,33 @@ public class ParserCornerCases18 { } public List<@AnnotatedUsage ?> testWildCardWithAnnotation() { - return null; + return null; } - public Object @Nullable [] testAnnotationsToArrayElements() { - return null; - } - - private byte @Nullable [] getBytes(){ - return null; - } - - public static > T getEnum() { - return null; - } + public Object @Nullable [] testAnnotationsToArrayElements() { + return null; + } + + private byte @Nullable [] getBytes(){ + return null; + } + + public static > T getEnum() { + return null; + } - public static @Nullable T getNullableEnum() { - return null; - } - - public Object[] createNonNullArray() { - return new Object @NonNull[0]; - } - - private static void testMultiDimArrayWithAnnotations() { - // ever used a 2D-Array in java?? - Object x = new Object @NonNull[2] @Nullable[1] @NonNull[3]; - } + public static @Nullable T getNullableEnum() { + return null; + } + + public Object[] createNonNullArray() { + return new Object @NonNull[0]; + } + + private static void testMultiDimArrayWithAnnotations() { + // ever used a 3D-Array in java?? + Object x = new Object @NonNull[2] @Nullable[1] @NonNull[3]; + } /**