Branch: refs/heads/main
  Home:   https://github.com/pmd/pmd
  Commit: 5bc929eece618f62aa22e661b75941e0c92bd7d3
      https://github.com/pmd/pmd/commit/5bc929eece618f62aa22e661b75941e0c92bd7d3
  Author: Peter Paul Bakker <[email protected]>
  Date:   2026-09-17 (Thu, 17 Sep 2026)

  Changed paths:
    M docs/_data/xpath_funs.yml
    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/KotlinHandler.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageProcessor.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinTypeAwarenessSupport.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/AttributeView.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/HasModifiers.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/HasTypeName.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtCatchBlockAttributes.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtClassDeclarationAttributes.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtClassParameterAttributes.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtCompanionObjectAttributes.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtDelegationSpecifierAttributes.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtForStatementAttributes.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtFunctionDeclarationAttributes.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtFunctionValueParameterAttributes.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtPropertyDeclarationAttributes.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtSingleAnnotationAttributes.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KtUnescapedAnnotationAttributes.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/internal/KotlinAstUtil.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/internal/KotlinDesignerBindings.java
    M 
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/rule/xpath/internal/AbstractKotlinTypeIsFunctionCall.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinHasAnnotationFunction.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinHasUnresolvedReferenceFunction.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinIsNullableFunction.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinMatchesSigFunction.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinModifiersFunction.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinTypeIsExactlyFunction.java
    A 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinTypeIsFunction.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/InternalApiBridge.java
    M 
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/KotlinTypeName.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/internal/AnnotationFqnAnnotator.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/internal/DelegationSpecifierAnnotator.java
    M 
pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/types/internal/FunctionParameterAnnotator.java
    M 
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/ast/KotlinInnerNodeTest.java
    M 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java
    M 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/internal/KotlinAstUtilTest.java
    M 
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/rule/xpath/internal/BaseKotlinXPathFunctionTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinHasAnnotationFunctionShapeTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinHasAnnotationFunctionTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinHasUnresolvedReferenceFunctionTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinIsNullableFunctionTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinMatchesSigFunctionTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinModifiersFunctionTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinTypeAttributesTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinTypeIsExactlyFunctionTest.java
    A 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/KotlinTypeIsFunctionTest.java
    M 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/types/KotlinAuxClasspathIntegrationTest.java
    M 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/types/KotlinNodeTypeDataTest.java
    M 
pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/types/internal/KotlinTypeAnnotationVisitorTest.java
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/MultiDollarLineStringRef.txt
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/MultiLineStringExprSplitting.txt
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/MultiLineStringExpressions.txt
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/MultiLineStringRefSplitting.txt
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/MultiLineStringRefs.txt
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/SingleDollarExprNoPrefix.txt
    M 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/SingleDollarRefNoPrefix.txt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/hasAnnotation/AnnotatedEntities.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/hasAnnotation/TestCaseExample.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/hasUnresolvedReference/LocalClass.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/hasUnresolvedReference/NoImports.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/hasUnresolvedReference/UnresolvedImports.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/isNullable/NullableTypes.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/AdjacentLineUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/CalendarDateUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/DateTimeFormatterUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/JodaDateTimeFormatterCtorUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/ListUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/NestedArgUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/PatternUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/PrintStackTraceUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/SystemPrintlnUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/matchesSig/TwoResolvedCallsSameLine.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/CalendarUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/ConstructorCallTypeCheck.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/DelegationSpecifierSubtype.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/InferredTypeSubtype.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/MessageDigestFieldUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/ParameterTypes.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/PrimaryCtorParams.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/SerializableSubtype.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/StringBufferFieldUsage.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/StringEquivalence.kt
    A 
pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/xpath/typeis/TypeAnnotationAttributes.kt

  Log Message:
  -----------
  [kotlin] Add XPath functions and type attributes (#6893)

Adds XPath function and attribute support to pmd-kotlin, enabling type-aware 
XPath rules.

## What's included

**7 XPath functions** (`pmd-kotlin:` namespace):
- `typeIs(typeName)` / `typeIsExactly(typeName)` — type checks (with/without 
subtypes)
- `matchesSig(signature)` — match function/constructor call signatures
- `hasAnnotation(fqn)` — check annotation presence
- `modifiers()` — get modifier keywords
- `isNullable()` — nullable type check
- `hasUnresolvedReference()` — whether a node has an unresolved type reference

**Type-info XPath attributes** (need `auxClasspath` + resolved types; absent 
otherwise):

| Attribute | Nodes | Meaning |
|---|---|---|
| `@TypeName` | ClassDeclaration, PropertyDeclaration, ClassParameter, 
DelegationSpecifier, CatchBlock, ForStatement, SingleAnnotation, 
UnescapedAnnotation, FunctionValueParameter | FQ type name (with generics + 
nullable marker) |
| `@ReturnTypeName` | FunctionDeclaration | FQ return type name |
| `@AnnotationFqNames` | ClassDeclaration, FunctionDeclaration, 
PropertyDeclaration, ClassParameter | FQNs of all annotations (always present, 
empty list if none) |

**General (structural) XPath attributes** — always present, don't depend on 
type resolution:

| Attribute | Nodes | Meaning |
|---|---|---|
| `@Identifier` | ClassDeclaration, FunctionDeclaration, ClassParameter, 
CompanionObject, VariableDeclaration, ImportAlias | Simple name of the declared 
identifier |
| `@Mutable` | PropertyDeclaration | `true`/`false` for `var`/`val` |
| `@Name` | ImportHeader | Fully-qualified imported name |

Note: modifiers are **not** exposed as an `@Modifiers` XPath attribute — use 
`pmd-kotlin:modifiers()`
instead. `HasModifiers.getModifiers()` remains available for Java-based rules.

**`KotlinTypeName` type abstraction.**
Type info is stored as `KotlinTypeName` objects (PMD-owned, immutable), 
decoupling the public API
from kotlin-type-mapper, which stays an internal implementation detail. Key 
members:
`getFqName()`, `isNullable()`, `isUnresolved()`, `toDisplayString()` (includes 
generics, e.g.
`kotlin.collections.List<kotlin.String>?`, powered by kotlin-type-mapper 
0.7.1's `TypeAst`).

Java rules use `HasTypeName.getType()` / `KotlinNodeTypeData.getType()`; XPath 
rules use
`@TypeName` / `@ReturnTypeName` directly.

## Design notes

- **Null attributes are filtered** 
(`KotlinInnerNode.getXPathAttributesIterator`): type-info
  attributes return null when they don't apply, so they're absent from XPath 
rather than
  present-with-null. `@AnnotationFqNames`, `@Identifier`, `@Mutable`, `@Name` 
are always present.
- **Unresolved vs. genuinely-none**, mirroring pmd-java's `isUnresolved()`: an 
absent `@TypeName`/
  `@ReturnTypeName` is ambiguous on its own, since a configured `auxClasspath` 
doesn't guarantee
  every type resolves. `pmd-kotlin:hasUnresolvedReference()` disambiguates: 
`true` → analysis ran
  but the type couldn't be resolved; `false` → analysis ran and there's 
genuinely no such value.
  Doesn't apply to `@AnnotationFqNames` (always present) or modifiers (absence 
just means none).
- **Unresolved types still get best-effort names** 
(`KotlinTypeName.isUnresolved()`), via
  kotlin-type-mapper 0.7.1's `TypeAst.isUnresolved()` support 
(stokpop/kotlin-type-mapper#29).


## Related issues

* See also #4339



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

Reply via email to