|
18 | 18 |
|
19 | 19 | package org.jacodb.api.ext |
20 | 20 |
|
21 | | -import org.jacodb.api.JcArrayType |
22 | | -import org.jacodb.api.JcClassType |
23 | | -import org.jacodb.api.JcPrimitiveType |
24 | | -import org.jacodb.api.JcRefType |
25 | | -import org.jacodb.api.JcType |
26 | | -import org.jacodb.api.JcTypedField |
27 | | -import org.jacodb.api.JcTypedMethod |
28 | | -import org.jacodb.api.throwClassNotFound |
| 21 | +import org.jacodb.api.* |
29 | 22 | import java.lang.Boolean |
30 | 23 | import java.lang.Byte |
31 | 24 | import java.lang.Double |
@@ -166,46 +159,31 @@ fun JcType.isAssignable(declaration: JcType): kotlin.Boolean { |
166 | 159 |
|
167 | 160 | /** |
168 | 161 | * find field by name |
| 162 | + * |
| 163 | + * @param name field name |
169 | 164 | */ |
170 | 165 | fun JcClassType.findFieldOrNull(name: String): JcTypedField? { |
171 | | - return findElements( |
172 | | - packageName = { jcClass.packageName }, |
173 | | - getAccessibles = { declaredFields }, |
174 | | - nextHierarchy = { listOfNotNull(superType) + interfaces}, |
175 | | - ) { |
176 | | - it.name == name |
177 | | - } |
| 166 | + return lookup.field(name) |
178 | 167 | } |
179 | 168 |
|
180 | | -fun JcClassType.findMethodOrNull(name: String, desc: String?): JcTypedMethod? { |
181 | | - return findMethodOrNull { |
182 | | - it.name == name && (desc == null || it.method.description == desc) |
183 | | - } |
| 169 | +/** |
| 170 | + * find method by name and description |
| 171 | + * |
| 172 | + * @param name method name |
| 173 | + * @param desc method description |
| 174 | + */ |
| 175 | +fun JcClassType.findMethodOrNull(name: String, desc: String): JcTypedMethod? { |
| 176 | + return lookup.method(name, desc) |
184 | 177 | } |
185 | 178 |
|
186 | 179 | /** |
187 | 180 | * find method by name and description |
| 181 | + * |
| 182 | + * This method doesn't support [org.jacodb.impl.features.classpaths.UnknownClasses] feature. |
188 | 183 | */ |
189 | | -fun JcClassType.findMethodOrNull( |
190 | | - predicate: (JcTypedMethod) -> kotlin.Boolean |
191 | | -): JcTypedMethod? { |
| 184 | +fun JcClassType.findMethodOrNull(predicate: (JcTypedMethod) -> kotlin.Boolean): JcTypedMethod? { |
192 | 185 | // let's find method based on strict hierarchy |
193 | 186 | // if method is not found then it's defined in interfaces |
194 | | - return findElements( |
195 | | - packageName = { jcClass.packageName }, |
196 | | - getAccessibles = { declaredMethods }, |
197 | | - nextHierarchy = { listOfNotNull(superType) + interfaces }, |
198 | | - predicate = predicate |
199 | | - ) |
200 | | -// if (method != null) { |
201 | | -// return method |
202 | | -// } |
203 | | -// // let's search interfaces |
204 | | -// return findElements( |
205 | | -// packageName = { jcClass.packageName }, |
206 | | -// getAccessibles = { declaredMethods }, |
207 | | -// nextHierarchy = { interfaces + superType?.interfaces.orEmpty() }, |
208 | | -// predicate = predicate |
209 | | -// ) |
| 187 | + return methods.firstOrNull(predicate) |
210 | 188 | } |
211 | 189 |
|
0 commit comments