[epilogue] Make nonloggable type warnings configurable (#7792)

Now a flag at the class level controls whether warning messages are printed.

Defaults to false (no warning messages).
This commit is contained in:
Sam Carlberg
2025-02-19 00:48:51 -05:00
committed by GitHub
parent 13626063dc
commit bd2211119f
4 changed files with 26 additions and 7 deletions

View File

@@ -269,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;
}

View File

@@ -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) {

View File

@@ -1772,7 +1772,7 @@ class AnnotationProcessorTest {
"""
package edu.wpi.first.epilogue;
@Logged
@Logged(warnForNonLoggableTypes = true)
class Example {
Throwable t;
}

View File

@@ -124,4 +124,12 @@ public @interface Logged {
* for all logged fields and methods in an annotated class
*/
Naming defaultNaming() default Naming.USE_CODE_NAME;
/**
* Class-level only: if {@link #strategy()} is {@link Strategy#OPT_OUT}, this can be used to quiet
* the warnings that are printed for non-loggable fields and methods detected within the class.
*
* @return true if warnings should be printed, or false if warnings should not be printed
*/
boolean warnForNonLoggableTypes() default false;
}