@@ -19,7 +19,7 @@ import fg from "fast-glob";
19
19
import fs from "fs" ;
20
20
import log from "loglevel" ;
21
21
import { spawnSync } from "node:child_process" ;
22
- import { JApplication } from "../../models/java" ;
22
+ import { JApplication , JCompilationUnit } from "../../models/java" ;
23
23
import * as types from "../../models/java/types" ;
24
24
import { JType } from "../../models/java" ;
25
25
import os from "os" ;
@@ -152,6 +152,15 @@ export class JavaAnalysis {
152
152
return this . application ;
153
153
}
154
154
155
+ /**
156
+ * Get the symbol table from the application.
157
+ * @returns {Promise<Record<string, types.JCompilationUnitType>> } A promise that resolves to a record of file paths and their
158
+ * corresponding {@link JCompilationUnitType} objects
159
+ *
160
+ * @notes This method retrieves the symbol table from the application, which contains information about all
161
+ * compilation units in the Java application. The returned record contains file paths as keys and their
162
+ * corresponding {@link JCompilationUnit} objects as values.
163
+ */
155
164
public async getSymbolTable ( ) : Promise < Record < string , types . JCompilationUnitType > > {
156
165
return ( await this . getApplication ( ) ) . symbol_table ;
157
166
}
@@ -222,4 +231,21 @@ export class JavaAnalysis {
222
231
const classForWhichMethodsAreRequested = await this . getClassByQualifiedName ( qualifiedName ) ;
223
232
return classForWhichMethodsAreRequested ? Object . values ( classForWhichMethodsAreRequested . callable_declarations ?? { } ) : [ ] ;
224
233
}
234
+
235
+ /**
236
+ * Get a specific methods within a specific class by its qualified name.
237
+ * @param {string } qualifiedName - The qualified name of the class to retrieve
238
+ * @param {string } methodName - The name of the method to retrieve
239
+ * @returns {Promise<types.JCallableType> } A promise that resolves to the {@link JCallable} object representing the method.
240
+ * @throws {Error } If the class or method is not found in the application.
241
+ *
242
+ * @notes This method retrieves a specific method from the application by its qualified name and method name.
243
+ * If the method is found, it returns the corresponding {@link JCallableType} object. If the method is not found,
244
+ * it throws an error.
245
+ */
246
+ public async getMethodByQualifiedName ( qualifiedName : string , methodName : string ) : Promise < types . JCallableType > {
247
+ return ( await this . getAllMethodsByClass ( qualifiedName ) ) . find (
248
+ ( method ) => method . signature === methodName
249
+ ) ?? ( ( ) => { throw new Error ( `Method ${ methodName } not found in class ${ qualifiedName } .` ) ; } ) ( ) ;
250
+ }
225
251
}
0 commit comments