Skip to content

Commit 0195607

Browse files
committed
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.
1 parent 789719a commit 0195607

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

extensions/ql-vscode/src/view/model-editor/MethodName.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,27 @@ const Name = styled.span`
77
word-break: break-all;
88
`;
99

10+
const TypeMethodName = (method: Method) => {
11+
if (!method.typeName) {
12+
return <>{method.methodName}</>;
13+
}
14+
15+
if (!method.methodName) {
16+
return <>{method.typeName}</>;
17+
}
18+
19+
return (
20+
<>
21+
{method.typeName}.{method.methodName}
22+
</>
23+
);
24+
};
25+
1026
export const MethodName = (method: Method): JSX.Element => {
1127
return (
1228
<Name>
1329
{method.packageName && <>{method.packageName}.</>}
14-
{method.typeName}.{method.methodName}
30+
<TypeMethodName {...method} />
1531
{method.methodParameters}
1632
</Name>
1733
);

extensions/ql-vscode/src/view/model-editor/__tests__/MethodName.spec.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,48 @@ describe(MethodName.name, () => {
2424
const name = `${method.typeName}.${method.methodName}${method.methodParameters}`;
2525
expect(screen.getByText(name)).toBeInTheDocument();
2626
});
27+
28+
it("renders method name without method name but with parameters", () => {
29+
const method = createMethod({
30+
packageName: "",
31+
methodName: "",
32+
});
33+
render(method);
34+
35+
const name = `${method.typeName}${method.methodParameters}`;
36+
expect(screen.getByText(name)).toBeInTheDocument();
37+
});
38+
39+
it("renders method name without method name and parameters", () => {
40+
const method = createMethod({
41+
packageName: "",
42+
methodName: "",
43+
methodParameters: "",
44+
});
45+
render(method);
46+
47+
const name = `${method.typeName}`;
48+
expect(screen.getByText(name)).toBeInTheDocument();
49+
});
50+
51+
it("renders method name without package and type name", () => {
52+
const method = createMethod({
53+
packageName: "",
54+
typeName: "",
55+
});
56+
render(method);
57+
58+
const name = `${method.methodName}${method.methodParameters}`;
59+
expect(screen.getByText(name)).toBeInTheDocument();
60+
});
61+
62+
it("renders method name without type name", () => {
63+
const method = createMethod({
64+
typeName: "",
65+
});
66+
render(method);
67+
68+
const name = `${method.packageName}.${method.methodName}${method.methodParameters}`;
69+
expect(screen.getByText(name)).toBeInTheDocument();
70+
});
2771
});

0 commit comments

Comments
 (0)