How to add custom SuppressWarnings token in Eclipse
Asked Answered
P

1

13

I'm writing a PMD plug-in for Eclipse which lets users suppress PMD warnings by adding annotations like @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull"). Since Eclipse doesn't know that PMD.ReturnEmptyArrayRatherThanNull is a valid token, it warns the token is unsupported and offers a quick fix to remove it.

How can it let Eclipse know that this is in fact a supported SuppressWarnings token and that it should not mark it with a warning?

I'm not looking for a way the user can suppress the warning. I know about the "Ignore unhandled token in SuppressWarnings" preference in Eclipse. This is a workaround and has the disadvantage that Eclipse does not report any unsupported token at all making it rather difficult to e.g. find a typo in a SuppressWarnings token.

What I'm looking for is a way I as a plug-in developer can extend Eclipse so it recognizes the PMD token as supported SuppressWarnings token.

So far I have only found that the token supported by Eclipse are hard coded into the Eclipse Java compiler but have not found an extension point or something else that lets me add the PMD token to the list of supported SuppressWarnings token.

Philippine answered 6/1, 2014 at 13:46 Comment(8)
Did you ever resolve this issue?Belfort
Unfortunately not. I tried a workaround where the warnings are deleted right after they are created but I never managed to get it to work correctly.Philippine
How about a feature request at eclipse.org that enables the extension of the list via plugin?Tobytobye
I would appreciate such a feature requestTerminate
I just wanted to create a feature request at eclipse.org. As it turns out there already is an almost 10 year old feature request: Extensionpoint for additional SuppressWarnings tokens. I added my requirements and upvoted the request. I suggest you do the same.Philippine
I look at org.jboss.tools.common.validation and I clearly realize they allow usage of custom SuppressWarnings through definition of an extension point org.jboss.tools.common.validation.warnings. But I don't get it yet how this is implemented. Maybe it would be interesting for you as well. If you find out anything, would you please let me know?Terminate
Here is the respective feature request: issues.jboss.org/browse/JBIDE-10187 According to the comments they are also aware of the problem. They solved it by using the mentioned "Ignore unhandled token in SuppressWarnings" preference. The user decides if that preference should be enabled for project or globally. Alas no other way around.Terminate
The class, which is responsive for the described behavior is AddSuppressWarningsMarkerResolutionTerminate
C
0

What you could do is write a small plugin that used Equinox Weaving Service to intercept this method calls and return custom IrritantSet instances from it. That would require a bit of snooping around compiler code, but should not be too difficult.

The disadvantage is that it might break with JDT updates and will only work in Eclipse that has that plugin installed.

See this tutorial to learn how to write a plugin that uses weaving service.

Chari answered 21/5, 2015 at 16:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.