-
Notifications
You must be signed in to change notification settings - Fork 145
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
Feature: integrate Jsr305CheckstylePlugin plugin #727
Comments
@mbert, please explain me what your Check is doing in examples please as I think good to know for users. Before you pass our strict CI, let's work on clear explanation of your Check reason/targets. |
OK, no problem. The check is an already existing project that was developed by colleagues in our then company and open-sourced thereafter. Here's the github repo for it. Because it's a standalone CheckStyle plugin it needs to be integrated in projects manually, which can be inconvenient in particular for IDEs. My contribution has only consisted of integrating it here I realise that the original project does not contain any user documentation. Let me summarise it here: The jsr305 annotations, like
You can also define class-wide defaults:
Annotations like these can assist static code analysis (some tools evaluate them if they are present), and they also document to others, how your code (API, ...) is supposed to be used. The I use the existing plugin in some projects where the annotations are considered compulsory as part of the coding conventions. Since the existing plugin always needs to integrated by hand (in particular in IDEs this can be error-prone), and also because it is rather unknown the way it is now, I hope by integrating it into the sevntu checks I can make it easier to integrate and encourage more people to use it. Please let me know whether you have any more questions, I shall happily add more examples if necessary. |
Yes, please continue with examples, checkstyle is not type aware tool https://checkstyle.org/#Limitations , I still do not understand what this Check is for. Please give few real problems in code and how to configure Check and what if will demand to put in code and .... All such examples will be in javadoc of Check. |
The plugin does not need to fully understand types, because they are all treated the same if they are not primitive types (void, int, ...) which can be identified by a positive-list. Hence whenever there is a method definition then a jsr305 annotation for the return type is either illegal if the return type is a primitive, or it is required, either at this position or by a class-default or by a parent class (if any). That's pretty much how it's being done technically. I'll try not to mix up things and continue with some usage examples in the next comment. |
Hoping to convince you of course, I am gathering tasks that I need to do in order to get the PR through later. From the travis-builds I've seen that only the first is related to my PR's code while number 2 and 3 seem to be related to a problem in the environment, and 4 of course represents this issue's outcome. Hence I would have to increase code coverage to 100%, that should be fine. From your comments here I gather that there is some documentation missing. If you've got a good example from which I can get some inspiration, I'd be happy to use that for orientation. |
This issue sounds very similar to #606 and kinda like #622 .
You may want to lean back on your check doing too much in 1. Is it possible this redundant annotation check be in a separate check an configured to any general annotation user wants or is this a very rare use case? |
Yes, that's similar indeed - I was not expecting that others had expressed similar ideas. The good news is: it's already done. My PR contains a port of a checkstyle plugin that has already been available for several years and is well-tested by users. The plugin checks both return values and parameters. In its current form there is no option for disabling warnings on redundant annotations, but that should be fairly easy to integrate. In its current form the plugin is designed to support a consistent use of these annotations. If somebody wants to allow "inconsistent" annotations one might debate on whether this should be supported, too. It should nevertheless be implementable. |
@mbert , thanks a lot, now I become to understand your ideas.
please extend examples on such validation, It is still not clear what Check i going to do in such situation. |
The Jsr305 annotations (annotations for software defect detection) contain a subset of "nullness" annotations that can be used to mark parameters as possibly null ( Using these annotations a programmer can declare how the code is meant to behave, and static code analysis (like e.g. FindBugs) can be used to verify that this is actually true. Also these annotations help others understanding code more easily, e.g. if confrontend with an annotated interface the necessity for null checks can easily be deducted from the annotations. The Jsr305AnnotationsCheck supports enforcing the following code style:
Here are a few examples:
The rules for treating inherited methods' return values and parameters can be relaxed, which can be useful for transitional periods when introducing this check to existing code. Having set the properties To get a fuller picture of the possible warnings and the corresponding code, I have appended the test classes from the check's unit test (they are also in the PR). This is the output the check generates for them:
|
Hi, any update? |
Sorry for delay, too much acticity in main project, I will reply. |
@mbert ,
This will not work, as interface and class might be in different files, please recheck whole list of limitations - https://checkstyle.org/writingchecks.html#Limitations . Please explain who you workaround such limitations. |
[edit] Please ignore, see my comment below. I would not call this a workaround. It's all possible using the CheckStyle API. Starting from the To get an idea you may look into the file Jsr305AnnotationsCheck in my PR, at line 905 you can see how it is implemented. |
Presence of parent class in same file is very rare case in real life, classes usually located in separate files. Please explain why you keep interfaces and classes in the same file. Am I missing something ? |
I've dug through the code again (I need to remind here that I am not the original author). The plugin does not actually analyse the parent class. It is enough to know that a method is overridden; in that case the following rules apply:
This constraint can be relaxed by setting the Sorry for the confusion. I should have looked things up before replying yesterday, I, too, am a bit tied up in other work atm. |
Thanks a lot for explanation, now it makes sense. We will do final review to make sure all is fine and this will let you avoid bunch of refactoring in PR. |
OK, new issue is #734. |
The Jsr305Annotations plugin has so far been hosted as an independent project. It allows enforcing the use of the "nullness" annotations in code in order to both support static code analysis and understandability of code.
In order to simplify its integration into IDEs I would like to see it integrated in the sevntu project. The authors have already changed the project license to LGPL 2.1 thus allowing to do so.
I have prepared a pull request to implement this feature.
The text was updated successfully, but these errors were encountered: