diff options
Diffstat (limited to 'java/com/google/turbine/binder/CompUnitPreprocessor.java')
-rw-r--r-- | java/com/google/turbine/binder/CompUnitPreprocessor.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/java/com/google/turbine/binder/CompUnitPreprocessor.java b/java/com/google/turbine/binder/CompUnitPreprocessor.java index 970dc4b..98be898 100644 --- a/java/com/google/turbine/binder/CompUnitPreprocessor.java +++ b/java/com/google/turbine/binder/CompUnitPreprocessor.java @@ -36,6 +36,8 @@ import com.google.turbine.tree.Tree.ModDecl; import com.google.turbine.tree.Tree.PkgDecl; import com.google.turbine.tree.Tree.TyDecl; import com.google.turbine.tree.TurbineModifier; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -105,7 +107,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 (isPackageInfo(unit)) { decls = Iterables.concat(decls, ImmutableList.of(packageInfoTree(unit.pkg().get()))); } } else { @@ -124,6 +126,18 @@ public final class CompUnitPreprocessor { unit.imports(), types.build(), unit.mod(), unit.source(), packageName); } + private static boolean isPackageInfo(CompUnit unit) { + String path = unit.source().path(); + if (path == null) { + return false; + } + Path fileName = Paths.get(path).getFileName(); + if (fileName == null) { + return false; + } + return fileName.toString().equals("package-info.java"); + } + private static ImmutableMap<String, ClassSymbol> preprocessChildren( SourceFile source, ImmutableList.Builder<SourceBoundClass> types, |