Skip to content

Commit

Permalink
Pretty much working now
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel1464 committed Nov 27, 2024
1 parent 15b5b98 commit 844d498
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,15 @@ private void processEpilogue(RoundEnvironment roundEnv) {
for (TypeElement clazz : classes) {
try {
warnOfNonLoggableElements(clazz);
m_loggerGenerator.writeLoggerFile(clazz);

boolean isMainRobotClass = false;
if (processingEnv.getTypeUtils().isAssignable(clazz.getSuperclass(), robotBaseClass)) {
mainRobotClasses.add(clazz);
isMainRobotClass = true;
}
boolean canBeLogged = m_loggerGenerator.writeLoggerFile(clazz, isMainRobotClass);
if (canBeLogged) {
loggerClassNames.add(StringUtils.loggerClassName(clazz));
}

loggerClassNames.add(StringUtils.loggerClassName(clazz));
} catch (IOException e) {
processingEnv
.getMessager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public String logInvocation(Element element) {
var loggableSubtypes =
m_loggedTypes.stream()
.filter(
l -> m_processingEnv.getTypeUtils().isAssignable(l.asType(), declaredType.asType()))
l -> l.getAnnotation(Logged.class) != null && m_processingEnv.getTypeUtils().isAssignable(l.asType(), declaredType.asType()))
.sorted(inheritanceComparatorFor(declaredType))
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 void writeLoggerFile(TypeElement clazz) throws IOException {
public boolean writeLoggerFile(TypeElement clazz, boolean isMainRobotClass) throws IOException {
var config = clazz.getAnnotation(Logged.class);
if (config == null) { config = kDefaultConfig; }
boolean requireExplicitOptIn = config.strategy() == Logged.Strategy.OPT_IN;
Expand Down Expand Up @@ -118,6 +118,12 @@ public void writeLoggerFile(TypeElement clazz) throws IOException {
.filter(this::isLoggable)
.filter(e -> !isSimpleGetterMethodForLoggedField(e, fieldsToLog))
.toList();

// Nothing to log; continue
// Robot classes must have a generated logger
if (fieldsToLog.isEmpty() && methodsToLog.isEmpty() && !isMainRobotClass) {
return false;
}

// Validate no name collisions
Map<String, List<Element>> usedNames =
Expand Down Expand Up @@ -160,6 +166,7 @@ public void writeLoggerFile(TypeElement clazz) throws IOException {
});

writeLoggerFile(clazz.getQualifiedName().toString(), config, fieldsToLog, methodsToLog);
return true;
}

private void writeLoggerFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void basicOptInLogging() {
class Example {
@Logged double x;
@Logged double y;
@Logged public double y;
public double z;
}
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ 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<EpilogueConfiguration> configurator) {
configurator.accept(config);
}
Expand Down Expand Up @@ -73,6 +71,7 @@ class Example extends edu.wpi.first.wpilibj.RobotBase {
public void startCompetition() {}
@Override
public void endCompetition() {}
private double x = 0.0;
}
""";

Expand Down Expand Up @@ -116,8 +115,7 @@ void timedRobot() {
package edu.wpi.first.epilogue;
@Logged
class Example extends edu.wpi.first.wpilibj.TimedRobot {
}
class Example extends edu.wpi.first.wpilibj.TimedRobot { }
""";

String expected =
Expand Down Expand Up @@ -192,10 +190,14 @@ void multipleRobots() {
package edu.wpi.first.epilogue;
@Logged
class AlphaBot extends edu.wpi.first.wpilibj.TimedRobot { }
class AlphaBot extends edu.wpi.first.wpilibj.TimedRobot {
double x = 0.0;
}
@Logged
class BetaBot extends edu.wpi.first.wpilibj.TimedRobot { }
class BetaBot extends edu.wpi.first.wpilibj.TimedRobot {
double x = 0.0;
}
""";

String expected =
Expand Down

0 comments on commit 844d498

Please sign in to comment.