From d57e3ae59b72fec851c7fb778a5531a0a6ac3f8a Mon Sep 17 00:00:00 2001 From: Goktug Gokdogan Date: Sat, 25 Jan 2025 18:58:04 -0800 Subject: [PATCH] Remove references to PackageInfoCache from javac. It is not used anywhere. PiperOrigin-RevId: 719753124 --- .../javac/CompilationUnitBuilder.java | 61 ------------------- .../frontend/javac/JavacParser.java | 4 -- 2 files changed, 65 deletions(-) diff --git a/transpiler/java/com/google/j2cl/transpiler/frontend/javac/CompilationUnitBuilder.java b/transpiler/java/com/google/j2cl/transpiler/frontend/javac/CompilationUnitBuilder.java index 6d9f5786a8..ca73065133 100644 --- a/transpiler/java/com/google/j2cl/transpiler/frontend/javac/CompilationUnitBuilder.java +++ b/transpiler/java/com/google/j2cl/transpiler/frontend/javac/CompilationUnitBuilder.java @@ -22,7 +22,6 @@ import static java.util.stream.Collectors.toCollection; import com.google.common.base.Predicates; -import com.google.common.collect.ComparisonChain; import com.google.common.collect.ImmutableList; import com.google.j2cl.common.FilePosition; import com.google.j2cl.common.SourcePosition; @@ -93,15 +92,12 @@ import com.google.j2cl.transpiler.ast.WhileStatement; import com.google.j2cl.transpiler.ast.YieldStatement; import com.google.j2cl.transpiler.frontend.common.AbstractCompilationUnitBuilder; -import com.google.j2cl.transpiler.frontend.common.Nullability; -import com.google.j2cl.transpiler.frontend.common.PackageInfoCache; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.Tree.Kind; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.MethodSymbol; -import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCArrayAccess; @@ -149,7 +145,6 @@ import java.io.IOException; import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.Collections; import java.util.Deque; import java.util.HashMap; import java.util.List; @@ -1375,19 +1370,6 @@ private List convertExpressions(List expressions) { private CompilationUnit build(JCCompilationUnit javacUnit) { this.javacUnit = javacUnit; - if (javacUnit.getSourceFile().getName().endsWith("package-info.java") - && javacUnit.getPackage() != null) { - String packageName = javacUnit.getPackageName().toString(); - String packageJsNamespace = getPackageJsNamespace(javacUnit); - boolean isNullMarked = isNullMarked(javacUnit); - PackageInfoCache.get() - .setPackageProperties( - packageName, - packageJsNamespace, - // TODO(b/135123615): need to support ObjectiveCName extraction. - null, - isNullMarked); - } setCurrentCompilationUnit( CompilationUnit.createForFile( javacUnit.getSourceFile().getName(), @@ -1402,56 +1384,13 @@ private CompilationUnit build(JCCompilationUnit javacUnit) { public static ImmutableList build( List compilationUnits, JavaEnvironment javaEnvironment) { - CompilationUnitBuilder compilationUnitBuilder = new CompilationUnitBuilder(javaEnvironment); - - // Ensure that all source package-info classes come before all other classes so that the - // freshness of the PackageInfoCache can be trusted. - sortPackageInfoFirst(compilationUnits); - return compilationUnits.stream() .map(JCCompilationUnit.class::cast) .map(compilationUnitBuilder::build) .collect(toImmutableList()); } - @Nullable - private static String getPackageJsNamespace(JCCompilationUnit javacUnit) { - PackageSymbol packge = javacUnit.packge; - if (packge == null) { - return null; - } - - return JsInteropAnnotationUtils.getJsNamespace(packge); - } - - private static boolean isNullMarked(JCCompilationUnit javacUnit) { - PackageSymbol packge = javacUnit.packge; - if (packge == null) { - return false; - } - - return packge.getAnnotationMirrors().stream() - .anyMatch(a -> Nullability.isNullMarkedAnnotation(AnnotationUtils.getAnnotationName(a))); - } - - private static void sortPackageInfoFirst(List compilationUnits) { - // Ensure that all source package-info classes come before all other classes so that the - // freshness of the PackageInfoCache can be trusted. - Collections.sort( - compilationUnits, - (thisCompilationUnit, thatCompilationUnit) -> { - String thisFilePath = thisCompilationUnit.getSourceFile().getName(); - String thatFilePath = thatCompilationUnit.getSourceFile().getName(); - boolean thisIsPackageInfo = thisFilePath.endsWith("package-info.java"); - boolean thatIsPackageInfo = thatFilePath.endsWith("package-info.java"); - return ComparisonChain.start() - .compareTrueFirst(thisIsPackageInfo, thatIsPackageInfo) - .compare(thisFilePath, thatFilePath) - .result(); - }); - } - private boolean inNullMarkedScope() { return getCurrentType().getDeclaration().isNullMarked(); } diff --git a/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavacParser.java b/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavacParser.java index 7637ef395a..052e78cbdb 100644 --- a/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavacParser.java +++ b/transpiler/java/com/google/j2cl/transpiler/frontend/javac/JavacParser.java @@ -26,7 +26,6 @@ import com.google.j2cl.transpiler.ast.Library; import com.google.j2cl.transpiler.ast.TypeDescriptors; import com.google.j2cl.transpiler.frontend.common.FrontendOptions; -import com.google.j2cl.transpiler.frontend.common.PackageInfoCache; import com.sun.source.tree.CompilationUnitTree; import com.sun.tools.javac.api.JavacTaskImpl; import com.sun.tools.javac.file.JavacFileManager; @@ -61,9 +60,6 @@ public JavacParser(Problems problems) { /** Returns a map from file paths to compilation units after Javac parsing. */ @Nullable public Library parseFiles(FrontendOptions options) { - // Records information about package-info files supplied as byte code. - PackageInfoCache.init(options.getClasspaths(), problems); - ImmutableList filePaths = options.getSources(); if (filePaths.isEmpty()) { return Library.newEmpty();