Skip to content

Add error message for @Listener methods.#1513

Merged
stephan-gh merged 1 commit intoSpongePowered:bleedingfrom
JBYoshi:warn-private-listeners
Apr 13, 2017
Merged

Add error message for @Listener methods.#1513
stephan-gh merged 1 commit intoSpongePowered:bleedingfrom
JBYoshi:warn-private-listeners

Conversation

@JBYoshi
Copy link
Copy Markdown
Member

@JBYoshi JBYoshi commented Mar 6, 2017

Copy link
Copy Markdown
Contributor

@stephan-gh stephan-gh left a comment

Choose a reason for hiding this comment

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

👍

msg.printMessage(Diagnostic.Kind.ERROR, "method must return void", method);
}
List<? extends VariableElement> parameters = method.getParameters();
if (parameters.isEmpty() || isTypeSubclass(parameters.get(0), EVENT_CLASS)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be || !isTypeSubClass(...) because you want to show the error if the method doesn't have an Event as first parameter

Types types = processingEnv.getTypeUtils();

TypeMirror event = types.getDeclaredType(elements.getTypeElement(subclass));
return types.isAssignable(event, typedElement.asType());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The order of the arguments for isAssignable is wrong here. From the Javadocs:

returns true if and only if the first type is assignable to the second

You want to check if the parameter type extends Event which means that you need to check if the parameter is assignable to Event. Event isn't directly assignable to a subclass of it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is fine here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Minecrell Fixed.

@@ -1 +1,2 @@
org.spongepowered.plugin.processor.PluginProcessor
org.spongepowered.processor.plugin.PluginProcessor
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While I understand why you move it, I would prefer if it stays in its original package so we don't break older versions of SpongeGradle

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Minecrell Moved back to the original package.


return false;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need a new line

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@liach Fixed.

Types types = processingEnv.getTypeUtils();

TypeMirror event = types.getDeclaredType(elements.getTypeElement(subclass));
return types.isAssignable(event, typedElement.asType());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is fine here.

@JBYoshi JBYoshi force-pushed the warn-private-listeners branch from e48b63d to d20b3f3 Compare March 7, 2017 01:14
@JBYoshi JBYoshi force-pushed the warn-private-listeners branch 3 times, most recently from a116968 to 203d186 Compare March 17, 2017 15:33
@JBYoshi JBYoshi force-pushed the warn-private-listeners branch 2 times, most recently from b4c057a to 376c1e3 Compare March 26, 2017 22:19
@stephan-gh stephan-gh force-pushed the warn-private-listeners branch from 376c1e3 to e2a1f7e Compare April 13, 2017 08:47
@stephan-gh stephan-gh merged commit e2a1f7e into SpongePowered:bleeding Apr 13, 2017
@JBYoshi JBYoshi deleted the warn-private-listeners branch May 17, 2017 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants