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

Fix existing cases of getFileContents() usage #11166

Open
9 of 14 tasks
romani opened this issue Jan 8, 2022 · 15 comments
Open
9 of 14 tasks

Fix existing cases of getFileContents() usage #11166

romani opened this issue Jan 8, 2022 · 15 comments

Comments

@romani
Copy link
Member

romani commented Jan 8, 2022

after #9889

We need to fix all existing cases of getFileContents() usage by usage on AST based logic.

/**
* Returns the file contents associated with the tree.
*
* @return the file contents
* @deprecated
* Usage of this method is no longer accepted.
* Please use AST based methods instead.
* @noinspection WeakerAccess
* @noinspectionreason WeakerAccess - we avoid 'protected' when possible
*/
@Deprecated(since = "9.3")
public final FileContents getFileContents() {

The same is true for methods getLine and getLines that do allow to have access to not AST content.

cases:

  • MissingOverrideCheck.java
  • PackageAnnotationCheck.java
  • AvoidEscapedUnicodeCharactersCheck.java
  • FallThroughCheck.java
  • PackageDeclarationCheck.java
  • ImportControlCheck.java
  • UnusedImportsCheck.java
  • MissingJavadocPackageCheck.java
  • OuterTypeFilenameCheck.java
  • RegexpCheck.java (not applicable as it is operates on text file, not java files, by design)
  • RegexpSinglelineJavaCheck.java (this is by design match to raw string, same a RegexpCheck)
  • MethodLengthCheck.java
  • EmptyLineSeparatorCheck.java
  • JavadocMetadataScraper.java

it is better to resolve each case in separate PR. Each PR should remove the suppression to show the issue is fixed. haanhvu@1439170#diff-c1ffc75b7152435a4d5d40d7ee9b32b57402959b1ad471a41e753ea67554378b

For javadoc please consult with maintainers before starting Javadoc modules that will require extra effort as redesign is required: - [ ] JavadocMethodCheck.java (1) - [ ] JavadocStyleCheck.java - [ ] JavadocTypeCheck.java - [ ] JavadocVariableCheck.java - [ ] MissingJavadocMethodCheck.java - [ ] MissingJavadocTypeCheck.java - [ ] WriteTagCheck.java
@remal
Copy link

remal commented Feb 1, 2022

@romani I have some custom checks for JavaDocs and, I'm afraid, it's not quite clear what exactly is supposed to be used instead of getFileContents(). Could you (or someone else) explain what is supposed to be used?

My goal is it check that JavaDoc is presented on every element that matches specific condition, has some tag (@author) and the tag's value is equal to some constant.

@strkkk
Copy link
Member

strkkk commented Feb 2, 2022

@remal instead of getContents() checks should use only AST and do not rely on text in file.
About the case you described - it seems to me that you dont need a custom check for it, MatchXPathCheck can provide same functionality.

strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 13, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 13, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 18, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 18, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 19, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 19, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 19, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 19, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 20, 2022
@strkkk strkkk linked a pull request Feb 20, 2022 that will close this issue
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 20, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 20, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 20, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 20, 2022
@strkkk strkkk linked a pull request Feb 20, 2022 that will close this issue
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 20, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Feb 28, 2022
strkkk added a commit to strkkk/checkstyle that referenced this issue Mar 1, 2022
@romani
Copy link
Member Author

romani commented Mar 1, 2022

@remal , please look at

public class AtclauseOrderCheck extends AbstractJavadocCheck {

With such inheritance, you will get whole ast of javadoc content.
The only downside is performance degradation, but you can measure how critical it for you in your projects.

@romani
Copy link
Member Author

romani commented Mar 1, 2022

Another approach is to override

to return "true" and your Check will get AST with all comment as plain text and you can parsing/matching content of comments as you need. You can find a lot of examples in our code of such override.
Such approach does not have any performance problems.

Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Jul 25, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Jul 26, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Jul 31, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 3, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 4, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 4, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 4, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 4, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 5, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 15, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 15, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 23, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 23, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 25, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 26, 2023
Kevin222004 added a commit to Kevin222004/checkstyle that referenced this issue Aug 27, 2023
@github-actions github-actions bot modified the milestones: 10.1, 10.12.4 Aug 28, 2023
@aayushRedHat
Copy link
Contributor

I am on JavadocStyleCheck

@romani
Copy link
Member Author

romani commented Dec 22, 2023

@aayushRedHat , please be aware that refactoring of javadoc check needs changing extension of abstract class to get AST of javadoc. It might be bigger update than for non javadoc Checks. Do not hesitate to set draft PR to share with us your direction and double check that you care right path.

@Kevin222004
Copy link
Contributor

Kevin222004 commented Mar 26, 2024

I am on ImportControlCheck

@romani
Copy link
Member Author

romani commented Mar 26, 2024

@Kevin222004 , please do not deal with Javadoc* Checks, it will require big redesign we do not have plan for this, please deal with regular Checks for now.

@mahfouz72
Copy link
Member

@romani I want to work on this. I can take EmptyLineSeparatorCheck. Is there anything I should keep in mind before starting? and
is it ok to split work for this Check in separate PRs to ease work and review because there are two usages of getFileContents() in this check or full migration should be done in one PR?

@romani
Copy link
Member Author

romani commented Apr 17, 2024

@mahfouz72, please help us to refactor this Check, yes, few PRs are good to ease review.

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

8 participants