-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to
MemberDescriptorReferencedClassVisitor
for visiting …
…referenced Kotlin inline class parameters
- Loading branch information
James Hamilton
committed
Jan 6, 2022
1 parent
818baea
commit cdf64c2
Showing
3 changed files
with
144 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...st/kotlin/proguard/classfile/kotlin/visitor/MemberDescriptorReferencedClassVisitorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* ProGuardCORE -- library to process Java bytecode. | ||
* | ||
* Copyright (c) 2002-2022 Guardsquare NV | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package proguard.classfile.kotlin.visitor | ||
|
||
import io.kotest.core.spec.style.FreeSpec | ||
import io.mockk.spyk | ||
import io.mockk.verify | ||
import proguard.classfile.visitor.AllMemberVisitor | ||
import proguard.classfile.visitor.ClassVisitor | ||
import proguard.classfile.visitor.MemberDescriptorReferencedClassVisitor | ||
import testutils.ClassPoolBuilder | ||
import testutils.KotlinSource | ||
|
||
class MemberDescriptorReferencedClassVisitorTest : FreeSpec({ | ||
"Given an inline class" - { | ||
val (programClassPool, _) = ClassPoolBuilder.fromSource( | ||
KotlinSource( | ||
"Test.kt", | ||
""" | ||
@JvmInline | ||
value class Password(val s: String) | ||
|
||
fun login(password: Password) { | ||
println(password); | ||
} | ||
""".trimIndent() | ||
) | ||
) | ||
|
||
"Then visiting the referenced descriptor methods of login with includeKotlinMetadata true" - { | ||
val visitor = spyk<ClassVisitor>() | ||
programClassPool.classesAccept( | ||
"TestKt", | ||
AllMemberVisitor(MemberDescriptorReferencedClassVisitor(true, visitor)) | ||
) | ||
|
||
"Should visit the Password class" { | ||
verify(exactly = 1) { | ||
visitor.visitAnyClass(programClassPool.getClass("Password")) | ||
} | ||
} | ||
} | ||
|
||
"Then visiting the referenced descriptor methods of login with includeKotlinMetadata false" - { | ||
val visitor = spyk<ClassVisitor>() | ||
programClassPool.classesAccept( | ||
"TestKt", | ||
AllMemberVisitor(MemberDescriptorReferencedClassVisitor(false, visitor)) | ||
) | ||
|
||
"Should not visit the Password class" { | ||
verify(exactly = 0) { | ||
visitor.visitAnyClass(programClassPool.getClass("Password")) | ||
} | ||
} | ||
} | ||
} | ||
}) |