Branch: refs/heads/main
Home: https://github.com/pmd/pmd
Commit: ca57d1e64b108426dc4885a2c87e521e0ed83296
https://github.com/pmd/pmd/commit/ca57d1e64b108426dc4885a2c87e521e0ed83296
Author: Peter Paul Bakker <[email protected]>
Date: 2026-07-18 (Sat, 18 Jul 2026)
Changed paths:
M docs/pages/pmd/languages/kotlin.md
M docs/pages/release_notes.md
M pmd-kotlin/pom.xml
M
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinAuxClasspathResolver.java
M
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageProcessor.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinTypeAwarenessSupport.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/internal/KotlinTypeAnalysisContext.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/InternalApiBridge.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/KotlinNodeTypeData.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/internal/AnnotationFqnAnnotator.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/internal/DelegationSpecifierAnnotator.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/internal/FunctionParameterAnnotator.java
A
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/internal/KotlinTypeAnnotationVisitor.java
A
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageProcessorTest.java
M
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java
A
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/internal/KotlinTypeAnalysisContextTest.java
A
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/types/KotlinAuxClasspathIntegrationTest.java
A
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/types/KotlinNodeTypeDataTest.java
A
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/types/internal/KotlinTypeAnnotationVisitorTest.java
M pmd-test/src/main/java/net/sourceforge/pmd/test/RuleTst.java
Log Message:
-----------
[kotlin] Add kotlin-type-mapper infrastructure (#6795)
* feat(kotlin): add KotlinNodeTypeData with package-private setters and
InternalApiBridge
KotlinNodeTypeData stores type-mapper results on AST nodes via DataMap.
Setters are package-private; InternalApiBridge exposes them to callers
outside the types package (e.g. KotlinLanguageProcessor).
* feat(kotlin): add KotlinTypeAnalysisContext and holder with
kotlin-type-mapper deps
Add KotlinTypeAnalysisContext (indexes call sites, declarations, type
hierarchy from TypedAst) and KotlinTypeAnalysisContextHolder (global +
thread-local slots). Add kotlin-type-mapper-model and -analyzer deps.
* feat(kotlin): integrate kotlin-type-mapper AST annotation phase
Add KotlinTypeAnnotationVisitor, AnnotationAttributeAnnotator, and
DelegationSpecifierAnnotator to walk parsed ASTs and set @TypeName /
@ReturnTypeName attributes on declaration nodes. KotlinLanguageProcessor
now runs kotlin-type-mapper before parsing and annotates each file via
InternalApiBridge; falls back gracefully when no auxClasspath is set.
* test(kotlin): expand KotlinTypeAnnotationVisitorTest to full visitor coverage
9 tests covering all node types with specific type assertions:
PropertyDeclaration, FunctionDeclaration, CatchBlock, ForStatement (loop var
+ collection param), ClassParameter, ClassDeclaration (simple name without
package; FQN with package declaration), annotation FQN. Uses
KotlinParsingHelper for production-like parsing.
* fix(kotlin): upgrade ktm to 0.5.1, fix NPE, add missing tests
- Upgrade kotlin-type-mapper deps from 0.5.1-SNAPSHOT to 0.5.1
- Add delegation specifier tests (superclass + interface) to
KotlinTypeAnnotationVisitorTest
- Add KotlinAuxClasspathIntegrationTest: end-to-end auxClasspath flow
- Remove KotlinNodeTypeDataTest.typeInfoAvailableFalseWhenNotSet (always failed)
- Add KotlinTypeAnalysisContextHolder.clear() to test teardown
- Add kotlin-type-mapper attribution to kotlin.md docs
- Fix NPE in KotlinAuxClasspathResolver when path has no filename component
* refactor(kotlin): move KotlinTypeAnalysisContext to rule.internal package
Was in rule.xpath.internal, implying XPath-only use. Both classes are
general infrastructure usable by Java-based rules too. Move to rule.internal,
add @Experimental @since 7.27.0, add japicmp exclusion for new package.
* refactor(kotlin): extract analyzeAndBuildVisitor to remove duplication
runTypeAnalysis() and runSingleFileAnalysis() shared identical core logic:
fromSources, context creation, setGlobal/clearGlobal. Extract to private
analyzeAndBuildVisitor(); callers add context-specific debug logging.
* feat(kotlin): upgrade ktm to 0.6.0-SNAPSHOT, use resolveAbsolutePath (#7)
Use TypedAstAccessorsKt.hasSourceRoot(ast) to explicitly distinguish
disk-based analysis (real abs path available) from in-memory analysis
(fromSources, sourceRoot is ""). For in-memory analysis, only the
basename is indexed — no bogus "/" + relativePath key is created.
For disk analysis, TypedAstAccessorsKt.resolveAbsolutePath(ast, file)
provides the canonical abs path.
Document that the basename index is an intentional fallback for cases
where PMD paths differ from ktm paths, and that it is inherently
ambiguous when multiple files share the same filename across packages.
* refactor(kotlin): store TypedAst in context, delegate isSubtypeOf to ktm (#8)
Store TypedAst in KotlinTypeAnalysisContext and delegate isSubtypeOf() to
TypedAstHierarchyQueriesKt.isSubtypeOf(). Removes the separate typeHierarchy
field; getTypeHierarchy() now delegates to typedAst.getTypeHierarchy().
The empty context (null typedAst) falls back to name-equivalence only.
Note: ktm#20 filed to add a cached upward-BFS variant for better per-node
rule evaluation performance.
* docs+test(kotlin): document endLine/endColumn span semantics from ktm 0.6.0
(#9)
- Document ktm 0.6.0 line semantics in callSitesAt/callSitesInRange javadoc:
CallSiteAst.line = callee-name token; endLine/endColumn now available.
- Add compilation-check test asserting getEndLine() >= 0 is readable.
- Add 5 line-number-sensitive tests to KotlinTypeAnnotationVisitorTest covering
multiline functions, multiple annotations on separate lines, leading blank
lines,
lambdas, and chained calls; each asserts the exact PMD beginLine.
- Document the +/-1 fallback in both lookupByLine and lookupWithFallback: needed
when ktm reports the annotation line but PMD reports the keyword line.
* feat(kotlin): expose callsOnReceiver/callsReturning delegation from ktm 0.6.0
(#10)
Add callsOnReceiver, callsOnReceiverSubtype, callsReturning,
callsReturningSubtype
to KotlinTypeAnalysisContext, delegating to TypedAstCallQueriesKt. These
methods use
the dispatchReceiverType and extensionReceiverType fields introduced in
CallSiteAst 0.6.0.
Add note to class Javadoc that ktm records concrete expanded types (not alias
names).
Tests verify dispatchReceiverType is non-null for method calls and that both
callsOnReceiver and callsReturning find expected call sites.
* perf(kotlin): use isSubtypeOfUpward for O(ancestors) hierarchy check (ktm #20)
Switch isSubtypeOf delegation from isSubtypeOf (downward BFS over all subtypes)
to isSubtypeOfUpward (upward walk of actual's supertypes, O(ancestors ~3-10)).
Also gains Object/Any short-circuit added in the same ktm PR #21.
* refactor(kotlin): defer call-site queries, use TypedAst direct API (ktm
#22/#23)
- Remove
callsOnReceiver/callsOnReceiverSubtype/callsReturning/callsReturningSubtype
from KotlinTypeAnalysisContext; deferred to add-kotlin-typealias-support
branch
alongside constructorCallsOf support (ktm #22)
- Use TypedAst.hasSourceRoot() and TypedAst.resolveAbsolutePath(FileAst)
directly
instead of TypedAstAccessorsKt static dispatch (ktm #23)
- Add missing @Experimental + @experimental javadoc on
KotlinTypeAnnotationVisitor
- Add missing @experimental javadoc on KotlinTypeAnalysisContext/Holder
* chore(kotlin): upgrade kotlin-type-mapper to 0.6.0 release
* refactor(kotlin): simplify KotlinParser usage in annotators
* Refactor Kotlin type-awareness flow and tighten Kotlin checks
* Warn once for missing Kotlin aux classpath
* docs(kotlin): note XPath/designer type attr exposure deferred to follow-up
* fix(kotlin): address trivial review comments from adangel
- pom.xml: extract kotlin.type.mapper.version property
- release_notes.md: simplify XPath/Designer limitation note
- KotlinLanguageProcessor: fix @since to 7.25.0; use direct KtKotlinFile
cast in parser lambda instead of instanceof check + debug log
- KotlinTypeAwarenessSupport: tighten annotateIfPossible to KtKotlinFile;
remove try-catch in analyzeAndBuildVisitor (fail fast)
- KotlinTypeAnnotationVisitor: tighten annotate() to KtKotlinFile
- KotlinNodeTypeData + InternalApiBridge: tighten isTypeInfoAvailable /
setTypeInfoAvailable to KtKotlinFile
- AnnotationAttributeAnnotator: use .children().first() for params node;
throw on param count mismatch; rethrow IndexOutOfBoundsException with
AssertionUtil.contexted(); remove unused LOG
- DelegationSpecifierAnnotator: rethrow IndexOutOfBoundsException with
AssertionUtil.contexted(); remove unused LOG
* refactor(kotlin): remove KotlinTypeAnalysisContextHolder static state
Replace static GLOBAL_CONTEXT/THREAD_CONTEXT fields with per-file root-node
storage. KotlinTypeAnalysisContext is now stored on each KtKotlinFile via
KotlinNodeTypeData (new ANALYSIS_CONTEXT_KEY), stamped by
KotlinTypeAwarenessSupport.annotateIfPossible() after annotation completes.
- KotlinNodeTypeData: add getAnalysisContext/setAnalysisContext(KtKotlinFile)
- InternalApiBridge: expose setAnalysisContext bridge method
- KotlinTypeAwarenessSupport: hold KotlinTypeAnalysisContext as instance
AtomicReference; set on root node per file; remove ContextHolder calls
- Delete KotlinTypeAnalysisContextHolder (static state gone)
- Delete KotlinTypeXPathTestHelper (only existed to inject into holder)
- KotlinTypeAnalysisContextTest: build context directly in @BeforeEach;
remove two holder-specific tests (holder no longer exists)
XPath functions (future): retrieve context via
KotlinNodeTypeData.getAnalysisContext(root) instead of the static holder.
* refactor(kotlin): split AnnotationAttributeAnnotator into two classes
Extract function-parameter type annotation into a dedicated class,
separating the two unrelated responsibilities.
- New FunctionParameterAnnotator: setFunctionParameterTypes +
annotateParameterNodes (moved verbatim from AnnotationAttributeAnnotator)
- AnnotationAttributeAnnotator: annotation FQN logic only; remove
KtFunctionDeclaration, KtFunctionValueParameters, ParameterAst imports;
update javadoc
- KotlinTypeAnnotationVisitor: call FunctionParameterAnnotator instead of
AnnotationAttributeAnnotator for parameter types; update javadoc
* refactor(kotlin): rename AnnotationAttributeAnnotator ->
AnnotationFqnAnnotator
Avoids double use of "annotation" (Kotlin @Annotation concept vs. "annotates
the AST"). Also rename setAnnotationAttributes -> setAnnotationFqns for
consistency with the class name.
* refactor(kotlin): KotlinTypeAnnotationVisitor: use KotlinTypeAnalysisContext
instead of TypedAst
Eliminate the duplicate declaration index built inside the visitor.
KotlinTypeAnalysisContext already indexes by abs path, basename, .kt
extension fallback, and +/-1 line tolerance via declarationsAt().
- Constructor: TypedAst -> KotlinTypeAnalysisContext; drop byFilename field
- annotate(): remove filename extraction + byFilename lookup; delegate
directly to AnnotatingVisitor(ctx, absPath)
- AnnotatingVisitor: take (ctx, absPath); call ctx.declarationsAt(absPath, line)
instead of lookupWithFallback(byLine, line)
- Remove lookupWithFallback static method (superseded by ctx.declarationsAt)
- Remove now-unused imports: File, ArrayList, Collections, HashMap, Map,
FileAst, TypedAst
- KotlinTypeAwarenessSupport: pass ctx (not ast) to visitor constructor
* fix(kotlin): use ktm fromPaths for disk files; fix AtomicRef race (items 5+6)
Item 5 — memory: KotlinTypeAwarenessSupport.prepare() now passes List<Path> to
KotlinTypeMapper.fromPaths() when all source files are on disk. KTM reads the
files itself, so source strings are not duplicated between PMD's TextFile cache
and the analyser — halves peak memory for disk-backed analysis runs. Designer /
in-memory files fall back to the existing fromSources(Map<String,String>) path.
Item 6 — race: annotateIfPossible() single-file branch previously read back
analysisContext.get() after runSingleFileAnalysis() set it. A concurrent
Designer parse could race between the set and the re-read, stamping the wrong
context on the root node. Fixed by exposing getContext() on
KotlinTypeAnnotationVisitor and using the visitor's own ctx directly.
Also bumps kotlin-type-mapper dependency to 0.6.1-SNAPSHOT (adds fromPaths).
* chore(kotlin): bump kotlin-type-mapper to 0.6.1 (released)
* refactor(kotlin): remove basename fallback from analysis context index
Index by canonical abs path (disk) or relativePath (in-memory) only.
Basename fallback was never needed: disk paths always match (PMD passes
the same paths it got from FS), and in-memory uses the fromSources key
directly. Add fail-fast clash detection so two files mapping to the same
index key throw immediately instead of silently corrupting results.
* refactor(kotlin): store annotation FQNs as List<String> instead of
comma-joined String
Addresses adangel review suggestion. SimpleDataKey<List<String>> stores
the list directly; no join on set, no split on get. Remove stale
InternalApiBridge.setAnnotationFqNames bridge method (unused).
* refactor(kotlin): remove sanitizeKtFilename workaround; use absPath directly
sanitizeKtFilename silently masked two bugs:
- buildSourceMap keyed by getFileName() (basename) while annotate()
looked up by getAbsolutePath() — only worked via now-removed basename fallback
- single-file path used a sanitized name inconsistently
Fix: buildSourceMap keys by getAbsolutePath(), single-file path uses
absPath as-is on both sides. Keys always match without fallback.
Add validateKotlinPath() with fail-fast throw for null/empty absPath.
* docs(kotlin): update comments — Designer fixed in pmd-designer#376, in-memory
fallback is for test framework only
* [test] use snippet.<ext> filename in RuleTst instead of bare "file"
Gives the virtual in-memory file a proper language extension so that
kotlin-type-mapper (and other language processors) can identify the
language from the filename during the pre-analysis prepare() step.
Suggested by adangel in PR #6795 review.
* [kotlin] remove AtomicReference and single-file fallback from
KotlinTypeAwarenessSupport
Replace AtomicReference fields with volatile fields — lifecycle guarantees
happen-before between prepare() and annotateIfPossible(), volatile ensures
visibility across threads.
Remove the 'if (visitor == null)' single-file workaround from
annotateIfPossible().
Fix the last bypass caller instead: KotlinParsingHelper now overrides doParse()
to call prepareForSingleDocument() before parsing, so
KotlinTypeAnnotationVisitorTest
tests go through a proper prepare() step without needing a full PmdAnalysis run.
RuleTst.java was fixed in the previous commit. Designer bypass is addressed
by adangel's pmd-designer#376.
Suggested by adangel in PR #6795 review.
* [kotlin] use plain fields instead of volatile in KotlinTypeAwarenessSupport
Plain fields are sufficient: prepare() completes before launchAnalysis()
submits file-processing tasks to threads, so JMM executor task submission
guarantees visibility. Avoids AvoidUsingVolatile PMD dogfood violation.
* [kotlin] Simplifications and fixes from review
- moving KotlinTypeAnnotationVisitor into internal package
- simplifying implementations of AnnotationFqnAnnotator,
DelegationSpecifierAnnotator and FunctionParameterAnnotator
- Correcting `@since` javadoc tags
- add all internal packages to japicmp
* [doc] Release notes (#6795)
---------
Co-authored-by: Andreas Dangel <[email protected]>
To unsubscribe from these emails, change your notification settings at
https://github.com/pmd/pmd/settings/notifications
_______________________________________________
Pmd-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pmd-commits