Skip to content

Commit

Permalink
rename annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
shueja committed Nov 9, 2023
1 parent 7aa6422 commit 70a1dbc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
39 changes: 21 additions & 18 deletions monologue/src/main/java/monologue/Monologue.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static String methodNameFix(String name) {

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface BothLog {
public @interface LogBoth {
public String path() default "";

public boolean once() default false;
Expand All @@ -66,15 +66,15 @@ private static String methodNameFix(String name) {
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface DataLog {
public @interface LogFile {
public boolean once() default false;

public int level() default 0;
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface NTLog {
public @interface LogNT {
public boolean once() default false;

public int level() default 0;
Expand Down Expand Up @@ -104,6 +104,9 @@ private static Supplier<?> getSupplier(Method method, Logged loggable) {
};
}

public static void setupLogging(Logged loggable, String rootPath) {
Monologue.setupLogging(loggable, rootPath, true);
}
public static void setupLogging(Logged loggable, String rootPath, boolean createDataLog) {
System.out.println(rootPath);
loggedRegistry.put(loggable, rootPath);
Expand Down Expand Up @@ -205,13 +208,13 @@ public static void setupLogging(Logged loggable, String rootPath, boolean create
DriverStation.reportWarning("Tried to log invalid type " + name + "(" + field.getType() + ") in " + ss_name, false);
continue;
}
if ((field.isAnnotationPresent(DataLog.class) || field.isAnnotationPresent(BothLog.class))
if ((field.isAnnotationPresent(LogFile.class) || field.isAnnotationPresent(LogBoth.class))
&& createDataLog) {
dataLogger.startLog();

DataLog annotation = field.getAnnotation(DataLog.class);
LogFile annotation = field.getAnnotation(LogFile.class);
if (annotation == null) {
BothLog logAnnotation = field.getAnnotation(BothLog.class);
LogBoth logAnnotation = field.getAnnotation(LogBoth.class);
annotationPath = logAnnotation.path();
oneShot = logAnnotation.once();
level = logAnnotation.level();
Expand All @@ -228,11 +231,11 @@ public static void setupLogging(Logged loggable, String rootPath, boolean create
dataLogger.helper(getSupplier(field, loggable), type, key, oneShot, level);
}
}
if (field.isAnnotationPresent(NTLog.class) || field.isAnnotationPresent(BothLog.class)) {
if (field.isAnnotationPresent(LogNT.class) || field.isAnnotationPresent(LogBoth.class)) {

NTLog annotation = field.getAnnotation(NTLog.class);
LogNT annotation = field.getAnnotation(LogNT.class);
if (annotation == null) {
BothLog logAnnotation = field.getAnnotation(BothLog.class);
LogBoth logAnnotation = field.getAnnotation(LogBoth.class);
annotationPath = logAnnotation.path();
oneShot = logAnnotation.once();
level = logAnnotation.level();
Expand All @@ -251,16 +254,16 @@ public static void setupLogging(Logged loggable, String rootPath, boolean create
}

for (Method method :getInheritedMethods(loggable.getClass())) {
if ((method.isAnnotationPresent(DataLog.class) || method.isAnnotationPresent(BothLog.class))
if ((method.isAnnotationPresent(LogFile.class) || method.isAnnotationPresent(LogBoth.class))
&& createDataLog) {
dataLogger.startLog();
method.setAccessible(true);
String annotationPath = "";
boolean oneShot;
int level;
DataLog annotation = method.getAnnotation(DataLog.class);
LogFile annotation = method.getAnnotation(LogFile.class);
if (annotation == null) {
BothLog logAnnotation = method.getAnnotation(BothLog.class);
LogBoth logAnnotation = method.getAnnotation(LogBoth.class);
annotationPath = logAnnotation.path();
oneShot = logAnnotation.once();
level = logAnnotation.level();
Expand All @@ -273,18 +276,18 @@ public static void setupLogging(Logged loggable, String rootPath, boolean create

DataType type = DataType.fromClass(method.getReturnType());
if (method.getParameterCount() > 0) {
throw new IllegalArgumentException("Cannot have parameters on a DataLog method");
throw new IllegalArgumentException("Cannot have parameters on a LogFile method");
}
dataLogger.helper(getSupplier(method, loggable), type, path, oneShot, level);
}
if (method.isAnnotationPresent(NTLog.class) || method.isAnnotationPresent(BothLog.class)) {
if (method.isAnnotationPresent(LogNT.class) || method.isAnnotationPresent(LogBoth.class)) {
method.setAccessible(true);
String annotationPath = "";
boolean oneShot;
int level;
NTLog annotation = method.getAnnotation(NTLog.class);
LogNT annotation = method.getAnnotation(LogNT.class);
if (annotation == null) {
BothLog logAnnotation = method.getAnnotation(BothLog.class);
LogBoth logAnnotation = method.getAnnotation(LogBoth.class);
annotationPath = logAnnotation.path();
oneShot = logAnnotation.once();
level = logAnnotation.level();
Expand All @@ -295,7 +298,7 @@ public static void setupLogging(Logged loggable, String rootPath, boolean create
String key = annotationPath.equals("") ? ss_name + "/" + method.getName() : annotationPath;
DataType type = DataType.fromClass(method.getReturnType());
if (method.getParameterCount() > 0) {
throw new IllegalArgumentException("Cannot have parameters on a DataLog method");
throw new IllegalArgumentException("Cannot have parameters on a LogFile method");
}
ntLogger.helper(getSupplier(method, loggable), type, key, oneShot, level);
}
Expand All @@ -311,7 +314,7 @@ public static void updateNT() {
ntLogger.update();
}

public static void updateDataLog() {
public static void updateFileLog() {
dataLogger.update();
}

Expand Down
2 changes: 1 addition & 1 deletion test-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'

implementation "com.github.Oblarg:Oblog:5.1.0"
implementation 'com.github.shueja-personal:Monologue:v0.0.4-alpha8'
implementation 'com.github.shueja-personal:Monologue:v1.0.0-alpha1'
}

repositories {
Expand Down
36 changes: 18 additions & 18 deletions test-project/src/main/java/frc/robot/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,69 @@

package frc.robot;

import monologue.Monologue.BothLog;
import monologue.Monologue.LogBoth;
import monologue.Logged;
import edu.wpi.first.math.geometry.*;

/** Add your docs here. */
public class Geometry implements Logged {
@BothLog
@LogBoth
public String getStringPath()
{
return getFullPath();
}
@BothLog private Pose2d m_pose2d = new Pose2d();
@LogBoth private Pose2d m_pose2d = new Pose2d();

@BothLog
@LogBoth
private Pose2d getPose2d() {
return m_pose2d;
}

@BothLog private Translation2d m_translation2d = new Translation2d();
@LogBoth private Translation2d m_translation2d = new Translation2d();

@BothLog
@LogBoth
private Translation2d getTranslation2d() {
return m_translation2d;
}

@BothLog private Transform2d m_transform2d = new Transform2d();
@LogBoth private Transform2d m_transform2d = new Transform2d();

@BothLog
@LogBoth
private Transform2d getTransform2d() {
return m_transform2d;
}

@BothLog private Rotation2d m_rotation2d = new Rotation2d();
@LogBoth private Rotation2d m_rotation2d = new Rotation2d();

@BothLog
@LogBoth
private Rotation2d getRotation2d() {
return m_rotation2d;
}

@BothLog private Pose3d m_pose3d = new Pose3d();
@LogBoth private Pose3d m_pose3d = new Pose3d();

@BothLog
@LogBoth
private Pose3d getPose3d() {
return m_pose3d;
}

@BothLog private Translation3d m_translation3d = new Translation3d();
@LogBoth private Translation3d m_translation3d = new Translation3d();

@BothLog
@LogBoth
private Translation3d getTranslation3d() {
return m_translation3d;
}

@BothLog private Transform3d m_transform3d = new Transform3d();
@LogBoth private Transform3d m_transform3d = new Transform3d();

@BothLog
@LogBoth
private Transform3d getTransform3d() {
return m_transform3d;
}

@BothLog private Rotation3d m_rotation3d = new Rotation3d();
@LogBoth private Rotation3d m_rotation3d = new Rotation3d();

@BothLog
@LogBoth
private Rotation3d getRotation3d() {
return m_rotation3d;
}
Expand Down
8 changes: 4 additions & 4 deletions test-project/src/main/java/frc/robot/Internal.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package frc.robot;

import monologue.Monologue.BothLog;
import monologue.Monologue.LogBoth;
import monologue.Logged;
import io.github.oblarg.oblog.Loggable;
import io.github.oblarg.oblog.annotations.Log;
Expand Down Expand Up @@ -30,17 +30,17 @@ public String configureLogName() {
}

// @Log
// @NTLog
// @LogNT
// public String name="name";
// @Log
// @DataLog
// @LogFile
public String getName() {
calls++;
return showName;
}

@Log
@BothLog
@LogBoth
public double getNumber() {
calls++;
return calls + calls / 1000.0;
Expand Down
16 changes: 8 additions & 8 deletions test-project/src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package frc.robot;

import monologue.Monologue;
import monologue.Monologue.BothLog;
import monologue.Monologue.DataLog;
import monologue.Monologue.NTLog;
import monologue.Monologue.LogBoth;
import monologue.Monologue.LogFile;
import monologue.Monologue.LogNT;
import monologue.Logged;
import edu.wpi.first.math.filter.LinearFilter;
import edu.wpi.first.math.geometry.Pose2d;
Expand All @@ -30,7 +30,7 @@
* project.
*/
public class Robot extends TimedRobot implements Logged, Loggable {
@BothLog(once=true) private int samples = 0;
@LogBoth(once=true) private int samples = 0;
boolean useOblog = false;
boolean dataLog = false;

Expand All @@ -41,10 +41,10 @@ public class Robot extends TimedRobot implements Logged, Loggable {

private Geometry m_geometry = new Geometry();

@NTLog @DataLog private Field2d field = new Field2d();
@LogNT @LogFile private Field2d field = new Field2d();

@BothLog private Mechanism2d mech = new Mechanism2d(1, 1);
@BothLog private long[] array = {0, 1, 2};
@LogBoth private Mechanism2d mech = new Mechanism2d(1, 1);
@LogBoth private long[] array = {0, 1, 2};

/**
* This function is run when the robot is first started up and should be used for any
Expand All @@ -68,7 +68,7 @@ public void robotInit() {
put("imperative", new Transform2d());
}

@BothLog
@LogBoth
public String getStringPath()
{
return getFullPath();
Expand Down

0 comments on commit 70a1dbc

Please sign in to comment.