mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Merge branch 'main' into 2027
This commit is contained in:
@@ -68,7 +68,9 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
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
|
||||
@@ -267,12 +269,18 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
processingEnv
|
||||
.getMessager()
|
||||
.printMessage(
|
||||
Diagnostic.Kind.NOTE,
|
||||
"[EPILOGUE] Excluded from logs because " + type + " is not a loggable data type",
|
||||
element);
|
||||
var classConfig = element.getEnclosingElement().getAnnotation(Logged.class);
|
||||
|
||||
if (classConfig == null || classConfig.warnForNonLoggableTypes()) {
|
||||
// Not loggable and not explicitly opted out of logging; print a warning message
|
||||
processingEnv
|
||||
.getMessager()
|
||||
.printMessage(
|
||||
Diagnostic.Kind.NOTE,
|
||||
"[EPILOGUE] Excluded from logs because " + type + " is not a loggable data type",
|
||||
element);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,11 @@ public class LoggerGenerator {
|
||||
public Naming defaultNaming() {
|
||||
return Naming.USE_CODE_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean warnForNonLoggableTypes() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public LoggerGenerator(ProcessingEnvironment processingEnv, List<ElementHandler> handlers) {
|
||||
|
||||
@@ -1772,7 +1772,7 @@ class AnnotationProcessorTest {
|
||||
"""
|
||||
package edu.wpi.first.epilogue;
|
||||
|
||||
@Logged
|
||||
@Logged(warnForNonLoggableTypes = true)
|
||||
class Example {
|
||||
Throwable t;
|
||||
}
|
||||
@@ -1974,6 +1974,37 @@ class AnnotationProcessorTest {
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user