diff --git a/tree_shaker/src/main/java/com/google/devtools/treeshaker/UsedCodeMarker.java b/tree_shaker/src/main/java/com/google/devtools/treeshaker/UsedCodeMarker.java index fd53e9ce85..6904d6ed16 100644 --- a/tree_shaker/src/main/java/com/google/devtools/treeshaker/UsedCodeMarker.java +++ b/tree_shaker/src/main/java/com/google/devtools/treeshaker/UsedCodeMarker.java @@ -347,8 +347,9 @@ private MemberInfo popMethodScope() { private void startMethodDeclaration( String methodName, boolean isConstructor, boolean isStatic) { - boolean isExported = exportedMethods.contains( - getQualifiedMethodName(currentTypeNameScope.peek(), methodName)); + boolean isExported = + exportedMethods.contains(getQualifiedMethodName(currentTypeNameScope.peek(), methodName)) + || currentTypeInfoScope.peek().getExported(); logger.atFine().log("Start Method: %s.%s : isConstructor: %s : isStatic: %s, exported: %b", currentTypeNameScope.peek(), methodName, isConstructor, isStatic, isExported); pushMethodScope(methodName, diff --git a/tree_shaker/src/test/java/com/google/devtools/treeshaker/TreeShakerTest.java b/tree_shaker/src/test/java/com/google/devtools/treeshaker/TreeShakerTest.java index 314b926738..cfa16ab3a5 100644 --- a/tree_shaker/src/test/java/com/google/devtools/treeshaker/TreeShakerTest.java +++ b/tree_shaker/src/test/java/com/google/devtools/treeshaker/TreeShakerTest.java @@ -124,11 +124,13 @@ public void testExportedClass() throws IOException { assertThat(getUnusedClasses(unused)).containsNoneOf("A", "b.c.C"); assertThat(getUnusedClasses(unused)).containsExactly("b.B"); - assertThat(getUnusedMethods(unused)).containsExactly( + assertThat(getUnusedMethods(unused)).containsNoneOf( getMethodName("A", "A", "()V"), getMethodName("A", "main", "([Ljava/lang/String;)V"), getMethodName("b.c.C", "C", "()V"), getMethodName("b.c.C", "c", "(Ljava/lang/String;)V")); + + assertThat(getUnusedMethods(unused)).isEmpty(); } public void testConstructorOverloads() throws IOException { @@ -677,8 +679,8 @@ public void testWriteUnusedClasses() throws IOException { } public void testWriteUnusedConstructor() throws IOException { - addTreeShakerRootsFile("A"); - addSourceFile("A.java", "class A { }"); + addTreeShakerRootsFile("A:\n a()"); + addSourceFile("A.java", "class A { static void a() {}}"); String output = writeUnused(findUnusedCode()); assertThat(output).startsWith("A:\n");