We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow.
Contributions to this project must be accompanied by a Contributor License Agreement (CLA). You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project. Head over to https://cla.developers.google.com/ to see your current agreements on file or to sign a new one.
You generally only need to submit a CLA once, so if you‘ve already submitted one (even if it was for a different project), you probably don’t need to do it again.
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.
This project follows Google's Open Source Community Guidelines.
For changes that involves API changes(new API, API signature change), please also update api.base file. You can monitor api change with ./gradlew :api:checkApi, and./gradlew :api:updateApi to generate new api signature.
If you want to submit a bug fix or report a bug via a test, follow this workflow:
@Bug requires a linked GitHub issue).runFailingTest or runThrowingTest respectively (annotated with @Bug(..., BugState.OPEN)).runFailingTest/runThrowingTest to runTest and update the BugState value (e.g., to BugState.FIXED).You may choose to follow any or all of the above steps as long as they are in that order.
For incoming PRs, we request that changes are covered by tests for good practice. We do end-to-end testing for KSP, which means you write a lightweight processor to be loaded with KSP for testing. The form of the test itself is flexible as long as the logic is covered.
[!NOTE] The
test-utilsdirectory is deprecated. Unit tests should be placed inkotlin-analysis-api.
Here are some sample test processors for your reference.
JavaLanguageVersion.of(17) in build.gradle.kts).List<String>.com.google.devtools.ksp.processor.AbstractTestProcessor class.toResult() function to collect test results.ApiFeatures. Specifically, it must override the apiFeatures property in SymbolProcessor. In other words, the constructor parameter list must be as follows: class MyProcessor(override val apiFeatures: ApiFeatures)..kt file under the testData folder in kotlin-analysis-api (e.g. kotlin-analysis-api/testData). Every .kt file under this folder corresponds to a test case.// WITH_RUNTIME to the top if you need access to the standard library.// TARGET_BACKEND: <backend> (e.g. // TARGET_BACKEND: NATIVE) and // WITH_FIXED_TARGET: <target> (e.g. // WITH_FIXED_TARGET: linux_x64) directives to ensure tests run on klib/native backends (as in packageDeclarations.kt). These directives come from the Kotlin compiler test framework.// TEST PROCESSOR:<Your test processor name> to provide the test processor for this test case. Processors can be reused if necessary.// PROCESSOR INPUT: <input/predicate> to specify inputs or predicates for the test processor (e.g. // PROCESSOR INPUT: Anno or // PROCESSOR INPUT: kotlin.annotation.Retention, kotlin.annotation.Target, as in aliasedAnnotation.kt). Note: for a processor to accept input, its constructor must have a single List<String> parameter. This is a handy way of writing a parametric test processor. The List<String> parameter must come before the apiFeatures property (e.g. class MyProcessor(val input: List<String>, override val apiFeatures: ApiFeatures)).// EXPECTED: and start your expected result lines. Every line should start with // (with a space after //).// <expected output> lines apply to all ApiFeatures configurations.ApiFeatures configurations, use the EXPECT directive: // EXPECT <FEATURE> = <BOOLEAN>[, <FEATURE> = <BOOLEAN>]: <expected output> where <FEATURE> is the screaming snake case name of a property in ApiFeatures (e.g. ENABLE_BACKING_FIELDS or ENABLE_CONTEXT_PARAMETERS) and <BOOLEAN> is TRUE or FALSE.// EXPECT ENABLE_BACKING_FIELDS = TRUE, ENABLE_CONTEXT_PARAMETERS = FALSE: <expected output>). If a feature is omitted on an EXPECT line, the expectation applies to both TRUE and FALSE values of the omitted feature. Use the minimal number of directives needed (see expectDifferentOutput.kt for an example).// END to indicate the end of expected test results.// FILE: <file name> to create files that will be available at runtime of the test.// FILE: a.kt will result in a file named a.kt at runtime.KSPUnitTestSuite in kotlin-analysis-api (or declare it abstract in KSPUnitTestSuite and override in AAConfiguredUnitTestSuite and PsiConfiguredUnitTestSuite if behavior differs between resolution strategies).@Bug and @BugState.@Bug annotation requires a link to an open or existing GitHub issue (e.g., @Bug("https://github.com/google/ksp/issues/<issue_number>", BugState.OPEN)).@Negative marker annotation if applicable.:kotlin-analysis-api:test gradle task.ApiFeatures and resolution strategy test suites (AAConfiguredUnitTestSuite.kt and PsiConfiguredUnitTestSuite.kt). To run your test only, specify the test name with --tests "com.google.devtools.ksp.test.*UnitTestSuite.<name of your test>"./gradlew check task as well to run all tests.