Skip to content

Commit ea064d8

Browse files
committed
Add API to get the array of method parameters given the qualified class name and the method signature.
Signed-off-by: Rahul Krishna <[email protected]>
1 parent cefedaa commit ea064d8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/analysis/java/JavaAnalysis.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,18 @@ export class JavaAnalysis {
248248
(method) => method.signature === methodName
249249
) ?? (() => { throw new Error(`Method ${methodName} not found in class ${qualifiedName}.`); })();
250250
}
251+
252+
/**
253+
* Get all the method parameters in a specific method within a specific class by its qualified name.
254+
* @param {string} qualifiedName - The qualified name of the class to retrieve
255+
* @param {string} methodName - The name of the method to retrieve
256+
* @returns {Promise<Array<types.JCallableParameterType>>} A promise that resolves to an array of {@link JCallableParameterType} objects
257+
* @throws {Error} If the class or method is not found in the application.
258+
*
259+
* @notes This method retrieves all the parameters of a specific method from the application by its qualified name
260+
* and method name. If the method is found, it returns an array of {@link JCallableParameter} objects representing
261+
*/
262+
public async getMethodParameters(qualifiedName: string, methodName: string): Promise<Array<types.JCallableParameterType>> {
263+
return (await this.getMethodByQualifiedName(qualifiedName, methodName)).parameters ?? [];
264+
}
251265
}

test/unit/analysis/java/JavaAnalysis.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JCallable, JType } from "../../../../src/models/java/";
1+
import { JCallable, JCallableParameter, JType } from "../../../../src/models/java/";
22
import { daytraderJavaAnalysis } from "../../../conftest";
33
import { expect, test } from "bun:test";
44

@@ -53,4 +53,15 @@ test("Must get a specific method in a specific class in the application", async
5353
"com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "publishQuotePriceChange(QuoteDataBean, BigDecimal, BigDecimal, double)");
5454

5555
expect(async () => JCallable.parse(method)).not.toThrow();
56+
});
57+
58+
test("Must get parameters of a specific method in a specific class in the application", async () => {
59+
const parameters = await daytraderJavaAnalysis.getMethodParameters(
60+
"com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "publishQuotePriceChange(QuoteDataBean, BigDecimal, BigDecimal, double)");
61+
62+
expect(parameters).toBeDefined();
63+
expect(parameters.length).toBeGreaterThan(0);
64+
parameters.forEach(param => {
65+
expect(async () => JCallableParameter.parse(param)).not.toThrow();
66+
});
5667
});

0 commit comments

Comments
 (0)