@@ -2,41 +2,72 @@ import { DecodedBqrsChunk } from "../common/bqrs-cli-types";
22import { Call , CallClassification , Method } from "./method" ;
33import { ModeledMethodType } from "./modeled-method" ;
44import { parseLibraryFilename } from "./library" ;
5+ import { Mode } from "./shared/mode" ;
6+ import { ApplicationModeTuple , FrameworkModeTuple } from "./queries/query" ;
57
6- export function decodeBqrsToMethods ( chunk : DecodedBqrsChunk ) : Method [ ] {
8+ export function decodeBqrsToMethods (
9+ chunk : DecodedBqrsChunk ,
10+ mode : Mode ,
11+ ) : Method [ ] {
712 const methodsByApiName = new Map < string , Method > ( ) ;
813
914 chunk ?. tuples . forEach ( ( tuple ) => {
10- const usage = tuple [ 0 ] as Call ;
11- const signature = tuple [ 1 ] as string ;
12- const supported = ( tuple [ 2 ] as string ) === "true" ;
13- let library = tuple [ 4 ] as string ;
14- let libraryVersion : string | undefined = tuple [ 5 ] as string ;
15- const type = tuple [ 6 ] as ModeledMethodType ;
16- const classification = tuple [ 8 ] as CallClassification ;
15+ let usage : Call ;
16+ let packageName : string ;
17+ let typeName : string ;
18+ let methodName : string ;
19+ let methodParameters : string ;
20+ let supported : boolean ;
21+ let library : string ;
22+ let libraryVersion : string | undefined ;
23+ let type : ModeledMethodType ;
24+ let classification : CallClassification ;
1725
18- const [ packageWithType , methodDeclaration ] = signature . split ( "#" ) ;
26+ if ( mode === Mode . Application ) {
27+ [
28+ usage ,
29+ packageName ,
30+ typeName ,
31+ methodName ,
32+ methodParameters ,
33+ supported ,
34+ library ,
35+ libraryVersion ,
36+ type ,
37+ classification ,
38+ ] = tuple as ApplicationModeTuple ;
39+ } else {
40+ [
41+ usage ,
42+ packageName ,
43+ typeName ,
44+ methodName ,
45+ methodParameters ,
46+ supported ,
47+ library ,
48+ type ,
49+ ] = tuple as FrameworkModeTuple ;
50+
51+ classification = CallClassification . Unknown ;
52+ }
1953
20- const packageName = packageWithType . substring (
21- 0 ,
22- packageWithType . lastIndexOf ( "." ) ,
23- ) ;
24- const typeName = packageWithType . substring (
25- packageWithType . lastIndexOf ( "." ) + 1 ,
26- ) ;
54+ if ( ! methodParameters . startsWith ( "(" ) ) {
55+ // There's a difference in how the Java and C# queries return method parameters. In the C# query, the method
56+ // parameters are returned without parentheses. In the Java query, the method parameters are returned with
57+ // parentheses. Therefore, we'll just add them if we don't see them.
58+ methodParameters = `(${ methodParameters } )` ;
59+ }
2760
28- const methodName = methodDeclaration . substring (
29- 0 ,
30- methodDeclaration . indexOf ( "(" ) ,
31- ) ;
32- const methodParameters = methodDeclaration . substring (
33- methodDeclaration . indexOf ( "(" ) ,
34- ) ;
61+ const signature = `${ packageName } .${ typeName } #${ methodName } ${ methodParameters } ` ;
3562
3663 // For Java, we'll always get back a .jar file, and the library version may be bad because not all library authors
3764 // properly specify the version. Therefore, we'll always try to parse the name and version from the library filename
3865 // for Java.
39- if ( library . endsWith ( ".jar" ) || libraryVersion === "" ) {
66+ if (
67+ library . endsWith ( ".jar" ) ||
68+ libraryVersion === "" ||
69+ libraryVersion === undefined
70+ ) {
4071 const { name, version } = parseLibraryFilename ( library ) ;
4172 library = name ;
4273 if ( version ) {
0 commit comments