Interface methods can be private now
This commit is contained in:
@ -57,7 +57,8 @@ public class ASTMethodDeclaration extends AbstractJavaAccessNode implements DFAG
|
||||
|
||||
@Override
|
||||
public boolean isPublic() {
|
||||
if (isInterfaceMember()) {
|
||||
// interface methods are public by default, but could be private since java9
|
||||
if (isInterfaceMember() && !isPrivate()) {
|
||||
return true;
|
||||
}
|
||||
return super.isPublic();
|
||||
|
@ -5,9 +5,13 @@
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ParserTstUtil;
|
||||
|
||||
public class ASTMethodDeclarationTest {
|
||||
|
||||
@Test
|
||||
@ -21,4 +25,20 @@ public class ASTMethodDeclarationTest {
|
||||
|
||||
assertEquals("foo", md.getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrivateInterfaceMethods() {
|
||||
ASTCompilationUnit node = ParserTstUtil.parseJava9("public interface Foo { private void bar() { } }");
|
||||
ASTMethodDeclaration methodDecl = node.getFirstDescendantOfType(ASTMethodDeclaration.class);
|
||||
assertTrue(methodDecl.isPrivate());
|
||||
assertFalse(methodDecl.isPublic());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublicInterfaceMethods() {
|
||||
ASTCompilationUnit node = ParserTstUtil.parseJava9("public interface Foo { void bar(); }");
|
||||
ASTMethodDeclaration methodDecl = node.getFirstDescendantOfType(ASTMethodDeclaration.class);
|
||||
assertFalse(methodDecl.isPrivate());
|
||||
assertTrue(methodDecl.isPublic());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user