mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user