Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traversal order #260

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
location unsupported operation exception
  • Loading branch information
yigit committed Jan 14, 2021
commit f8f51d68dca154ef220641e829a6bf6bc47dca3b
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.google.devtools.ksp.processor

import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.processing.Resolver

class DeclarationOrderProcessor : AbstractTestProcessor() {
private val result = mutableListOf<String>()
override fun toResult() = result

override fun process(resolver: Resolver) {
val classNames = listOf(
//"ClassInModule1", "JavaClassInModule1",
"ClassInMain"//, "JavaClassInMain"
)
classNames.mapNotNull {
resolver.getClassDeclarationByName(it)
}.forEach { klass ->
klass.declarations.forEach {
println("${klass.qualifiedName?.asString()} $it")
println("$it ${it.location}")
result.add("$it : ${it.location}")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public void testDeclarationInconsistency() throws Exception {
runTest("testData/api/declarationInconsistency.kt");
}

@TestMetadata("declarationOrder.kt")
public void testDeclarationOrder() throws Exception {
runTest("testData/api/declarationOrder.kt");
}

@TestMetadata("declarationPackageName.kt")
public void testDeclarationPackageName() throws Exception {
runTest("testData/api/declarationPackageName.kt");
Expand Down
41 changes: 41 additions & 0 deletions compiler-plugin/testData/api/declarationOrder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// WITH_RUNTIME
// TEST PROCESSOR: DeclarationOrderProcessor
// EXPECTED:
// ClassInMainModule[KOTLIN]
// ClassInModule1[CLASS]
// ClassInModule2[CLASS]
// JavaClassInMainModule[JAVA]
// JavaClassInModule1[CLASS]
// JavaClassInModule2[CLASS]
// TestTarget[KOTLIN]
// END
// MODULE: module1
// FILE: ClassInModule1.kt
class ClassInModule1 {
val prop1: String = TODO()
val prop2: String? = TODO()
fun fun1(): String = TODO()
fun fun2() :String = TODO()
}
// FILE: JavaClassInModule1.java
public class JavaClassInModule1 {
String field1 = "";
String field2 = "";
void function1() {}
void function2() {}
}
// MODULE: main(module1)
// FILE: main.kt
class ClassInMain {
val prop1: String = TODO()
val prop2: String? = TODO()
fun fun1(): String = TODO()
fun fun2() :String = TODO()
}
// FILE: JavaClassInModule1.java
public class JavaClassInMain {
String field1 = "";
String field2 = "";
void function1() {}
void function2() {}
}