Skip to content

Commit

Permalink
Merge kotlin.symbol.processing to ksp
Browse files Browse the repository at this point in the history
  • Loading branch information
ting-yuan committed Sep 17, 2020
1 parent 5186a78 commit 26c6673
Show file tree
Hide file tree
Showing 152 changed files with 575 additions and 577 deletions.
32 changes: 15 additions & 17 deletions api/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ fun KSFile.suppressedNames(): List<String> {

## Additional details

The API definition can be found [here](src/org/jetbrains/kotlin/ksp/).
The diagram below is an overview of how Kotlin is [modeled](src/org/jetbrains/kotlin/ksp/symbol/) in KSP:
The API definition can be found [here](api/src/main/kotlin/com/google/devtools/ksp/).
The diagram below is an overview of how Kotlin is [modeled](api/src/main/kotlin/com/google/devtools/ksp/symbol/) in KSP:
![class diagram](ClassDiagram.png)

### Type and resolution
Expand Down Expand Up @@ -435,27 +435,27 @@ Here's a sample processor that you can check out: https://github.com/android/kot
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-symbol-processing-api:1.4.0-dev-experimental-20200914")
implementation("com.google.devtools.ksp:symbol-processing-api:1.4.0-dev-experimental-20200914")
}
```

* The processor you're writing needs to implement `com.google.devtools.kotlin.symbol.processing.processing.SymbolProcessor`.
* The processor you're writing needs to implement `com.google.devtools.ksp.processing.SymbolProcessor`.
Note the following:
* Your main logic should be in the `process()` method.
* Use `CodeGenerator` in the `init()` method for code generation. You can also save
the `CodeGenerator` instance for later use in either `process()` or `finish()`.
* Use `resolver.getSymbolsWithAnnotation()` to get the symbols you want to process, given
the fully-qualified name of an annotation.
* A common use case for KSP is to implement a customized visitor (interface
`com.google.devtools.kotlin.symbol.processing.symbol.KSVisitor`) for operating on symbols. A simple template
visitor is `com.google.devtools.kotlin.symbol.processing.symbol.KSDefaultVisitor`.
`com.google.devtools.ksp.symbol.KSVisitor`) for operating on symbols. A simple template
visitor is `com.google.devtools.ksp.symbol.KSDefaultVisitor`.
* For sample implementations of the `SymbolProcessor` interface, see the following files
in the sample project.
* `src/main/kotlin/BuilderProcessor.kt`
* `src/main/kotlin/TestProcessor.kt`
* After writing your own processor, register your processor to the package by including
the fully-qualified name of that processor in
`resources/META-INF.services/com.google.devtools.kotlin.symbol.processing.processing.SymbolProcessor`.
`resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessor`.
* Here's a sample `build.gradle.kts` file for writing a processor.

```
Expand All @@ -469,7 +469,7 @@ Here's a sample processor that you can check out: https://github.com/android/kot
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-symbol-processing-api:1.4.0-dev-experimental-20200914")
implementation("com.google.devtools.ksp:symbol-processing-api:1.4.0-dev-experimental-20200914")
}
```

Expand All @@ -484,10 +484,8 @@ Here's a sample processor that you can check out: https://github.com/android/kot
resolutionStrategy {
eachPlugin {
when (requested.id.id) {
"kotlin-ksp",
"org.jetbrains.kotlin.kotlin-ksp",
"com.google.devtools.kotlin.symbol.processing" ->
useModule("org.jetbrains.kotlin:kotlin-ksp:${requested.version}")
"symbol-processing" ->
useModule("com.google.devtools.ksp:symbol-processing:${requested.version}")
}
}
}
Expand Down Expand Up @@ -563,11 +561,11 @@ We do end to end test for KSP, which means you need to write a lightweight proce

The form of the test itself is flexible as long as the logic is being covered.

Here are some [sample test processors](../../../plugins/ksp/src/org/jetbrains/kotlin/ksp/processor) for your reference.
Here are some [sample test processors](compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor) for your reference.

#### Steps for writing a test
* Create a test processor under the sample processor folder.
it should be extending [AbstractTestProcessor](../../../plugins/ksp/src/org/jetbrains/kotlin/ksp/processor/AbstractTestProcessor.kt)
it should be extending [AbstractTestProcessor](compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processor/AbstractTestProcessor.kt)
* Write your logic by overriding corresponding functions.
* Test is performed by running test processor and get a collection of test results in the form of List<String>.
* Make sure you override toResult() function to collect test result.
Expand All @@ -591,8 +589,8 @@ it should be extending [AbstractTestProcessor](../../../plugins/ksp/src/org/jetb
* After you have finished writing your test file, you can generate the test case in TestSuite by running
```generateTests```gradle task. It can take a while.
* After generating, make sure there is no other tests generated by checking git status, you should include only tests in
[KotlinKSPTestGenerated](../../../plugins/ksp/test/org/jetbrains/kotlin/ksp/test/KotlinKSPTestGenerated.java) in your PR.
* Run generated tests with ```:kotlin-symbol-processing:test``` gradle task.
[KotlinKSPTestGenerated](compiler-plugin/src/test/kotlin/com/google/devtools/ksp/test/KotlinKSPTestGenerated.java) in your PR.
* Run generated tests with ```:compiler-plugin:test``` gradle task.
* This will execute all tests in KSP test suite. To run your test only, specify the test name with
```--tests "com.google.devtools.kotlin.symbol.processing.test.KotlinKSPTestGenerated.<name of your generated test>"```
```--tests "com.google.devtools.ksp.test.KotlinKSPTestGenerated.<name of your generated test>"```
* Make sure your change is not breaking any existing test as well :).
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Kotlin Symbol Processing API"
val kotlinBaseVersion: String by project
val kspVersion: String? by project

group = "com.google.devtools.kotlin"
group = "com.google.devtools.ksp"
version = kspVersion ?: kotlinBaseVersion

tasks.withType<KotlinCompile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.processing
package com.google.devtools.ksp.processing

import java.io.File
import java.io.OutputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.processing
package com.google.devtools.ksp.processing

import com.google.devtools.kotlin.symbol.processing.symbol.KSType
import com.google.devtools.ksp.symbol.KSType

interface KSBuiltIns {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.processing
package com.google.devtools.ksp.processing

import com.google.devtools.kotlin.symbol.processing.symbol.KSNode
import com.google.devtools.ksp.symbol.KSNode

interface KSPLogger {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.processing
package com.google.devtools.ksp.processing

import com.google.devtools.kotlin.symbol.processing.symbol.*
import com.google.devtools.ksp.symbol.*

/**
* [Resolver] provides [SymbolProcessor] with access to compiler details such as Symbols.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.processing
package com.google.devtools.ksp.processing

/**
* [SymbolProcessor] is the interface used by plugins to integrate into Kotlin Symbol Processing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

enum class AnnotationUseSiteTarget {
FILE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Kind of a class declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Kind of a function declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A symbol that can be annotated with annotations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Instance of a constructor-call-like annotation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A reference to a callable entity, such as a function or a property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Models class-like declarations, including class, interface and object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* An application / reference to a user declared type such as class, interface and object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A declaration, can be function declaration, clsss declaration and property declaration, or a type alias.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A declaration container can have a list of declarations declared in it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Models `dynamic` type for Kotlin/JS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Classes, functions, properties and typealiases can be declared as `expect` in common modules and `actual` in platform modules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A Kotlin source file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A function definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A [KSModifierListOwner] can have zero or more modifiers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Kotlin Symbol Processing's representation of names. Can be simple or qualified names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Base class of every visitable program elements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A reference within a parenthesis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* The common base of property getter and setter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A property declaration, can also be used to denote a variable declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* An application/reference to a type declared somewhere else.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* Represents a type in Kotlin's type system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A type alias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A type argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A type parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A [KSTypeReference] is a [KSReferenceElement] with annotations and modifiers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package com.google.devtools.kotlin.symbol.processing.symbol
package com.google.devtools.ksp.symbol

/**
* A value argument to function / constructor calls.
Expand Down
Loading

0 comments on commit 26c6673

Please sign in to comment.