[java] Improve ForLoopCanBeForeach to use StablePathMatcher
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 5.5k
- Forks
- 1.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 54
Description
Rule: ForLoopCanBeForeach
Use the StablePathMatcher of #3191 to improve ForLoopCanBeForeach (see https://github.com/pmd/pmd/pull/3191#discussion_r606865642):
Note: this thing, might look overweight for the task (there's a single test case in BrokenNullCheck that requires it), but I think it could be used in other rules to make them smarter. For instance, in ForLoopCanBeForeach, we could recognise looping on any "stable path", eg
this.field.collectionorthis.getCollection().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ForLoopCanBeForeach rule and read the StablePathMatcher work from pull request #3191, including the referenced discussion. Determine how the rule can use stable paths such as this.field.collection or this.getCollection(), then verify the rule's existing tests and add coverage for the supported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100