Skip to content

Commit

Permalink
Fix empty package in AutoBazelRepositoryProcessor
Browse files Browse the repository at this point in the history
Add support for when the AutoBazelRepository annotation is placed on a file in a root package (ie. one where there is no package)

fixes bazelbuild#24150

Closes bazelbuild#24161.

PiperOrigin-RevId: 692888334
Change-Id: Idd85e79250f64cf50ca709cf6ad8d025a0db032c
  • Loading branch information
fzakaria authored and bazel-io committed Nov 4, 2024
1 parent 7a63c33 commit d64f326
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/java/runfiles/AutoBazelRepositoryProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ private void emitClass(TypeElement annotatedClass) {
try (PrintWriter out =
new PrintWriter(
processingEnv.getFiler().createSourceFile(generatedClassName).openWriter())) {
out.printf("package %s;\n", generatedClassPackage);

if (!generatedClassPackage.isEmpty()) {
// This annotation may exist on a class which is at the root package
out.printf("package %s;\n", generatedClassPackage);
}
out.printf("\n");
out.printf("class %s {\n", generatedClassSimpleName);
out.printf(" /**\n");
Expand Down

0 comments on commit d64f326

Please sign in to comment.