google / google/ksp

`implements ToBeGenerated` type shows up as a `CLASS` kind rather than an `INTERFACE`.

Open
#1,443 9 comments 0 reactions 0 assignees View on GitHub
api P4
Dominant language
Kotlin
Stars
3.5k
Forks
415
Avg merge
1d 2h
Merged PRs (30d)
53

Description

Take the following java source

```java
class Subject implements ToBeGenerated {}
```

Consider the case where `ToBeGenerated` will be generated by some processor, but has not been generated yet.

When processing with Javac annotation processing, `ToBeGenerated` will still show up as an interface of `Subject` via [`TypeElement#getInterfaces()`](https://docs.oracle.com/javase/8/docs/api/javax/lang/model/element/TypeElement.html#getInterfaces--) even though it has not been generated yet.

In KSP the `KSClassDeclaration` API does not distinguish between the super class and super interfaces, they are all combined into a single API, `KSClassDeclaration#superTypes()`. Thus, we need to `superType.resolve()` each super type, then cast `as? KSClassDeclaration`, and finally check `KSClassDeclaration#classKind()` to determine if its a `CLASS` or `INTERFACE` kind. However, the issue here is that `ToBeGenerated` shows up as `CLASS` rather than `INTERFACE` kind.

Ideally, KSP would match Javac here and treat the missing type, `ToBeGenerated`, as an `INTERFACE` kind since it appears under `implements` rather than `extends` declaration.

(Note: I realize this is a bit of an edge case (as everything works fine after `ToBeGenerated` has been generated) but it helps with libraries like `XProcessing` trying to support both Javac and KSP if things behave similar between the two.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.