From fd046b06f6a1600647495cc1e7ad322191cb349e Mon Sep 17 00:00:00 2001 From: wilsonwatson Date: Wed, 31 Jul 2024 05:47:07 -0500 Subject: [PATCH] mixins --- .gitignore | 6 +++- .idea/gradle.xml | 1 + gen_io_types/src/main.rs | 2 +- .../{serde/Serde.java => mixin/Final.java} | 22 +++++++------- .../java/org/frc5572/util/mixin/Mixin.java | 18 ++++++++++++ .../Aliases.java => mixin/Overwrite.java} | 23 +++++++-------- .../java/org/frc5572/util/mixin/Shadow.java | 11 +++++++ .../org/frc5572/util/mixin/inject/At.java | 11 +++++++ .../org/frc5572/util/mixin/inject/Inject.java | 11 +++++++ .../frc5572/util/profiler/AutoProfile.java | 4 --- .../java/org/frc5572/util/serde/Alias.java | 15 ---------- .../java/org/frc5572/util/serde/Casing.java | 12 -------- .../frc5572/util/serde/DefaultSerializer.java | 6 ---- .../java/org/frc5572/util/serde/Rename.java | 13 --------- .../org/frc5572/util/serde/RenameAll.java | 13 --------- .../org/frc5572/util/serde/Serialize.java | 9 ------ .../frc5572/util/serde/SingleSerdeItem.java | 7 ----- .../java/org/frc5572/util/serde/Skip.java | 5 ---- .../java/org/frc5572/util/serde/With.java | 13 --------- plugin/build.gradle | 29 +++++++++++++++++++ .../kotlin/org/frc5572/mixin/MixinPlugin.kt | 19 ++++++++++++ .../org/frc5572/robotools/RobotProcessor.java | 4 +-- .../main/kotlin/org/frc5572/robotools/Test.kt | 5 ---- settings.gradle | 1 + 24 files changed, 131 insertions(+), 129 deletions(-) rename lib/src/main/java/org/frc5572/util/{serde/Serde.java => mixin/Final.java} (53%) mode change 100755 => 100644 create mode 100644 lib/src/main/java/org/frc5572/util/mixin/Mixin.java rename lib/src/main/java/org/frc5572/util/{serde/Aliases.java => mixin/Overwrite.java} (51%) mode change 100755 => 100644 create mode 100644 lib/src/main/java/org/frc5572/util/mixin/Shadow.java create mode 100644 lib/src/main/java/org/frc5572/util/mixin/inject/At.java create mode 100644 lib/src/main/java/org/frc5572/util/mixin/inject/Inject.java delete mode 100755 lib/src/main/java/org/frc5572/util/profiler/AutoProfile.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/Alias.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/Casing.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/DefaultSerializer.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/Rename.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/RenameAll.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/Serialize.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/Skip.java delete mode 100755 lib/src/main/java/org/frc5572/util/serde/With.java create mode 100644 plugin/build.gradle create mode 100644 plugin/src/main/kotlin/org/frc5572/mixin/MixinPlugin.kt delete mode 100644 processor/src/main/kotlin/org/frc5572/robotools/Test.kt diff --git a/.gitignore b/.gitignore index 44736e7..f7a84da 100644 --- a/.gitignore +++ b/.gitignore @@ -161,4 +161,8 @@ bin/ # Simulation GUI and other tools window save file *-window.json -/src/main/java/org/frc5572/robotools/IOTypes.java \ No newline at end of file +/.idea + +/processor/src/main/java/org/frc5572/robotools/IOTypes.java + +/build \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4f0cdce..e0ada1e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -9,6 +9,7 @@ diff --git a/gen_io_types/src/main.rs b/gen_io_types/src/main.rs index 8ba970d..efc2e5a 100644 --- a/gen_io_types/src/main.rs +++ b/gen_io_types/src/main.rs @@ -89,7 +89,7 @@ async fn main() { } } - let mut outf = std::fs::File::create(source_dir.join("src/main/java/org/frc5572/robotools/IOTypes.java")).unwrap(); + let mut outf = std::fs::File::create(source_dir.join("processor/src/main/java/org/frc5572/robotools/IOTypes.java")).unwrap(); writeln!(&mut outf, "package org.frc5572.robotools;\n").unwrap(); writeln!(&mut outf, "/** Auto-generated list of IO interfaces and classes. */").unwrap(); writeln!(&mut outf, "public class IOTypes {{\n").unwrap(); diff --git a/lib/src/main/java/org/frc5572/util/serde/Serde.java b/lib/src/main/java/org/frc5572/util/mixin/Final.java old mode 100755 new mode 100644 similarity index 53% rename from lib/src/main/java/org/frc5572/util/serde/Serde.java rename to lib/src/main/java/org/frc5572/util/mixin/Final.java index 3be8359..7bed915 --- a/lib/src/main/java/org/frc5572/util/serde/Serde.java +++ b/lib/src/main/java/org/frc5572/util/mixin/Final.java @@ -1,11 +1,11 @@ -package org.frc5572.util.serde; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** File supports serialization to and from a log table. */ -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.TYPE}) -public @interface Serde {} +package org.frc5572.util.mixin; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.CLASS) +public @interface Final { +} diff --git a/lib/src/main/java/org/frc5572/util/mixin/Mixin.java b/lib/src/main/java/org/frc5572/util/mixin/Mixin.java new file mode 100644 index 0000000..fdfd88f --- /dev/null +++ b/lib/src/main/java/org/frc5572/util/mixin/Mixin.java @@ -0,0 +1,18 @@ +package org.frc5572.util.mixin; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.CLASS) +public @interface Mixin { + + Class[] value() default { }; + + String[] targets() default { }; + + int priority() default 1000; + +} diff --git a/lib/src/main/java/org/frc5572/util/serde/Aliases.java b/lib/src/main/java/org/frc5572/util/mixin/Overwrite.java old mode 100755 new mode 100644 similarity index 51% rename from lib/src/main/java/org/frc5572/util/serde/Aliases.java rename to lib/src/main/java/org/frc5572/util/mixin/Overwrite.java index d991826..a349bfd --- a/lib/src/main/java/org/frc5572/util/serde/Aliases.java +++ b/lib/src/main/java/org/frc5572/util/mixin/Overwrite.java @@ -1,12 +1,11 @@ -package org.frc5572.util.serde; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.FIELD}) -public @interface Aliases { - Alias[] value(); -} +package org.frc5572.util.mixin; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.CLASS) +public @interface Overwrite { +} diff --git a/lib/src/main/java/org/frc5572/util/mixin/Shadow.java b/lib/src/main/java/org/frc5572/util/mixin/Shadow.java new file mode 100644 index 0000000..ad05b66 --- /dev/null +++ b/lib/src/main/java/org/frc5572/util/mixin/Shadow.java @@ -0,0 +1,11 @@ +package org.frc5572.util.mixin; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.CLASS) +public @interface Shadow { +} diff --git a/lib/src/main/java/org/frc5572/util/mixin/inject/At.java b/lib/src/main/java/org/frc5572/util/mixin/inject/At.java new file mode 100644 index 0000000..6cd21cf --- /dev/null +++ b/lib/src/main/java/org/frc5572/util/mixin/inject/At.java @@ -0,0 +1,11 @@ +package org.frc5572.util.mixin.inject; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.CLASS) +public @interface At { +} diff --git a/lib/src/main/java/org/frc5572/util/mixin/inject/Inject.java b/lib/src/main/java/org/frc5572/util/mixin/inject/Inject.java new file mode 100644 index 0000000..3899462 --- /dev/null +++ b/lib/src/main/java/org/frc5572/util/mixin/inject/Inject.java @@ -0,0 +1,11 @@ +package org.frc5572.util.mixin.inject; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.CLASS) +public @interface Inject { +} diff --git a/lib/src/main/java/org/frc5572/util/profiler/AutoProfile.java b/lib/src/main/java/org/frc5572/util/profiler/AutoProfile.java deleted file mode 100755 index 42be446..0000000 --- a/lib/src/main/java/org/frc5572/util/profiler/AutoProfile.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.frc5572.util.profiler; - -/** Automatically profile a method. */ -public @interface AutoProfile {} diff --git a/lib/src/main/java/org/frc5572/util/serde/Alias.java b/lib/src/main/java/org/frc5572/util/serde/Alias.java deleted file mode 100755 index 9f9b89b..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/Alias.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.frc5572.util.serde; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Additional name this field could go by. Only used for deserialization, and only used if previous names/aliases are missing in log files. */ -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.FIELD}) -@Repeatable(Aliases.class) -public @interface Alias { - String value(); -} diff --git a/lib/src/main/java/org/frc5572/util/serde/Casing.java b/lib/src/main/java/org/frc5572/util/serde/Casing.java deleted file mode 100755 index 991ff99..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/Casing.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.frc5572.util.serde; - -public enum Casing { - LOWERCASE, - UPPERCASE, - PASCAL_CASE, - CAMEL_CASE, - SNAKE_CASE, - SCREAMING_SNAKE_CASE, - KEBAB_CASE, - SCREAMING_KEBAB_CASE, -} diff --git a/lib/src/main/java/org/frc5572/util/serde/DefaultSerializer.java b/lib/src/main/java/org/frc5572/util/serde/DefaultSerializer.java deleted file mode 100755 index 0aeb06e..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/DefaultSerializer.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.frc5572.util.serde; - -/** Mark this class as the default serialization implementation for a given class. */ -public @interface DefaultSerializer { - Class value(); -} diff --git a/lib/src/main/java/org/frc5572/util/serde/Rename.java b/lib/src/main/java/org/frc5572/util/serde/Rename.java deleted file mode 100755 index 2fee0bf..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/Rename.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.frc5572.util.serde; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Rename field in log table using the given name. */ -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.FIELD}) -public @interface Rename { - String value(); -} diff --git a/lib/src/main/java/org/frc5572/util/serde/RenameAll.java b/lib/src/main/java/org/frc5572/util/serde/RenameAll.java deleted file mode 100755 index e406097..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/RenameAll.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.frc5572.util.serde; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Rename all fields in serialized table using the given case conversions. This is ignored for any field with an explicit {@link Rename} annotation. */ -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.TYPE}) -public @interface RenameAll { - Casing value(); -} diff --git a/lib/src/main/java/org/frc5572/util/serde/Serialize.java b/lib/src/main/java/org/frc5572/util/serde/Serialize.java deleted file mode 100755 index 63fb567..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/Serialize.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.frc5572.util.serde; - -/** Implementation for serialization/deserialization of a type. */ -public interface Serialize { - - void toTable(String name, T value); - T fromTable(String name); - -} diff --git a/lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java b/lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java deleted file mode 100755 index 148b981..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/SingleSerdeItem.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.frc5572.util.serde; - -/** Indicates this item should be updated every call to `periodic()`. */ -public @interface SingleSerdeItem { - String name(); - String updateInputs(); -} diff --git a/lib/src/main/java/org/frc5572/util/serde/Skip.java b/lib/src/main/java/org/frc5572/util/serde/Skip.java deleted file mode 100755 index 82b0592..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/Skip.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.frc5572.util.serde; - - -/** Indicates this field should be skipped during serialization and deserialization. */ -public @interface Skip {} diff --git a/lib/src/main/java/org/frc5572/util/serde/With.java b/lib/src/main/java/org/frc5572/util/serde/With.java deleted file mode 100755 index 9933075..0000000 --- a/lib/src/main/java/org/frc5572/util/serde/With.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.frc5572.util.serde; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** Use a field with type that implements {@link Serialize} for serialization instead of the default. */ -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.FIELD}) -public @interface With { - Class> value(); -} diff --git a/plugin/build.gradle b/plugin/build.gradle new file mode 100644 index 0000000..a9ea49d --- /dev/null +++ b/plugin/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'java-gradle-plugin' + id 'maven-publish' + id 'org.jetbrains.kotlin.jvm' version '1.9.10' +} + +group = "com.github.Frc5572" +var githubProjectName = "RobotTools" + +repositories { + mavenCentral() +} + +gradlePlugin { + plugins { + register("ffstMixin") { + id = "$group.$githubProjectName" + implementationClass = 'org.frc5572.mixin.MixinPlugin' + } + } +} + +kotlin { + jvmToolchain(17) +} + +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile.class).configureEach { + jvmTargetValidationMode = org.jetbrains.kotlin.gradle.dsl.jvm.JvmTargetValidationMode.WARNING +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/org/frc5572/mixin/MixinPlugin.kt b/plugin/src/main/kotlin/org/frc5572/mixin/MixinPlugin.kt new file mode 100644 index 0000000..4983028 --- /dev/null +++ b/plugin/src/main/kotlin/org/frc5572/mixin/MixinPlugin.kt @@ -0,0 +1,19 @@ +package org.frc5572.mixin; + +import org.gradle.api.Project +import org.gradle.api.Plugin +import org.gradle.api.Task +import org.gradle.api.tasks.JavaExec +import org.gradle.jvm.tasks.Jar + +class MixinPlugin: Plugin { + override fun apply(target: Project) { + target.tasks.withType(Jar::class.java) { task -> + task.doLast { + task.outputs.files.forEach { + println(it.path) + } + } + } + } +} \ No newline at end of file diff --git a/processor/src/main/java/org/frc5572/robotools/RobotProcessor.java b/processor/src/main/java/org/frc5572/robotools/RobotProcessor.java index f622930..4e20877 100644 --- a/processor/src/main/java/org/frc5572/robotools/RobotProcessor.java +++ b/processor/src/main/java/org/frc5572/robotools/RobotProcessor.java @@ -57,8 +57,8 @@ public boolean process(Set arg0, RoundEnvironment roundEn } } CompilationData compilationData = new CompilationData(typeElements, processingEnv); - SerdeProcessor.processTypes(compilationData); - AutoProfileProcessor.processTypes(compilationData); +// SerdeProcessor.processTypes(compilationData); +// AutoProfileProcessor.processTypes(compilationData); return false; } diff --git a/processor/src/main/kotlin/org/frc5572/robotools/Test.kt b/processor/src/main/kotlin/org/frc5572/robotools/Test.kt deleted file mode 100644 index 4c87435..0000000 --- a/processor/src/main/kotlin/org/frc5572/robotools/Test.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.frc5572.robotools - -fun test() { - println("Test") -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 1c05833..83b8d01 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,5 +4,6 @@ plugins { } rootProject.name = 'robot-tools' +include('plugin') include('processor') include('lib')