From 701bb990443345880777525234284d6fb5f28396 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 26 Jun 2023 11:04:09 -0700 Subject: Write `package-info`s even if the package info doesn't contain any annotations Similar to javac's `-Xpkginfo:always` PiperOrigin-RevId: 543487269 --- java/com/google/turbine/binder/CompUnitPreprocessor.java | 2 +- javatests/com/google/turbine/lower/LowerIntegrationTest.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/java/com/google/turbine/binder/CompUnitPreprocessor.java b/java/com/google/turbine/binder/CompUnitPreprocessor.java index 970dc4b..25ba48a 100644 --- a/java/com/google/turbine/binder/CompUnitPreprocessor.java +++ b/java/com/google/turbine/binder/CompUnitPreprocessor.java @@ -105,7 +105,7 @@ public final class CompUnitPreprocessor { // "While the file could technically contain the source code // for one or more package-private (default-access) classes, // it would be very bad form." -- JLS 7.4.1 - if (!unit.pkg().get().annos().isEmpty()) { + if (!unit.pkg().get().annos().isEmpty() || unit.decls().isEmpty()) { decls = Iterables.concat(decls, ImmutableList.of(packageInfoTree(unit.pkg().get()))); } } else { diff --git a/javatests/com/google/turbine/lower/LowerIntegrationTest.java b/javatests/com/google/turbine/lower/LowerIntegrationTest.java index 9026725..6c95d44 100644 --- a/javatests/com/google/turbine/lower/LowerIntegrationTest.java +++ b/javatests/com/google/turbine/lower/LowerIntegrationTest.java @@ -391,7 +391,12 @@ public class LowerIntegrationTest { int version = SOURCE_VERSION.getOrDefault(test, 8); assumeTrue(version <= Runtime.version().feature()); ImmutableList javacopts = - ImmutableList.of("-source", String.valueOf(version), "-target", String.valueOf(version)); + ImmutableList.of( + "-source", + String.valueOf(version), + "-target", + String.valueOf(version), + "-Xpkginfo:always"); Map expected = IntegrationTestSupport.runJavac(input.sources, classpathJar, javacopts); -- cgit v1.2.3