From 0bc96270f1f8efdac0cb2633ee2d54b7f045c011 Mon Sep 17 00:00:00 2001 From: Daniel Chen Date: Wed, 27 Nov 2024 11:03:09 -0500 Subject: [PATCH] Reverted problematic changes --- .../first/epilogue/processor/AnnotationProcessor.java | 10 ++++------ .../wpi/first/epilogue/processor/LoggerGenerator.java | 8 ++++---- .../epilogue/processor/EpilogueGeneratorTest.java | 10 ++++------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java index 8a7ec2bdcf5..d9094b10106 100644 --- a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java +++ b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java @@ -355,15 +355,13 @@ private void processEpilogue(RoundEnvironment roundEnv) { for (TypeElement clazz : classes) { try { warnOfNonLoggableElements(clazz); - boolean isMainRobotClass = false; - if (processingEnv.getTypeUtils().isAssignable(clazz.getSuperclass(), robotBaseClass)) { - mainRobotClasses.add(clazz); - isMainRobotClass = true; - } - boolean canBeLogged = m_loggerGenerator.writeLoggerFile(clazz, isMainRobotClass); + boolean canBeLogged = m_loggerGenerator.writeLoggerFile(clazz); if (canBeLogged) { loggerClassNames.add(StringUtils.loggerClassName(clazz)); } + if (processingEnv.getTypeUtils().isAssignable(clazz.getSuperclass(), robotBaseClass)) { + mainRobotClasses.add(clazz); + } } catch (IOException e) { processingEnv .getMessager() diff --git a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java index b86be2f0ed4..9bceeb53fe7 100644 --- a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java +++ b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java @@ -79,7 +79,7 @@ private static boolean isBuiltInJavaMethod(ExecutableElement e) { * @param clazz the data type that the logger should support. * @throws IOException if the file could not be written */ - public boolean writeLoggerFile(TypeElement clazz, boolean isMainRobotClass) throws IOException { + public boolean writeLoggerFile(TypeElement clazz) throws IOException { var config = clazz.getAnnotation(Logged.class); if (config == null) { config = kDefaultConfig; } boolean requireExplicitOptIn = config.strategy() == Logged.Strategy.OPT_IN; @@ -119,9 +119,9 @@ public boolean writeLoggerFile(TypeElement clazz, boolean isMainRobotClass) thro .filter(e -> !isSimpleGetterMethodForLoggedField(e, fieldsToLog)) .toList(); - // Nothing to log; continue - // Robot classes must have a generated logger - if (fieldsToLog.isEmpty() && methodsToLog.isEmpty() && !isMainRobotClass) { + // If there is no log annotation and no fields to log, don't generate a logger + // logger is still generated for @Logged classes for compatibility reasons + if (fieldsToLog.isEmpty() && methodsToLog.isEmpty() && clazz.getAnnotation(Logged.class) == null) { return false; } diff --git a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java index 4442e9d8387..171eaf260ca 100644 --- a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java +++ b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/EpilogueGeneratorTest.java @@ -37,6 +37,8 @@ class Example { public final class Epilogue { private static final EpilogueConfiguration config = new EpilogueConfiguration(); + + public static final ExampleLogger exampleLogger = new ExampleLogger(); public static void configure(java.util.function.Consumer configurator) { configurator.accept(config); @@ -190,14 +192,10 @@ void multipleRobots() { package edu.wpi.first.epilogue; @Logged - class AlphaBot extends edu.wpi.first.wpilibj.TimedRobot { - double x = 0.0; - } + class AlphaBot extends edu.wpi.first.wpilibj.TimedRobot { } @Logged - class BetaBot extends edu.wpi.first.wpilibj.TimedRobot { - double x = 0.0; - } + class BetaBot extends edu.wpi.first.wpilibj.TimedRobot { } """; String expected =