Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 28, 2024
1 parent b7d58a9 commit 2642d4a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,29 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
}

/**
* Gets the set of all loggable types in the compilation unit. A type is considered loggable if
* it is directly annotated with {@code @Logged} or contains a field or method with a
* {@code @Logged} annotation.
* Gets the set of all loggable types in the compilation unit. A type is considered loggable if it
* is directly annotated with {@code @Logged} or contains a field or method with a {@code @Logged}
* annotation.
*
* @param roundEnv the compilation round environment
*
* @return the set of all loggable types
*/
private Set<TypeElement> getLoggedTypes(RoundEnvironment roundEnv) {
return Stream.concat(
// 1. All type elements (classes, interfaces, or enums) with the @Logged annotation
roundEnv.getRootElements()
.stream()
.filter(e -> e instanceof TypeElement)
.map(e -> (TypeElement) e)
.filter(t -> t.getAnnotation(Logged.class) != null),
// 2. All type elements containing a field or method with the @Logged annotation
roundEnv.getElementsAnnotatedWith(Logged.class)
.stream()
.filter(e -> e instanceof VariableElement || e instanceof ExecutableElement)
.map(e -> e.getEnclosingElement())
.filter(e -> e instanceof TypeElement)
.map(e -> (TypeElement) e)
).collect(Collectors.toSet()); // Collect to a set to avoid duplicates
// 1. All type elements (classes, interfaces, or enums) with the @Logged annotation
roundEnv.getRootElements().stream()
.filter(e -> e instanceof TypeElement)
.map(e -> (TypeElement) e)
.filter(t -> t.getAnnotation(Logged.class) != null),
// 2. All type elements containing a field or method with the @Logged annotation
roundEnv.getElementsAnnotatedWith(Logged.class).stream()
.filter(e -> e instanceof VariableElement || e instanceof ExecutableElement)
.map(e -> e.getEnclosingElement())
.filter(e -> e instanceof TypeElement)
.map(e -> (TypeElement) e))
.collect(Collectors.toSet()); // Collect to a set to avoid duplicates
}

private boolean validateFields(Set<? extends Element> annotatedElements) {
var fields =
annotatedElements.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,33 @@ public class LoggerGenerator {
LoggerGenerator::isBuiltInJavaMethod;
private final ProcessingEnvironment m_processingEnv;
private final List<ElementHandler> m_handlers;
private final Logged kDefaultConfig = new Logged() {
@Override public Class<? extends Annotation> annotationType() { return Logged.class; }
@Override public String name() { return ""; }
@Override public Strategy strategy() { return Strategy.OPT_IN; }
@Override public Importance importance() { return Importance.DEBUG; }
@Override public Naming defaultNaming() { return Naming.USE_CODE_NAME; }
};
private final Logged kDefaultConfig =
new Logged() {
@Override
public Class<? extends Annotation> annotationType() {
return Logged.class;
}

@Override
public String name() {
return "";
}

@Override
public Strategy strategy() {
return Strategy.OPT_IN;
}

@Override
public Importance importance() {
return Importance.DEBUG;
}

@Override
public Naming defaultNaming() {
return Naming.USE_CODE_NAME;
}
};

public LoggerGenerator(ProcessingEnvironment processingEnv, List<ElementHandler> handlers) {
this.m_processingEnv = processingEnv;
Expand Down Expand Up @@ -81,7 +101,9 @@ private static boolean isBuiltInJavaMethod(ExecutableElement e) {
*/
public void writeLoggerFile(TypeElement clazz) throws IOException {
var config = clazz.getAnnotation(Logged.class);
if (config == null) { config = kDefaultConfig; }
if (config == null) {
config = kDefaultConfig;
}
boolean requireExplicitOptIn = config.strategy() == Logged.Strategy.OPT_IN;

Predicate<Element> notSkipped = LoggerGenerator::isNotSkipped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void update(DataLogger dataLogger, Example object) {

assertLoggerGenerates(source, expectedGeneratedSource);
}

@Test
void basicOptInLogging() {
String source =
Expand All @@ -70,7 +70,7 @@ class Example {
@Logged double y;
}
""";

String expectedGeneratedSource =
"""
package edu.wpi.first.epilogue;
Expand All @@ -94,7 +94,7 @@ public void update(DataLogger dataLogger, Example object) {
}
}
""";

assertLoggerGenerates(source, expectedGeneratedSource);
}

Expand Down Expand Up @@ -1334,11 +1334,11 @@ void nestedImplicit() {
String source =
"""
package edu.wpi.first.epilogue;
class Implicit {
@Logged double x;
}
class Example {
@Logged Implicit i;
}
Expand Down

0 comments on commit 2642d4a

Please sign in to comment.