Skip to content
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

Use annotations for operation descriptions #851

Conversation

SamCarlberg
Copy link
Member

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 @Description annotation on the class

@SamCarlberg SamCarlberg requested a review from JLLeitschuh May 5, 2017 20:38
@codecov-io
Copy link

codecov-io commented May 5, 2017

Codecov Report

Merging #851 into master will increase coverage by 0.25%.
The diff coverage is 74.5%.

@@             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

@SamCarlberg
Copy link
Member Author

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.
*/
public static OperationDescription from(Description description) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No can do. Annotation interfaces can't have methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thats fine.

@Parameters(name = "{index}: Operation({0})")
public static Collection<Object[]> data() {
EventBus eventBus = new EventBus();
System.out.println("data()");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did PMD not find this...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@SamCarlberg SamCarlberg force-pushed the operation-description-annotations branch from 5f1d0c6 to aaed76b Compare May 6, 2017 21:28

import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use javax.inject.Inject instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer JSR-330's annotations and Provider interface.

https://github.com/google/guice/wiki/JSR330

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -11,6 +11,7 @@
* {@link Size}s are converted into this.
*/
@Immutable
@PublishableProxy({Point.class, Size.class})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine. This makes sense.

// @Parameters is called before @BeforeClass, so we call it manually in a static initializer block
// @BeforeClass
public static void setUpClass() {
System.out.println("setUpClass");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this please.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be addressed.


@AfterClass
public static void tearDownClass() {
System.out.println("tearDownClass()");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this please.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be addressed.

OperationsFactory.create(eventBus).addOperations();
//CVOperations.addOperations(eventBus);
OperationsFactory.create(eventBus, injector).addOperations();
OperationsFactory.createCV(eventBus).addOperations();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this commented out before?

@@ -405,9 +405,6 @@
<grip:Input step="34" socket="1">
<value>COLOR_BGR2GRAY</value>
</grip:Input>
<grip:Input step="34" socket="2">
<value>0.0</value>
</grip:Input>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So somewhere along the way we had a breaking change that we never did a major version bump for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this?

@SamCarlberg
Copy link
Member Author

@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/}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right use of this javadoc annotation? Does it render correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's just a shortcut for <code>...</code>

@@ -125,7 +136,7 @@ public void convert(J javaType, Message message, MessageFactory messageFactory)
}

private abstract static class SimpleConverter<J, M extends Message> extends
JavaToMessageConverter<J, M> {
JavaToMessageConverter<J, M> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this whitespace diff here?

@@ -61,7 +62,12 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
.getOperationByName(operationName);

if (!operationMetaData.isPresent()) {
throw new ConversionException("Unknown operation: " + operationName);
throw new ConversionException(String.format("Unknown operation: %s. Known operations: %s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps "Unknown operation: %s. did not match any known operations: %s"

@@ -27,7 +27,8 @@ public CoreSanityTest() {
ManualPipelineRunner.class,
SubtractionOperation.class,
Main.class,
CoreCommandLineHelper.class
CoreCommandLineHelper.class,
OperationDescription.class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding this class? Why not simply make it pass?

@Named("ntManager") MapNetworkPublisherFactory ntManager,
@Named("httpManager") MapNetworkPublisherFactory httpManager,
@Named("rosManager") ROSNetworkPublisherFactory rosManager,
Injector injector,
FileManager fileManager,
InputSocket.Factory isf,
OutputSocket.Factory osf) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the OutputSocket.Factory still get used anymore?

@JLLeitschuh
Copy link
Member

I cleared up my own review comments and I'll merge this if the CI passes.

Copy link
Member

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JLLeitschuh JLLeitschuh merged commit 978b4a9 into WPIRoboticsProjects:master Dec 15, 2017
@SamCarlberg SamCarlberg deleted the operation-description-annotations branch April 19, 2019 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants