Skip to content

Commit ffa780e

Browse files
Dino Olivacopybara-github
authored andcommitted
Update entry class specification to export both the class and associated members.
PiperOrigin-RevId: 366359998
1 parent a58e44f commit ffa780e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tree_shaker/src/main/java/com/google/devtools/treeshaker/UsedCodeMarker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,9 @@ private MemberInfo popMethodScope() {
347347

348348
private void startMethodDeclaration(
349349
String methodName, boolean isConstructor, boolean isStatic) {
350-
boolean isExported = exportedMethods.contains(
351-
getQualifiedMethodName(currentTypeNameScope.peek(), methodName));
350+
boolean isExported =
351+
exportedMethods.contains(getQualifiedMethodName(currentTypeNameScope.peek(), methodName))
352+
|| currentTypeInfoScope.peek().getExported();
352353
logger.atFine().log("Start Method: %s.%s : isConstructor: %s : isStatic: %s, exported: %b",
353354
currentTypeNameScope.peek(), methodName, isConstructor, isStatic, isExported);
354355
pushMethodScope(methodName,

tree_shaker/src/test/java/com/google/devtools/treeshaker/TreeShakerTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ public void testExportedClass() throws IOException {
124124
assertThat(getUnusedClasses(unused)).containsNoneOf("A", "b.c.C");
125125
assertThat(getUnusedClasses(unused)).containsExactly("b.B");
126126

127-
assertThat(getUnusedMethods(unused)).containsExactly(
127+
assertThat(getUnusedMethods(unused)).containsNoneOf(
128128
getMethodName("A", "A", "()V"),
129129
getMethodName("A", "main", "([Ljava/lang/String;)V"),
130130
getMethodName("b.c.C", "C", "()V"),
131131
getMethodName("b.c.C", "c", "(Ljava/lang/String;)V"));
132+
133+
assertThat(getUnusedMethods(unused)).isEmpty();
132134
}
133135

134136
public void testConstructorOverloads() throws IOException {
@@ -677,8 +679,8 @@ public void testWriteUnusedClasses() throws IOException {
677679
}
678680

679681
public void testWriteUnusedConstructor() throws IOException {
680-
addTreeShakerRootsFile("A");
681-
addSourceFile("A.java", "class A { }");
682+
addTreeShakerRootsFile("A:\n a()");
683+
addSourceFile("A.java", "class A { static void a() {}}");
682684
String output = writeUnused(findUnusedCode());
683685

684686
assertThat(output).startsWith("A:\n");

0 commit comments

Comments
 (0)