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

Improve quality of Spoon's API documentation (javadoc) #3923

Open
slarse opened this issue May 12, 2021 · 5 comments
Open

Improve quality of Spoon's API documentation (javadoc) #3923

slarse opened this issue May 12, 2021 · 5 comments

Comments

@slarse
Copy link
Collaborator

slarse commented May 12, 2021

A lot of the Javadoc comments int the public API are missing documentation for things like parameters and return types (think @param and @return tags). In my opinion, the most glaring omissions of these details are in the metamodel docs, found in the subpackages of spoon.reflect.

For example, at the time of writing this, CtImport is entirely missing tags in its Javadocs.

What we're currently focusing on is improving the documentation of methods, which is arguably the most important documentation. To facilitate this, we have a script to find checkstyle errors in method Javadoc at chore/check-javadoc-regressions.py. You can use this script for two things, as described below.

Note on script compatibility: You must have Python 3.6+ and Maven installed to run the script. It should work fine in most *NIX environments. For Windows, it will only work if the mvn executable is on the system path (i.e. user path won't work). We recommend using WSL if you're on Windows for minimum hassle.

Find methods with poor Javadoc (i.e. stuff you can fix!)

To find methods with poor Javadoc, run the script and provide a regex to match the filepaths you're interested in. It's sufficient to just supply a "sufficiently unique" partial filepath. For example, to find poor Javadoc in the entirety of Spoon core, run the script like so:

Note: Replace python with whatever executable points to a Python 3.6+ interpreter on your machine!

$ python chore/check-javadoc-regressions.py src/main/java
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/IncrementalLauncher.java:256: Expected @return tag. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/Launcher.java:103:42: Expected @param tag for 'args'. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/Launcher.java:180:52: Expected @param tag for 'resource'. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/Launcher.java:604: Expected @return tag. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/Launcher.java:644: Expected @return tag. [JavadocMethod]
[... OUTPUT TRUNCATED ...]

To get only the errors of a particular file, it's almost always sufficient to use the regex /ClassName.java. For example, for ProcessingManager errors, you can execute the script like so.

$ python chore/check-javadoc-regressions.py /ProcessingManager.java
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/processing/ProcessingManager.java:32:57: Expected @param tag for 'type'. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/processing/ProcessingManager.java:39: Expected @return tag. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/processing/ProcessingManager.java:39:43: Expected @param tag for 'p'. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/processing/ProcessingManager.java:57: Expected @return tag. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/processing/ProcessingManager.java:68:54: Expected @param tag for 'elements'. [JavadocMethod]
[ERROR] /home/slarse/Documents/github/cdate/spoon-slarse/src/main/java/spoon/processing/ProcessingManager.java:78:32: Expected @param tag for 'element'. [JavadocMethod]

You can then go about fixing checkstyle errors!

Compare the current branch with the master branch

The second mode of the script is to compare overall Javadoc quality with the master branch. This runs in CI and breaks the build if Javadoc quality deteriorates (the amount of errors increase).

This can be nice to run after you're done with your changes to verify that you've actually improved Javadoc quality. So don't run it unless you've committed all changes! For details, see the help section by running check-javadoc-regressions.py with the --help flag.

Scope of a PR fixing checkstyle errors

The scope of a PR fixing checkstyle errors can range from a single method to an entire file. Try not to fix less than a single method, or work in more than a single file. It's much faster and easier to review a commit that only touches Javadoc in a single file, than it is to do so for edits in many files.

Feel free to fix any related Javadoc errors as well (typos, missing Javadoc body, outright errors, etc) in the Javadoc comments you work on.

With that, happy Javadoc fixing! And feel free to ask questions if anything is unclear.

I-Al-Istannen added a commit to I-Al-Istannen/spoon that referenced this issue Jul 2, 2021
Before this patch the CI Javadoc regression check would only look at the
amount of violations and fail the build if they increased:

```
JAVADOC QUALITY SCORE (lower is better)
    Compare: 2584
    Current: 2592

Javadoc quality has deteriorated!
Run the chore/ci-checkstyle-javadoc.sh script locally to find errors
See INRIA#3923 for details
```

This wasn't really helpful when actually finding the errors, as you
would need to run the checkstyle command locally on both branches and
diff the output yourself. This patch adds a small python script that
tries to (somewhat intelligently) perform this diff in the CI and print
a more useful failure message.

The line numbers in the output will not be correct if the exact same
violation message appears multiple times in a single file, but it is
better than having no feedback.
I-Al-Istannen added a commit to I-Al-Istannen/spoon that referenced this issue Jul 2, 2021
Before this patch the CI Javadoc regression check would only look at the
amount of violations and fail the build if they increased:

```
JAVADOC QUALITY SCORE (lower is better)
    Compare: 2584
    Current: 2592

Javadoc quality has deteriorated!
Run the chore/ci-checkstyle-javadoc.sh script locally to find errors
See INRIA#3923 for details
```

This wasn't really helpful when actually finding the errors, as you
would need to run the checkstyle command locally on both branches and
diff the output yourself. This patch adds a small python script that
tries to (somewhat intelligently) perform this diff in the CI and print
a more useful failure message.

The line numbers in the output will not be correct if the exact same
violation message appears multiple times in a single file, but it is
better than having no feedback.
I-Al-Istannen added a commit to I-Al-Istannen/spoon that referenced this issue Jul 2, 2021
Before this patch the CI Javadoc regression check would only look at the
amount of violations and fail the build if they increased:

```
JAVADOC QUALITY SCORE (lower is better)
    Compare: 2584
    Current: 2592

Javadoc quality has deteriorated!
Run the chore/ci-checkstyle-javadoc.sh script locally to find errors
See INRIA#3923 for details
```

This wasn't really helpful when actually finding the errors, as you
would need to run the checkstyle command locally on both branches and
diff the output yourself. This patch adds a small python script that
tries to (somewhat intelligently) perform this diff in the CI and print
a more useful failure message.

The line numbers in the output will not be correct if the exact same
violation message appears multiple times in a single file, but it is
better than having no feedback.
I-Al-Istannen added a commit to I-Al-Istannen/spoon that referenced this issue Jul 4, 2021
Before this patch the CI Javadoc regression check would only look at the
amount of violations and fail the build if they increased:

```
JAVADOC QUALITY SCORE (lower is better)
    Compare: 2584
    Current: 2592

Javadoc quality has deteriorated!
Run the chore/ci-checkstyle-javadoc.sh script locally to find errors
See INRIA#3923 for details
```

This wasn't really helpful when actually finding the errors, as you
would need to run the checkstyle command locally on both branches and
diff the output yourself. This patch adds a small python script that
tries to (somewhat intelligently) perform this diff in the CI and print
a more useful failure message.

The line numbers in the output will not be correct if the exact same
violation message appears multiple times in a single file, but it is
better than having no feedback.
@bhargavi-kotha
Copy link

@slarse Is this still open to start with contribution? And i'm willing to work on GSoC 2022 Implement Javadoc quality project idea.
can u please guide me on how to start with if not this PR to go on. I have experience on java based microservices and spring boot.I have implemented unit test cases with sonar coverage 85% in many of the projects.

@MartinWitt
Copy link
Collaborator

Hi @bhargavi-kotha,

Yes, this issue is still open and there should be countless Javadoc issues left. You are pretty fast because I have still no confirmation that we are accepted as GSoC project. In the next days(when I/we get the confirmation) we create a new GSoC post on things you can do to get into the project spoon. For now, you can have a look at the old post from @monperrus #3828 from 2021.

@slarse
Copy link
Collaborator Author

slarse commented Feb 28, 2022

What @MartinWitt said :)

@bhargavi-kotha
Copy link

Thanks @MartinWitt and @slarse . I would go through any documentation and explore the project. would start off with any issue, until we get confirmation.

@monperrus
Copy link
Collaborator

monperrus commented Apr 12, 2022

Javadoc warnings today

[WARNING] Javadoc Warnings
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/compiler/Environment.java:579: warning - invalid usage of tag >
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/processing/AbstractParallelProcessor.java:34: warning - Tag @link: reference not found: Executors#newFixedThreadPool()
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/refactoring/Refactoring.java:234: warning - @param argument "input" is not a parameter name.
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/code/CtTypePattern.java:29: warning - invalid usage of tag >
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/factory/Factory.java:371: warning - Tag @see: reference not found: CodeFactory#createJavaDocTag()
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/factory/Factory.java:371: warning - Tag @see: reference not found: CodeFactory#createJavaDocTag()
[WARNING] javadoc: warning - Tag @link: reference not found: #toString()
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/visitor/PrettyPrinter.java:73: warning - Tag @link: reference not found: #toString()
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/visitor/PrettyPrinter.java:73: warning - Tag @link: reference not found: #toString()
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/visitor/PrettyPrinter.java:73: warning - Tag @link: reference not found: #toString()
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/compiler/Environment.java:579: warning - invalid usage of tag >
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/support/template/Parameters.java:221: warning - @param argument "targetType" is not a parameter name.
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/support/util/internal/ElementNameMap.java:28: warning - invalid usage of tag >
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/visitor/PrettyPrinter.java:73: warning - Tag @link: reference not found: #toString()
[WARNING] /home/martin/martin-no-backup/spoon/spoon-core/src/main/java/spoon/reflect/visitor/PrettyPrinter.java:73: warning - Tag @link: reference not found: #toString()

@monperrus monperrus changed the title Improve quality of Spoon's API documentation Improve quality of Spoon's API documentation (javadoc) Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants