-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[epilogue] Autogenerate nicer data names by default, not just raw element names #7167
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import edu.wpi.first.epilogue.Logged; | ||
import edu.wpi.first.epilogue.logging.ClassSpecificLogger; | ||
import edu.wpi.first.epilogue.logging.DataLogger; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.lang.model.element.Element; | ||
import javax.lang.model.element.ExecutableElement; | ||
|
@@ -61,14 +62,24 @@ protected TypeMirror dataType(Element element) { | |
* @return the name specified in the {@link Logged @Logged} annotation on the element, if present; | ||
* otherwise, the field or method's name with no modifications | ||
*/ | ||
public String loggedName(Element element) { | ||
public static String loggedName(Element element) { | ||
var elementName = element.getSimpleName().toString(); | ||
var config = element.getAnnotation(Logged.class); | ||
|
||
if (config != null && !config.name().isBlank()) { | ||
return config.name(); | ||
} else { | ||
return elementName; | ||
// Delete common field prefixes (k_Name, m_name, s_name) | ||
elementName = elementName.replaceFirst("^[msk]_", ""); | ||
if (elementName.matches("^k[A-Z]")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Java's default regex engine supports lookaheads, this could be a replace with lookahead rather than an if statement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was to avoid replacing the first capital letter when this was part of the group above, eg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why the lookahead -- |
||
// Drop leading "k" prefix from fields | ||
// (though normally these should be static, and thus not logged) | ||
elementName = elementName.substring(1); | ||
} | ||
|
||
return StringUtils.splitToWords(elementName).stream() | ||
.map(StringUtils::capitalize) | ||
.collect(Collectors.joining(" ")); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_
is also sometimes used as a prefix for private membersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good callout