Use annotations for operation descriptions#851
Use annotations for operation descriptions#851JLLeitschuh merged 3 commits intoWPIRoboticsProjects:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #851 +/- ##
============================================
+ Coverage 51.45% 51.71% +0.25%
- Complexity 1146 1158 +12
============================================
Files 247 247
Lines 7956 7812 -144
Branches 531 533 +2
============================================
- Hits 4094 4040 -54
+ Misses 3677 3592 -85
+ Partials 185 180 -5 |
|
As an FYI the branch for CUDA support will be based on this for dependency injection |
| /** | ||
| * Creates an operation description from a {@link Description @Description} annotation on | ||
| * an operation subclass. | ||
| */ |
There was a problem hiding this comment.
I think (and I'm totally okay with being wrong) but I think this code could go inside of Description because it is a fully qualified class and can have its own logic inside it.
There was a problem hiding this comment.
No can do. Annotation interfaces can't have methods.
| @Parameters(name = "{index}: Operation({0})") | ||
| public static Collection<Object[]> data() { | ||
| EventBus eventBus = new EventBus(); | ||
| System.out.println("data()"); |
There was a problem hiding this comment.
Why did PMD not find this...
There was a problem hiding this comment.
I don't think PMD runs on test files
Re-enable CompatibilityTest. Fix some backwards compatbility issues. Not really a fan of injecting the Injector into the Operations class. Need to see if there's a better solution
5f1d0c6 to
aaed76b
Compare
| import edu.wpi.grip.core.util.Icon; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.inject.Inject; |
There was a problem hiding this comment.
Can you use javax.inject.Inject instead?
There was a problem hiding this comment.
Prefer JSR-330's annotations and Provider interface.
There was a problem hiding this comment.
Oh. That's going to be a lot of code changed because both are used everywhere. Should probably add a checkstyle rule for this in a different PR
| * {@link Size}s are converted into this. | ||
| */ | ||
| @Immutable | ||
| @PublishableProxy({Point.class, Size.class}) |
There was a problem hiding this comment.
Do you want to use the constructor parameter to get the type?
Any reason why the type should be specified in the parameter and in the annotation?
There was a problem hiding this comment.
We could iterate over all public constructors, but I like how this specifies exactly what's being proxied. It could also run into issues with publicly accessible helper constructors eg Vector2D(double, double)
| // @Parameters is called before @BeforeClass, so we call it manually in a static initializer block | ||
| // @BeforeClass | ||
| public static void setUpClass() { | ||
| System.out.println("setUpClass"); |
There was a problem hiding this comment.
This still needs to be addressed.
|
|
||
| @AfterClass | ||
| public static void tearDownClass() { | ||
| System.out.println("tearDownClass()"); |
There was a problem hiding this comment.
This still needs to be addressed.
| OperationsFactory.create(eventBus).addOperations(); | ||
| //CVOperations.addOperations(eventBus); | ||
| OperationsFactory.create(eventBus, injector).addOperations(); | ||
| OperationsFactory.createCV(eventBus).addOperations(); |
There was a problem hiding this comment.
Why was this commented out before?
| </grip:Input> | ||
| <grip:Input step="34" socket="2"> | ||
| <value>0.0</value> | ||
| </grip:Input> |
There was a problem hiding this comment.
It was incompatible with the new version of the operation. I think the compatibility test was disabled for so long that it was never picked up
There was a problem hiding this comment.
So somewhere along the way we had a breaking change that we never did a major version bump for?
|
@JLLeitschuh want to revisit this? |
|
|
||
| /** | ||
| * The name of the icon to use to display the operation. If empty ({@code ""}), no icon will be | ||
| * shown. The icon should be located in {@code /edu/wpi/grip/ui/icons/}. |
There was a problem hiding this comment.
Is this the right use of this javadoc annotation? Does it render correctly?
There was a problem hiding this comment.
Yeah, it's just a shortcut for <code>...</code>
|
|
||
| private abstract static class SimpleConverter<J, M extends Message> extends | ||
| JavaToMessageConverter<J, M> { | ||
| JavaToMessageConverter<J, M> { |
There was a problem hiding this comment.
Why is this whitespace diff here?
|
|
||
| if (!operationMetaData.isPresent()) { | ||
| throw new ConversionException("Unknown operation: " + operationName); | ||
| throw new ConversionException(String.format("Unknown operation: %s. Known operations: %s", |
There was a problem hiding this comment.
Perhaps "Unknown operation: %s. did not match any known operations: %s"
| Main.class, | ||
| CoreCommandLineHelper.class | ||
| CoreCommandLineHelper.class, | ||
| OperationDescription.class |
There was a problem hiding this comment.
Why are you adding this class? Why not simply make it pass?
| Injector injector, | ||
| FileManager fileManager, | ||
| InputSocket.Factory isf, | ||
| OutputSocket.Factory osf) { |
There was a problem hiding this comment.
Does the OutputSocket.Factory still get used anymore?
|
I cleared up my own review comments and I'll merge this if the CI passes. |
JLLeitschuh
left a comment
There was a problem hiding this comment.
Looks good to me after making my own changes to the PR. Great work @SamCarlberg I know that this was a significant amount of rewrite work. Thanks for your dedication.
Operations are created via the Guice
Injector, making it much easier to use dependency injection in operations. Operations are also discovered at startup as long as they have an@Descriptionannotation on the class