Skip to content

Commit

Permalink
[epilogue] Fix epilogue with package-info files (wpilibsuite#7749)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamCarlberg authored Jan 30, 2025
1 parent b31fd17 commit 18321e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
customLoggers.putAll(processCustomLoggers(roundEnv, customLogger));
});

// Get all root types (classes and interfaces), excluding packages and modules
roundEnv.getRootElements().stream()
.filter(e -> e instanceof TypeElement)
.filter(
e ->
processingEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,37 @@ public void update(EpilogueBackend backend, Example object) {
assertLoggerGenerates(source, expectedRootLogger);
}

@Test
void doesNotBreakWithPackageInfo() {
String source =
"""
package example;
import edu.wpi.first.epilogue.*;
@Logged
class Example {}
""";

String packageInfo = """
package example;
""";

Compilation compilation =
javac()
.withOptions(kJavaVersionOptions)
.withProcessors(new AnnotationProcessor())
.compile(
JavaFileObjects.forSourceString("example.Example", source),
JavaFileObjects.forSourceString("example.package-info", packageInfo));

assertThat(compilation).succeeded();
compilation.generatedSourceFiles().stream()
.filter(jfo -> jfo.getName().contains("Example"))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Logger file was not generated!"));
}

private void assertCompilationError(
String message, long lineNumber, long col, Diagnostic<? extends JavaFileObject> diagnostic) {
assertAll(
Expand Down

0 comments on commit 18321e5

Please sign in to comment.