Skip to content

[kotlin] Fix #6677: Add auxClasspath language property - #6678

Merged
adangel merged 17 commits into
pmd:mainfrom
stokpop:feature/kotlin-auxclasspath-standalone
Jun 18, 2026
Merged

adangel merged 17 commits into
pmd:mainfrom
stokpop:feature/kotlin-auxclasspath-standalone

Conversation

@stokpop

@stokpop stokpop commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • KotlinLanguageModule now uses JvmLanguagePropertyBundle so --aux-classpath is accepted for Kotlin analysis
  • New KotlinLanguageProcessor + KotlinAuxClasspathResolver: resolves classpath entries via the language property auxClasspath

Related issues/PRs

Follow-up

  • KotlinNode DataMap keys (TYPE_NAME_KEY, RETURN_TYPE_KEY, ANNOTATION_NAMES_KEY) + accessors — API contract for the kotlin-type-mapper to populate
  • KotlinHandler refactored to XPathHandlerHolder pattern (deferred init); XPath functions registered in follow-up PRs
  • XPath functions (hasAnnotation, hasImport) and full kotlin-type-mapper integration are in separate PRs.

Wire JvmLanguagePropertyBundle so --aux-classpath is accepted for Kotlin analysis.
Introduce KotlinLanguageProcessor and KotlinAuxClasspathResolver (3-tier resolution:
string property, URLClassLoader hierarchy, java.class.path system property).
Note pmd#4953 TODO on getAnalysisClassLoader() tier for future deprecation.

Add DataMap keys to KotlinNode ready for type-mapper population:
- TYPE_NAME_KEY: resolved type FQN for PropertyDeclaration / UnescapedAnnotation
- RETURN_TYPE_KEY: resolved return type FQN for FunctionDeclaration
- ANNOTATION_NAMES_KEY: comma-separated FQN annotation names on declaration nodes

Refactor KotlinHandler to use XPathHandlerHolder pattern (deferred init).
XPath functions (hasAnnotation, hasImport, etc.) registered in a follow-up PR.
@stokpop
stokpop force-pushed the feature/kotlin-auxclasspath-standalone branch from 40df60d to f1edf89 Compare May 14, 2026 12:50
@pmd-actions-helper

pmd-actions-helper Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-06-18 13:25:05+00:00 for d9c36f4)

stokpop added 2 commits May 30, 2026 06:55
getTypeName() and getReturnTypeName() on KotlinNode return null before type
analysis runs. Filter them out so they do not appear as null XPath attributes.
Update Simple.txt reference dump accordingly.
@stokpop
stokpop marked this pull request as draft May 30, 2026 07:41
@stokpop
stokpop marked this pull request as ready for review June 8, 2026 10:00
@stokpop

stokpop commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Hi @adangel, this PR is reworked to move as much as possible the code from KotlinNode, in line with previous related merged PRs. Can you please have a look? I think this is the next step to get to type awareness in Kotlin rules.

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Let's scope this PR down to just "[kotlin] Add auxclasspath language property" and add the KotlinNodeTypeData with the PR, that actually uses it.

So in short:

  1. Please remove KotlinNodeTypeData from this PR
  2. Make KotlinAuxClasspathResolver simpler to only support one way of configuring aux classpath.
  3. Refactor KotlinAuxClasspathResolver#resolve to return List<Path> instead of List<File>
  4. Add documentation about the new auxclasspath language property for Kotlin

@adangel

adangel commented Jun 12, 2026

Copy link
Copy Markdown
Member

XPath functions (hasAnnotation, hasImport) and full kotlin-type-mapper integration are in separate PRs.

The XPath functions can only be added, when you have types... So, I guess, the next PR should then focus on integrating kotlin-type-mapper, adding the additional AST processing phase and put the types into the nodes.

Also note: The types you have designed now are simple Strings... is this what you want? At some point, rules probably want to query something like "what are the methods of this type", or "is this type a subtype of this other type". Depending on the use cases, Strings are maybe too simple... (Note: I didn't look at all into #6645 - so not sure what use cases you already implemented).

@stokpop

stokpop commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review! I will go through each of the points.

The three "tiers" of classpath handling were there for three usages:

  • via pmd check,
  • in the PMD Designer,
  • for running test cases

If both Designer and tests can use the same approach we can indeed consolidate on one way.

stokpop added 4 commits June 16, 2026 14:33
Scope this PR down to auxclasspath language property only.
KotlinNodeTypeData will be added with the PR that actually uses it
(kotlin-type-mapper integration).
…asspath property

Only support the auxClasspath language property; remove URLClassLoader
hierarchy and java.class.path fallbacks. Returns List<Path> instead of
List<File>. Update tests accordingly.
- Log warning when auxClasspath is empty so users know type resolution
  will not work
- Use tempDir.resolve() for non-existent paths in tests for determinism

docs(kotlin): add auxclasspath section and language property entry

Add "Providing the auxiliary classpath" section to kotlin.md and add
auxClasspath entry to language_properties.md. Since 7.26.0.
…is PR

Holder-class pattern belongs with the PR that adds XPath functions.
@adangel adangel changed the title [kotlin] Add auxclasspath support and type-mapper infrastructure (#6677) [kotlin] Add auxclasspath language property (#6677) Jun 18, 2026
@adangel adangel changed the title [kotlin] Add auxclasspath language property (#6677) [kotlin] Fix #6677: Add auxclasspath language property Jun 18, 2026
@adangel adangel changed the title [kotlin] Fix #6677: Add auxclasspath language property [kotlin] Fix #6677: Add auxClasspath language property Jun 18, 2026
@adangel adangel added this to the 7.26.0 milestone Jun 18, 2026

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

@adangel
adangel merged commit 2c11a15 into pmd:main Jun 18, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[kotlin] Add auxClasspath language property

2 participants