From 722b2b165786b583da63d7ce72d91f1a72b8785e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 22 Sep 2017 13:33:08 +0200 Subject: [PATCH] Allow nested private methods --- pmd-java/etc/grammar/Java.jjt | 6 +++--- .../net/sourceforge/pmd/lang/java/ast/JDKVersionTest.java | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index d3720dd64d..18ad2d4435 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1359,11 +1359,11 @@ void TypeDeclaration(): void ClassOrInterfaceDeclaration(int modifiers): { -Token t = null; -jjtThis.setModifiers(modifiers); + Token t = null; + jjtThis.setModifiers(modifiers); + inInterface = false; } { - ( /* See note about this optional final modifier in BlockStatement */ ["final"|"abstract"] "class" | "interface" { jjtThis.setInterface(); inInterface = true; } ) t= { jjtThis.setImage(t.image); } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/JDKVersionTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/JDKVersionTest.java index 019687f12b..faa604cea0 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/JDKVersionTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/JDKVersionTest.java @@ -218,6 +218,11 @@ public class JDKVersionTest { parseJava18("public class Foo { private void bar() { } }"); } + @Test + public final void testNestedPrivateMethods() { + parseJava18("public interface Baz { public static class Foo { private void bar() { } } }"); + } + @Test public final void jdk9PrivateInterfaceMethods() { parseJava9(loadSource("jdk9_private_interface_methods.java"));