pmd / pmd/pmd

[kotlin] Request for an XPath function as simple partial replacement of missing typeIs function

Open
#4,858 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

an:enhancement
Dominant language
Java
Stars
5.5k
Forks
1.6k
Avg merge
1d 19h
Merged PRs (30d)
54

Description

Is your feature request related to a problem? Please describe.
Because of a missing typeIf function in Kotlin, we are checking if the expected package of the type is imported, to come close to typeIs functionality. This is a verbose expression in XPath on the verbose parse tree and often needed.

Describe the solution you'd like
A function called hasImport with expected package as argument.
Example: /KotlinFile[pmd-kotlin:hasImport('javax.xml.xpath')]

Describe alternatives you've considered

  • copy-paste every time: we want to avoid this and be more concise
  • create a proper concise AST out of the kotlin parse tree: don't know how to do this, expected a lot of work
  • create a real typeIs function for Kotlin: expected to be difficult and much work

Additional context

  • This would be a small step to improve productivity of creating rule. Maybe one of the above could be next step.
  • I do have a initial version in a my repo fork in the 'pmd/7.0.0x-kotlin/hasImport' branch.
  • Not sure this is the way to go, so feedback requested.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository file or test; start with the reporter's pmd/7.0.0x-kotlin/hasImport branch and compare its initial implementation with the requested XPath example. Confirm the intended scope for a hasImport function; done means the example query works without the verbose import check.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.