Skip to content

Commit

Permalink
[8.0.0] Fix empty package in AutoBazelRepositoryProcessor (#24193)
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 #24150

Closes #24161.

PiperOrigin-RevId: 692888334
Change-Id: Idd85e79250f64cf50ca709cf6ad8d025a0db032c

Commit
1560047

Co-authored-by: Farid Zakaria <farid.m.zakaria@gmail.com>
  • Loading branch information
bazel-io and fzakaria authored Nov 4, 2024
1 parent 7a63c33 commit e58341f
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 e58341f

Please sign in to comment.