From 01956072b3c9c80330a4457d971a56d04a99f9ca Mon Sep 17 00:00:00 2001 From: Koen Vlaswinkel Date: Thu, 7 Dec 2023 16:18:21 +0100 Subject: [PATCH 1/2] Fix rendering of method names This fixes the rendering of method names when either the type or method name is empty. This can happen when the method is a not in a class or when the method is a synthetic method and the properties actually apply to the type. --- .../src/view/model-editor/MethodName.tsx | 18 +++++++- .../__tests__/MethodName.spec.tsx | 44 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/extensions/ql-vscode/src/view/model-editor/MethodName.tsx b/extensions/ql-vscode/src/view/model-editor/MethodName.tsx index b46ef0653..f01891d89 100644 --- a/extensions/ql-vscode/src/view/model-editor/MethodName.tsx +++ b/extensions/ql-vscode/src/view/model-editor/MethodName.tsx @@ -7,11 +7,27 @@ const Name = styled.span` word-break: break-all; `; +const TypeMethodName = (method: Method) => { + if (!method.typeName) { + return <>{method.methodName}; + } + + if (!method.methodName) { + return <>{method.typeName}; + } + + return ( + <> + {method.typeName}.{method.methodName} + + ); +}; + export const MethodName = (method: Method): JSX.Element => { return ( {method.packageName && <>{method.packageName}.} - {method.typeName}.{method.methodName} + {method.methodParameters} ); diff --git a/extensions/ql-vscode/src/view/model-editor/__tests__/MethodName.spec.tsx b/extensions/ql-vscode/src/view/model-editor/__tests__/MethodName.spec.tsx index ac79c708e..4a4422270 100644 --- a/extensions/ql-vscode/src/view/model-editor/__tests__/MethodName.spec.tsx +++ b/extensions/ql-vscode/src/view/model-editor/__tests__/MethodName.spec.tsx @@ -24,4 +24,48 @@ describe(MethodName.name, () => { const name = `${method.typeName}.${method.methodName}${method.methodParameters}`; expect(screen.getByText(name)).toBeInTheDocument(); }); + + it("renders method name without method name but with parameters", () => { + const method = createMethod({ + packageName: "", + methodName: "", + }); + render(method); + + const name = `${method.typeName}${method.methodParameters}`; + expect(screen.getByText(name)).toBeInTheDocument(); + }); + + it("renders method name without method name and parameters", () => { + const method = createMethod({ + packageName: "", + methodName: "", + methodParameters: "", + }); + render(method); + + const name = `${method.typeName}`; + expect(screen.getByText(name)).toBeInTheDocument(); + }); + + it("renders method name without package and type name", () => { + const method = createMethod({ + packageName: "", + typeName: "", + }); + render(method); + + const name = `${method.methodName}${method.methodParameters}`; + expect(screen.getByText(name)).toBeInTheDocument(); + }); + + it("renders method name without type name", () => { + const method = createMethod({ + typeName: "", + }); + render(method); + + const name = `${method.packageName}.${method.methodName}${method.methodParameters}`; + expect(screen.getByText(name)).toBeInTheDocument(); + }); }); From 0a4d28e9f0a77cdc1469491ab8b117e60e1ca4b3 Mon Sep 17 00:00:00 2001 From: Koen Vlaswinkel Date: Thu, 7 Dec 2023 16:23:30 +0100 Subject: [PATCH 2/2] Fix empty method names in output for Ruby This fixes the output of the Ruby MaD models when the method name is empty which can happen when the model applies to a type rather than to a method. --- .../src/model-editor/languages/ruby/index.ts | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/extensions/ql-vscode/src/model-editor/languages/ruby/index.ts b/extensions/ql-vscode/src/model-editor/languages/ruby/index.ts index b5209703a..0c3354706 100644 --- a/extensions/ql-vscode/src/model-editor/languages/ruby/index.ts +++ b/extensions/ql-vscode/src/model-editor/languages/ruby/index.ts @@ -29,6 +29,23 @@ function rubyMethodSignature(typeName: string, methodName: string) { return `${typeName}#${methodName}`; } +function rubyMethodPath(methodName: string) { + if (methodName === "") { + return ""; + } + + return `Method[${methodName}]`; +} + +function rubyPath(methodName: string, path: string) { + const methodPath = rubyMethodPath(methodName); + if (methodPath === "") { + return path; + } + + return `${methodPath}.${path}`; +} + export const ruby: ModelsAsDataLanguage = { availableModes: [Mode.Framework], createMethodSignature: ({ typeName, methodName }) => @@ -42,7 +59,7 @@ export const ruby: ModelsAsDataLanguage = { // ); generateMethodDefinition: (method) => [ method.typeName, - `Method[${method.methodName}].${method.output}`, + rubyPath(method.methodName, method.output), method.kind, ], readModeledMethod: (row) => { @@ -71,8 +88,11 @@ export const ruby: ModelsAsDataLanguage = { // string type, string path, string kind // ); generateMethodDefinition: (method) => { - const path = `Method[${method.methodName}].${method.input}`; - return [method.typeName, path, method.kind]; + return [ + method.typeName, + rubyPath(method.methodName, method.input), + method.kind, + ]; }, readModeledMethod: (row) => { const typeName = row[0] as string; @@ -101,7 +121,7 @@ export const ruby: ModelsAsDataLanguage = { // ); generateMethodDefinition: (method) => [ method.typeName, - `Method[${method.methodName}]`, + rubyMethodPath(method.methodName), method.input, method.output, method.kind, @@ -131,7 +151,7 @@ export const ruby: ModelsAsDataLanguage = { // ); generateMethodDefinition: (method) => [ method.typeName, - `Method[${method.methodName}]`, + rubyMethodPath(method.methodName), method.kind, ], readModeledMethod: (row) => { @@ -157,7 +177,7 @@ export const ruby: ModelsAsDataLanguage = { generateMethodDefinition: (method) => [ method.relatedTypeName, method.typeName, - `Method[${method.methodName}].${method.path}`, + rubyPath(method.methodName, method.path), ], readModeledMethod: (row) => { const typeName = row[1] as string;