1+ /*
2+ * Copyright 2022 UnitTestBot contributors (utbot.org)
3+ * <p>
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ * <p>
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ * <p>
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org.jacodb.testing
18+
19+ import kotlinx.coroutines.runBlocking
20+ import org.jacodb.api.JcMethod
21+ import org.jacodb.api.JcParameter
22+ import org.jacodb.api.ext.findClass
23+ import org.jacodb.api.ext.methods
24+ import org.jacodb.impl.fs.asClassInfo
25+ import org.jacodb.impl.types.ParameterInfo
26+ import org.junit.jupiter.api.Assertions
27+ import org.junit.jupiter.api.Test
28+ import java.nio.file.Files
29+
30+ class ParameterNamesTest : BaseTest () {
31+ companion object : WithDB ()
32+
33+ private val target = Files .createTempDirectory(" jcdb-temp" )
34+
35+ @Test
36+ fun checkParameterName () {
37+ val clazz = cp.findClass(" GenericsApi" )
38+ runBlocking {
39+ cp.db.load(target.toFile())
40+ }
41+ val method = clazz.methods.firstOrNull { jcMethod -> jcMethod.name == " call" }
42+ Assertions .assertNotNull(method)
43+ Assertions .assertNull(method?.parameters?.get(0 )?.name)
44+ Assertions .assertEquals(" arg" , method?.parameterNames?.get(0 ))
45+ }
46+
47+ private val JcMethod .parameterNames: List <String ?>
48+ get() {
49+ return enclosingClass.asmNode()
50+ .asClassInfo(enclosingClass.bytecode()).methods.find { info -> info.name == name && info.desc == description }
51+ ?.parametersInfo?.map(ParameterInfo ::name)
52+ ? : parameters.map(JcParameter ::name)
53+ }
54+ }
0 commit comments