@alloy-js/csharp 0.20.0-dev.2 → 0.20.0-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/Declaration.d.ts +2 -2
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -13
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +5 -1
- package/dist/src/components/SourceFile.d.ts +8 -9
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +69 -45
- package/dist/src/components/UsingDirective.d.ts +5 -1
- package/dist/src/components/UsingDirective.d.ts.map +1 -1
- package/dist/src/components/UsingDirective.js +3 -1
- package/dist/src/components/class/declaration.d.ts +2 -2
- package/dist/src/components/class/declaration.d.ts.map +1 -1
- package/dist/src/components/class/declaration.js +19 -33
- package/dist/src/components/class/declaration.test.js +192 -193
- package/dist/src/components/constructor/constructor.d.ts.map +1 -1
- package/dist/src/components/constructor/constructor.js +11 -19
- package/dist/src/components/constructor/constructor.test.js +10 -19
- package/dist/src/components/{EnumDeclaration.d.ts → enum/declaration.d.ts} +6 -11
- package/dist/src/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.js +54 -0
- package/dist/src/components/enum/declaration.ref.test.d.ts +2 -0
- package/dist/src/components/enum/declaration.ref.test.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.ref.test.js +120 -0
- package/dist/src/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/components/enum/declaration.test.js +39 -0
- package/dist/src/components/enum/member.d.ts +7 -0
- package/dist/src/components/enum/member.d.ts.map +1 -0
- package/dist/src/components/enum/member.js +29 -0
- package/dist/src/components/enum/member.test.d.ts +2 -0
- package/dist/src/components/enum/member.test.d.ts.map +1 -0
- package/dist/src/components/enum/member.test.js +28 -0
- package/dist/src/components/field/field.d.ts.map +1 -1
- package/dist/src/components/field/field.js +9 -17
- package/dist/src/components/field/field.test.js +7 -7
- package/dist/src/components/index.d.ts +5 -2
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +5 -2
- package/dist/src/components/interface/declaration.d.ts.map +1 -1
- package/dist/src/components/interface/declaration.js +19 -21
- package/dist/src/components/interface/declaration.test.js +26 -35
- package/dist/src/components/interface/method.d.ts.map +1 -1
- package/dist/src/components/interface/method.js +7 -18
- package/dist/src/components/interface/method.test.js +38 -47
- package/dist/src/components/interface/property.d.ts.map +1 -1
- package/dist/src/components/interface/property.js +21 -39
- package/dist/src/components/interface/property.test.js +11 -11
- package/dist/src/components/lexical-scope.d.ts +8 -0
- package/dist/src/components/lexical-scope.d.ts.map +1 -0
- package/dist/src/components/lexical-scope.js +24 -0
- package/dist/src/components/method/method.d.ts +5 -2
- package/dist/src/components/method/method.d.ts.map +1 -1
- package/dist/src/components/method/method.js +7 -16
- package/dist/src/components/method/method.test.js +11 -11
- package/dist/src/components/method-scope.d.ts +8 -0
- package/dist/src/components/method-scope.d.ts.map +1 -0
- package/dist/src/components/method-scope.js +24 -0
- package/dist/src/components/namespace-scopes.d.ts +13 -0
- package/dist/src/components/namespace-scopes.d.ts.map +1 -0
- package/dist/src/components/namespace-scopes.js +44 -0
- package/dist/src/components/namespace.d.ts +7 -0
- package/dist/src/components/namespace.d.ts.map +1 -0
- package/dist/src/components/namespace.js +46 -0
- package/dist/src/components/namespace.ref.test.d.ts +2 -0
- package/dist/src/components/namespace.ref.test.d.ts.map +1 -0
- package/dist/src/components/namespace.ref.test.js +181 -0
- package/dist/src/components/namespace.test.d.ts.map +1 -0
- package/dist/src/components/namespace.test.js +78 -0
- package/dist/src/components/parameters/parameters.d.ts +2 -2
- package/dist/src/components/parameters/parameters.d.ts.map +1 -1
- package/dist/src/components/parameters/parameters.js +12 -14
- package/dist/src/components/parameters/parameters.test.d.ts +2 -0
- package/dist/src/components/parameters/parameters.test.d.ts.map +1 -0
- package/dist/src/components/parameters/parameters.test.js +87 -0
- package/dist/src/components/property/property.d.ts.map +1 -1
- package/dist/src/components/property/property.js +21 -39
- package/dist/src/components/property/property.test.js +14 -14
- package/dist/src/components/record/declaration.d.ts +18 -0
- package/dist/src/components/record/declaration.d.ts.map +1 -1
- package/dist/src/components/record/declaration.js +19 -13
- package/dist/src/components/record/declaration.test.js +50 -3
- package/dist/src/components/struct/declaration.d.ts.map +1 -1
- package/dist/src/components/struct/declaration.js +4 -6
- package/dist/src/components/struct/declaration.test.js +30 -39
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
- package/dist/src/components/type-parameters/type-parameter.js +7 -10
- package/dist/src/components/type-parameters/type-parameters.test.js +3 -3
- package/dist/src/components/var/declaration.d.ts.map +1 -1
- package/dist/src/components/var/declaration.js +6 -8
- package/dist/src/components/var/declaration.test.js +11 -20
- package/dist/src/contexts/global-namespace.d.ts +5 -0
- package/dist/src/contexts/global-namespace.d.ts.map +1 -0
- package/dist/src/contexts/global-namespace.js +24 -0
- package/dist/src/contexts/namespace.d.ts +8 -0
- package/dist/src/contexts/namespace.d.ts.map +1 -0
- package/dist/src/contexts/namespace.js +5 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/modifiers.d.ts +11 -0
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/scopes/class.d.ts +10 -0
- package/dist/src/scopes/class.d.ts.map +1 -0
- package/dist/src/scopes/class.js +10 -0
- package/dist/src/scopes/contexts.d.ts +9 -0
- package/dist/src/scopes/contexts.d.ts.map +1 -0
- package/dist/src/scopes/contexts.js +33 -0
- package/dist/src/scopes/csharp.d.ts +8 -0
- package/dist/src/scopes/csharp.d.ts.map +1 -0
- package/dist/src/scopes/csharp.js +11 -0
- package/dist/src/scopes/factories.d.ts +9 -0
- package/dist/src/scopes/factories.d.ts.map +1 -0
- package/dist/src/scopes/factories.js +23 -0
- package/dist/src/scopes/index.d.ts +10 -0
- package/dist/src/scopes/index.d.ts.map +1 -0
- package/dist/src/scopes/index.js +9 -0
- package/dist/src/scopes/lexical.d.ts +7 -0
- package/dist/src/scopes/lexical.d.ts.map +1 -0
- package/dist/src/scopes/lexical.js +7 -0
- package/dist/src/scopes/method.d.ts +9 -0
- package/dist/src/scopes/method.d.ts.map +1 -0
- package/dist/src/scopes/method.js +13 -0
- package/dist/src/scopes/named-type.d.ts +22 -0
- package/dist/src/scopes/named-type.d.ts.map +1 -0
- package/dist/src/scopes/named-type.js +32 -0
- package/dist/src/scopes/namespace.d.ts +11 -0
- package/dist/src/scopes/namespace.d.ts.map +1 -0
- package/dist/src/scopes/namespace.js +38 -0
- package/dist/src/scopes/source-file.d.ts +16 -0
- package/dist/src/scopes/source-file.d.ts.map +1 -0
- package/dist/src/scopes/source-file.js +43 -0
- package/dist/src/symbols/csharp.d.ts +76 -0
- package/dist/src/symbols/csharp.d.ts.map +1 -0
- package/dist/src/symbols/csharp.js +222 -0
- package/dist/src/symbols/factories.d.ts +25 -0
- package/dist/src/symbols/factories.d.ts.map +1 -0
- package/dist/src/symbols/factories.js +86 -0
- package/dist/src/symbols/index.d.ts +5 -2
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +6 -3
- package/dist/src/symbols/method.d.ts +13 -0
- package/dist/src/symbols/method.d.ts.map +1 -0
- package/dist/src/symbols/method.js +15 -0
- package/dist/src/symbols/named-type.d.ts +19 -0
- package/dist/src/symbols/named-type.d.ts.map +1 -0
- package/dist/src/symbols/named-type.js +30 -0
- package/dist/src/symbols/namespace.d.ts +22 -0
- package/dist/src/symbols/namespace.d.ts.map +1 -0
- package/dist/src/symbols/namespace.js +44 -0
- package/dist/src/symbols/reference.d.ts +2 -2
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +36 -43
- package/dist/test/project-directory.test.js +12 -16
- package/dist/test/sourcefile.test.js +7 -19
- package/dist/test/using.test.js +18 -16
- package/dist/test/utils.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -4
- package/src/components/Declaration.tsx +3 -6
- package/src/components/Reference.tsx +3 -1
- package/src/components/SourceFile.tsx +68 -55
- package/src/components/UsingDirective.tsx +12 -2
- package/src/components/class/declaration.test.tsx +138 -143
- package/src/components/class/declaration.tsx +20 -33
- package/src/components/constructor/constructor.test.tsx +10 -16
- package/src/components/constructor/constructor.tsx +13 -32
- package/src/components/enum/declaration.ref.test.tsx +93 -0
- package/src/components/enum/declaration.test.tsx +34 -0
- package/src/components/enum/declaration.tsx +65 -0
- package/src/components/enum/member.test.tsx +24 -0
- package/src/components/enum/member.tsx +36 -0
- package/src/components/field/field.test.tsx +7 -7
- package/src/components/field/field.tsx +12 -22
- package/src/components/index.ts +5 -2
- package/src/components/interface/declaration.test.tsx +26 -32
- package/src/components/interface/declaration.tsx +16 -18
- package/src/components/interface/method.test.tsx +38 -44
- package/src/components/interface/method.tsx +7 -20
- package/src/components/interface/property.test.tsx +11 -11
- package/src/components/interface/property.tsx +15 -34
- package/src/components/lexical-scope.tsx +29 -0
- package/src/components/method/method.test.tsx +11 -11
- package/src/components/method/method.tsx +12 -23
- package/src/components/method-scope.tsx +27 -0
- package/src/components/namespace-scopes.tsx +44 -0
- package/src/components/namespace.ref.test.tsx +139 -0
- package/src/components/namespace.test.tsx +52 -0
- package/src/components/namespace.tsx +45 -0
- package/src/components/parameters/parameters.test.tsx +71 -0
- package/src/components/parameters/parameters.tsx +9 -21
- package/src/components/property/property.test.tsx +14 -14
- package/src/components/property/property.tsx +17 -41
- package/src/components/record/declaration.test.tsx +47 -3
- package/src/components/record/declaration.tsx +34 -11
- package/src/components/struct/declaration.test.tsx +16 -22
- package/src/components/struct/declaration.tsx +4 -6
- package/src/components/type-parameters/type-parameter.tsx +14 -11
- package/src/components/type-parameters/type-parameters.test.tsx +4 -4
- package/src/components/var/declaration.test.tsx +8 -14
- package/src/components/var/declaration.tsx +12 -6
- package/src/contexts/global-namespace.ts +29 -0
- package/src/contexts/namespace.ts +13 -0
- package/src/index.ts +1 -0
- package/src/modifiers.ts +14 -0
- package/src/scopes/class.ts +12 -0
- package/src/scopes/contexts.ts +45 -0
- package/src/scopes/csharp.ts +18 -0
- package/src/scopes/factories.ts +45 -0
- package/src/scopes/index.ts +9 -0
- package/src/scopes/lexical.ts +10 -0
- package/src/scopes/method.ts +22 -0
- package/src/scopes/named-type.ts +44 -0
- package/src/scopes/namespace.ts +59 -0
- package/src/scopes/source-file.ts +67 -0
- package/src/symbols/csharp.ts +307 -0
- package/src/symbols/factories.ts +199 -0
- package/src/symbols/index.ts +5 -2
- package/src/symbols/method.ts +26 -0
- package/src/symbols/named-type.ts +54 -0
- package/src/symbols/namespace.ts +62 -0
- package/src/symbols/reference.ts +47 -50
- package/temp/api.json +6152 -2151
- package/test/project-directory.test.tsx +12 -16
- package/test/sourcefile.test.tsx +7 -21
- package/test/using.test.tsx +18 -16
- package/test/utils.tsx +1 -1
- package/tsdoc-metadata.json +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.js +0 -85
- package/dist/src/components/Namespace.d.ts +0 -11
- package/dist/src/components/Namespace.d.ts.map +0 -1
- package/dist/src/components/Namespace.js +0 -33
- package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
- package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
- package/dist/src/symbols/csharp-output-symbol.js +0 -19
- package/dist/src/symbols/scopes.d.ts +0 -14
- package/dist/src/symbols/scopes.d.ts.map +0 -1
- package/dist/src/symbols/scopes.js +0 -31
- package/dist/test/enum.test.d.ts +0 -2
- package/dist/test/enum.test.d.ts.map +0 -1
- package/dist/test/enum.test.js +0 -178
- package/dist/test/namespace.test.d.ts.map +0 -1
- package/dist/test/namespace.test.js +0 -81
- package/src/components/EnumDeclaration.tsx +0 -99
- package/src/components/Namespace.tsx +0 -35
- package/src/symbols/csharp-output-symbol.ts +0 -22
- package/src/symbols/scopes.ts +0 -41
- package/test/enum.test.tsx +0 -149
- package/test/namespace.test.tsx +0 -55
- /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OutputScope,
|
|
3
|
+
OutputScopeOptions,
|
|
4
|
+
shallowReactive,
|
|
5
|
+
track,
|
|
6
|
+
TrackOpTypes,
|
|
7
|
+
trigger,
|
|
8
|
+
TriggerOpTypes,
|
|
9
|
+
useScope,
|
|
10
|
+
} from "@alloy-js/core";
|
|
11
|
+
import { NamespaceSymbol } from "../symbols/namespace.js";
|
|
12
|
+
import { CSharpLexicalScope } from "./lexical.js";
|
|
13
|
+
import { CSharpNamespaceScope } from "./namespace.js";
|
|
14
|
+
|
|
15
|
+
export class CSharpSourceFileScope extends CSharpLexicalScope {
|
|
16
|
+
#usings = shallowReactive<Set<NamespaceSymbol>>(new Set());
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
name: string,
|
|
20
|
+
parent?: CSharpNamespaceScope,
|
|
21
|
+
options?: OutputScopeOptions,
|
|
22
|
+
) {
|
|
23
|
+
super(name, parent, options);
|
|
24
|
+
}
|
|
25
|
+
get usings() {
|
|
26
|
+
return this.#usings;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get parent() {
|
|
30
|
+
return super.parent! as CSharpNamespaceScope;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set parent(v: CSharpNamespaceScope) {
|
|
34
|
+
super.parent = v;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
addUsing(using: NamespaceSymbol) {
|
|
38
|
+
this.#usings.add(using);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#hasBlockNamespace: boolean = false;
|
|
42
|
+
get hasBlockNamespace() {
|
|
43
|
+
track(this, TrackOpTypes.GET, "hasBlockNamespace");
|
|
44
|
+
return this.#hasBlockNamespace;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
set hasBlockNamespace(value: boolean) {
|
|
48
|
+
const old = this.#hasBlockNamespace;
|
|
49
|
+
if (this.#hasBlockNamespace === value) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.#hasBlockNamespace = value;
|
|
53
|
+
trigger(this, TriggerOpTypes.SET, "hasBlockNamespace", value, old);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function useSourceFileScope() {
|
|
58
|
+
let scope: OutputScope | undefined = useScope();
|
|
59
|
+
while (scope) {
|
|
60
|
+
if (scope instanceof CSharpSourceFileScope) {
|
|
61
|
+
return scope;
|
|
62
|
+
}
|
|
63
|
+
scope = scope.parent;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Namekey,
|
|
3
|
+
OutputDeclarationSpace,
|
|
4
|
+
OutputMemberSpace,
|
|
5
|
+
OutputSpace,
|
|
6
|
+
OutputSymbol,
|
|
7
|
+
OutputSymbolOptions,
|
|
8
|
+
track,
|
|
9
|
+
TrackOpTypes,
|
|
10
|
+
trigger,
|
|
11
|
+
TriggerOpTypes,
|
|
12
|
+
watch,
|
|
13
|
+
} from "@alloy-js/core";
|
|
14
|
+
import { AccessModifiers, NonAccessModifiers } from "../modifiers.js";
|
|
15
|
+
import type { CSharpScope } from "../scopes/csharp.js";
|
|
16
|
+
import { NamespaceSymbol } from "./namespace.js";
|
|
17
|
+
|
|
18
|
+
export type DeclaredAccessibility =
|
|
19
|
+
| "private"
|
|
20
|
+
| "protected"
|
|
21
|
+
| "internal"
|
|
22
|
+
| "public";
|
|
23
|
+
|
|
24
|
+
export interface CSharpSymbolOptions extends OutputSymbolOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The accessibility of the symbol.
|
|
27
|
+
*/
|
|
28
|
+
accessibility?: DeclaredAccessibility;
|
|
29
|
+
isOverride?: boolean;
|
|
30
|
+
isAbstract?: boolean;
|
|
31
|
+
isVirtual?: boolean;
|
|
32
|
+
isStatic?: boolean;
|
|
33
|
+
isSealed?: boolean;
|
|
34
|
+
isExtern?: boolean;
|
|
35
|
+
isReadOnly?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type CSharpSymbolKinds =
|
|
39
|
+
| "symbol"
|
|
40
|
+
| "named-type"
|
|
41
|
+
| "method"
|
|
42
|
+
| "field"
|
|
43
|
+
| "property"
|
|
44
|
+
| "namespace"
|
|
45
|
+
| "event";
|
|
46
|
+
/**
|
|
47
|
+
* This is the base type for all symbols in C#.
|
|
48
|
+
*
|
|
49
|
+
* Many subtypes of this symbol exist for specific purposes. However, this symbol
|
|
50
|
+
* may be used in cases where a more specific symbol is not required.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
*
|
|
54
|
+
* This is roughly equivalent to the Roslyn ISymbol interface:
|
|
55
|
+
* https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.isymbol?view=roslyn-dotnet-4.13.0
|
|
56
|
+
*/
|
|
57
|
+
export class CSharpSymbol extends OutputSymbol {
|
|
58
|
+
public readonly symbolKind: CSharpSymbolKinds = "symbol";
|
|
59
|
+
|
|
60
|
+
constructor(
|
|
61
|
+
name: string | Namekey,
|
|
62
|
+
spaces: OutputSpace[] | OutputSpace | undefined,
|
|
63
|
+
options: CSharpSymbolOptions = {},
|
|
64
|
+
) {
|
|
65
|
+
super(name, spaces, options);
|
|
66
|
+
|
|
67
|
+
this.#accessibility = options.accessibility;
|
|
68
|
+
this.#isAbstract = options.isAbstract ?? false;
|
|
69
|
+
this.#isVirtual = options.isVirtual ?? false;
|
|
70
|
+
this.#isStatic = options.isStatic ?? false;
|
|
71
|
+
this.#isOverride = options.isOverride ?? false;
|
|
72
|
+
this.#isSealed = options.isSealed ?? false;
|
|
73
|
+
this.#isExtern = options.isExtern ?? false;
|
|
74
|
+
this.#isReadOnly = options.isReadOnly ?? false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get enclosingNamespace(): NamespaceSymbol | undefined {
|
|
78
|
+
if (this.spaces.length === 0) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// todo: probably need to validate that a symbol can't belong to spaces in
|
|
83
|
+
// multiple namespaces.
|
|
84
|
+
const firstSpace = this.spaces[0];
|
|
85
|
+
|
|
86
|
+
if (firstSpace instanceof OutputMemberSpace) {
|
|
87
|
+
// this symbol is a member of something, so get the enclosing namespace from
|
|
88
|
+
// the symbol.
|
|
89
|
+
|
|
90
|
+
if (firstSpace.symbol.constructor.name === "NamespaceSymbol") {
|
|
91
|
+
// this is a namespace symbol, so return the namespace symbol itself.
|
|
92
|
+
// can't use instanceof here due to circular reference issues.
|
|
93
|
+
return firstSpace.symbol as NamespaceSymbol;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (firstSpace.symbol as CSharpSymbol).enclosingNamespace;
|
|
97
|
+
} else if (firstSpace instanceof OutputDeclarationSpace) {
|
|
98
|
+
// this symbol is in a lexical scope, so get the namespace symbol from the
|
|
99
|
+
// scope.
|
|
100
|
+
return (firstSpace.scope as CSharpScope).enclosingNamespace;
|
|
101
|
+
}
|
|
102
|
+
throw new Error("No place to get namespace symbol from");
|
|
103
|
+
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#accessibility: DeclaredAccessibility | undefined;
|
|
108
|
+
get accessibility() {
|
|
109
|
+
track(this, TrackOpTypes.GET, "accessibility");
|
|
110
|
+
return this.#accessibility;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
set accessibility(value: DeclaredAccessibility | undefined) {
|
|
114
|
+
const old = this.#accessibility;
|
|
115
|
+
if (old === value) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.#accessibility = value;
|
|
120
|
+
|
|
121
|
+
trigger(this, TriggerOpTypes.SET, "accessibility", value, old);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
copy() {
|
|
125
|
+
const options = this.getCopyOptions();
|
|
126
|
+
const copy = new CSharpSymbol(this.name, undefined, {
|
|
127
|
+
...options,
|
|
128
|
+
accessibility: this.#accessibility,
|
|
129
|
+
isStatic: this.#isStatic,
|
|
130
|
+
isVirtual: this.#isVirtual,
|
|
131
|
+
isAbstract: this.#isAbstract,
|
|
132
|
+
isOverride: this.#isOverride,
|
|
133
|
+
isSealed: this.#isSealed,
|
|
134
|
+
isExtern: this.#isExtern,
|
|
135
|
+
isReadOnly: this.#isReadOnly,
|
|
136
|
+
});
|
|
137
|
+
this.initializeCopy(copy);
|
|
138
|
+
|
|
139
|
+
watch(
|
|
140
|
+
() => this.accessibility,
|
|
141
|
+
(newAccessibility) => {
|
|
142
|
+
copy.accessibility = newAccessibility;
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return copy;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Whether this symbol is static.
|
|
151
|
+
*/
|
|
152
|
+
get isStatic(): boolean {
|
|
153
|
+
track(this, TrackOpTypes.GET, "isStatic");
|
|
154
|
+
return this.#isStatic;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
set isStatic(value: boolean) {
|
|
158
|
+
const old = this.#isStatic;
|
|
159
|
+
if (old === value) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.#isStatic = value;
|
|
164
|
+
|
|
165
|
+
trigger(this, TriggerOpTypes.SET, "isStatic", value, old);
|
|
166
|
+
}
|
|
167
|
+
#isStatic: boolean = false;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether this symbol is virtual.
|
|
171
|
+
*/
|
|
172
|
+
get isVirtual(): boolean {
|
|
173
|
+
track(this, TrackOpTypes.GET, "isVirtual");
|
|
174
|
+
return this.#isVirtual;
|
|
175
|
+
}
|
|
176
|
+
set isVirtual(value: boolean) {
|
|
177
|
+
const old = this.#isVirtual;
|
|
178
|
+
if (old === value) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
this.#isVirtual = value;
|
|
183
|
+
|
|
184
|
+
trigger(this, TriggerOpTypes.SET, "isVirtual", value, old);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
#isVirtual: boolean = false;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Whether this symbol is abstract.
|
|
191
|
+
*/
|
|
192
|
+
get isAbstract(): boolean {
|
|
193
|
+
track(this, TrackOpTypes.GET, "isAbstract");
|
|
194
|
+
return this.#isAbstract;
|
|
195
|
+
}
|
|
196
|
+
set isAbstract(value: boolean) {
|
|
197
|
+
const old = this.#isAbstract;
|
|
198
|
+
if (old === value) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
this.#isAbstract = value;
|
|
203
|
+
|
|
204
|
+
trigger(this, TriggerOpTypes.SET, "isAbstract", value, old);
|
|
205
|
+
}
|
|
206
|
+
#isAbstract: boolean = false;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Whether this symbol is override.
|
|
210
|
+
*/
|
|
211
|
+
get isOverride(): boolean {
|
|
212
|
+
track(this, TrackOpTypes.GET, "isOverride");
|
|
213
|
+
return this.#isOverride;
|
|
214
|
+
}
|
|
215
|
+
set isOverride(value: boolean) {
|
|
216
|
+
const old = this.#isOverride;
|
|
217
|
+
if (old === value) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.#isOverride = value;
|
|
222
|
+
|
|
223
|
+
trigger(this, TriggerOpTypes.SET, "isOverride", value, old);
|
|
224
|
+
}
|
|
225
|
+
#isOverride: boolean = false;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Whether this symbol is sealed.
|
|
229
|
+
*/
|
|
230
|
+
get isSealed(): boolean {
|
|
231
|
+
track(this, TrackOpTypes.GET, "isSealed");
|
|
232
|
+
return this.#isSealed;
|
|
233
|
+
}
|
|
234
|
+
set isSealed(value: boolean) {
|
|
235
|
+
const old = this.#isSealed;
|
|
236
|
+
if (old === value) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
this.#isSealed = value;
|
|
241
|
+
|
|
242
|
+
trigger(this, TriggerOpTypes.SET, "isSealed", value, old);
|
|
243
|
+
}
|
|
244
|
+
#isSealed: boolean = false;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Whether this symbol is extern.
|
|
248
|
+
*/
|
|
249
|
+
get isExtern(): boolean {
|
|
250
|
+
track(this, TrackOpTypes.GET, "isExtern");
|
|
251
|
+
return this.#isExtern;
|
|
252
|
+
}
|
|
253
|
+
set isExtern(value: boolean) {
|
|
254
|
+
const old = this.#isExtern;
|
|
255
|
+
if (old === value) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
this.#isExtern = value;
|
|
260
|
+
|
|
261
|
+
trigger(this, TriggerOpTypes.SET, "isExtern", value, old);
|
|
262
|
+
}
|
|
263
|
+
#isExtern: boolean = false;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Whether this symbol is readonly.
|
|
267
|
+
*/
|
|
268
|
+
get isReadOnly(): boolean {
|
|
269
|
+
track(this, TrackOpTypes.GET, "isReadOnly");
|
|
270
|
+
return this.#isReadOnly;
|
|
271
|
+
}
|
|
272
|
+
set isReadOnly(value: boolean) {
|
|
273
|
+
const old = this.#isReadOnly;
|
|
274
|
+
if (old === value) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
this.#isReadOnly = value;
|
|
279
|
+
|
|
280
|
+
trigger(this, TriggerOpTypes.SET, "isReadOnly", value, old);
|
|
281
|
+
}
|
|
282
|
+
#isReadOnly: boolean = false;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function accessibilityFromProps(props: AccessModifiers) {
|
|
286
|
+
for (const key of ["public", "internal", "protected", "private"] as const) {
|
|
287
|
+
if (props[key]) {
|
|
288
|
+
return key;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return "private";
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function nonAccessibilityFromProps(
|
|
296
|
+
props: NonAccessModifiers,
|
|
297
|
+
): CSharpSymbolOptions {
|
|
298
|
+
return {
|
|
299
|
+
isOverride: props.override ?? false,
|
|
300
|
+
isAbstract: props.abstract ?? false,
|
|
301
|
+
isVirtual: props.virtual ?? false,
|
|
302
|
+
isStatic: props.static ?? false,
|
|
303
|
+
isSealed: props.sealed ?? false,
|
|
304
|
+
isExtern: props.extern ?? false,
|
|
305
|
+
isReadOnly: props.readOnly ?? false,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Namekey,
|
|
3
|
+
NamePolicyGetter,
|
|
4
|
+
OutputSymbolOptions,
|
|
5
|
+
useBinder,
|
|
6
|
+
} from "@alloy-js/core";
|
|
7
|
+
import { getGlobalNamespace } from "../contexts/global-namespace.js";
|
|
8
|
+
import { CSharpElements, useCSharpNamePolicy } from "../name-policy.js";
|
|
9
|
+
import { CSharpClassScope } from "../scopes/class.js";
|
|
10
|
+
import { useCSharpScope, useNamedTypeScope } from "../scopes/contexts.js";
|
|
11
|
+
import { CSharpScope } from "../scopes/csharp.js";
|
|
12
|
+
import { CSharpLexicalScope } from "../scopes/lexical.js";
|
|
13
|
+
import { CSharpMethodScope } from "../scopes/method.js";
|
|
14
|
+
import { CSharpNamedTypeScope } from "../scopes/named-type.js";
|
|
15
|
+
import {
|
|
16
|
+
CSharpNamespaceScope,
|
|
17
|
+
useEnclosingNamespaceScope,
|
|
18
|
+
} from "../scopes/namespace.js";
|
|
19
|
+
import { CSharpSourceFileScope } from "../scopes/source-file.js";
|
|
20
|
+
import { CSharpSymbol, CSharpSymbolOptions } from "./csharp.js";
|
|
21
|
+
import { MethodKinds, MethodSymbol } from "./method.js";
|
|
22
|
+
import { NamedTypeSymbol, NamedTypeTypeKind } from "./named-type.js";
|
|
23
|
+
import { NamespaceSymbol } from "./namespace.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a symbol for a parameter in the current method scope.
|
|
27
|
+
*/
|
|
28
|
+
export function createParameterSymbol(
|
|
29
|
+
originalName: string | Namekey,
|
|
30
|
+
options: CSharpSymbolOptions = {},
|
|
31
|
+
) {
|
|
32
|
+
const scope = useCSharpScope();
|
|
33
|
+
if (
|
|
34
|
+
!(scope instanceof CSharpMethodScope) &&
|
|
35
|
+
!(scope instanceof CSharpClassScope)
|
|
36
|
+
) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Can't create parameter symbol outside of a method or class scope.`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return new CSharpSymbol(
|
|
42
|
+
originalName,
|
|
43
|
+
scope.parameters,
|
|
44
|
+
withNamePolicy(options, "parameter"),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface CreateTypeParameterSymbolOptions extends CSharpSymbolOptions {
|
|
49
|
+
scope?: CSharpMethodScope | CSharpNamedTypeScope;
|
|
50
|
+
}
|
|
51
|
+
export function createTypeParameterSymbol(
|
|
52
|
+
originalName: string | Namekey,
|
|
53
|
+
options: CreateTypeParameterSymbolOptions = {},
|
|
54
|
+
) {
|
|
55
|
+
const scope = options.scope ?? useCSharpScope();
|
|
56
|
+
if (
|
|
57
|
+
!(scope instanceof CSharpMethodScope) &&
|
|
58
|
+
!(scope instanceof CSharpNamedTypeScope)
|
|
59
|
+
) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"Can't create a type parameter symbol outside of a method or named type scope.",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return new CSharpSymbol(
|
|
66
|
+
originalName,
|
|
67
|
+
scope.typeParameters,
|
|
68
|
+
withNamePolicy(options, "type-parameter"),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createFieldSymbol(
|
|
73
|
+
originalName: string | Namekey,
|
|
74
|
+
options: CSharpSymbolOptions = {},
|
|
75
|
+
) {
|
|
76
|
+
let nameElement: CSharpElements = "class-member-private";
|
|
77
|
+
|
|
78
|
+
if (
|
|
79
|
+
options.accessibility === "public" ||
|
|
80
|
+
options.accessibility === "internal" ||
|
|
81
|
+
options.accessibility === "protected"
|
|
82
|
+
) {
|
|
83
|
+
nameElement = "class-member-public";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const scope = useNamedTypeScope();
|
|
87
|
+
|
|
88
|
+
if (
|
|
89
|
+
scope.ownerSymbol.typeKind !== "class" &&
|
|
90
|
+
scope.ownerSymbol.typeKind !== "struct"
|
|
91
|
+
) {
|
|
92
|
+
throw new Error(`Can't define a field outside of a class or struct.`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return new CSharpSymbol(
|
|
96
|
+
originalName,
|
|
97
|
+
scope.members,
|
|
98
|
+
withNamePolicy(options, nameElement),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function createNamedTypeSymbol(
|
|
103
|
+
name: string | Namekey,
|
|
104
|
+
kind: NamedTypeTypeKind,
|
|
105
|
+
options?: OutputSymbolOptions,
|
|
106
|
+
) {
|
|
107
|
+
const scope = useNamedTypeScope();
|
|
108
|
+
return new NamedTypeSymbol(name, scope.ownerSymbol.members, kind, options);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function createNamespaceSymbol(name: string) {
|
|
112
|
+
const scope = useEnclosingNamespaceScope();
|
|
113
|
+
const nsSymbol = scope?.ownerSymbol ?? getGlobalNamespace(useBinder());
|
|
114
|
+
if (nsSymbol.members.symbolNames.has(name)) {
|
|
115
|
+
return nsSymbol.members.symbolNames.get(name)! as NamespaceSymbol;
|
|
116
|
+
}
|
|
117
|
+
return new NamespaceSymbol(name, nsSymbol);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface CreateMethodSymbolOptions extends CSharpSymbolOptions {
|
|
121
|
+
methodKind?: MethodKinds;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function createMethodSymbol(
|
|
125
|
+
originalName: string | Namekey,
|
|
126
|
+
options: CreateMethodSymbolOptions = {},
|
|
127
|
+
) {
|
|
128
|
+
const scope = useNamedTypeScope();
|
|
129
|
+
|
|
130
|
+
if (
|
|
131
|
+
scope.ownerSymbol.typeKind !== "class" &&
|
|
132
|
+
scope.ownerSymbol.typeKind !== "interface" &&
|
|
133
|
+
scope.ownerSymbol.typeKind !== "struct"
|
|
134
|
+
) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`Can't define a method outside of a class, interface, or struct.`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return new MethodSymbol(
|
|
141
|
+
originalName,
|
|
142
|
+
scope.members,
|
|
143
|
+
options.methodKind ?? "ordinary",
|
|
144
|
+
withNamePolicy(options, "class-method"),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function createPropertySymbol(
|
|
149
|
+
name: string | Namekey,
|
|
150
|
+
options: CSharpSymbolOptions,
|
|
151
|
+
) {
|
|
152
|
+
const scope = useNamedTypeScope();
|
|
153
|
+
return new CSharpSymbol(
|
|
154
|
+
name,
|
|
155
|
+
scope.members,
|
|
156
|
+
withNamePolicy(options, "class-property"),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function createVariableSymbol(
|
|
161
|
+
originalName: string | Namekey,
|
|
162
|
+
options: CSharpSymbolOptions = {},
|
|
163
|
+
) {
|
|
164
|
+
let scope = useCSharpScope();
|
|
165
|
+
if (
|
|
166
|
+
scope instanceof CSharpNamespaceScope &&
|
|
167
|
+
scope.ownerSymbol === getGlobalNamespace(scope.ownerSymbol.binder)
|
|
168
|
+
) {
|
|
169
|
+
// allow top-level variables in the global namespace, which are local to the source file.
|
|
170
|
+
scope = scope.parent as CSharpScope;
|
|
171
|
+
|
|
172
|
+
if (!(scope instanceof CSharpSourceFileScope)) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
"Variable declarations must be in the global namespace or within a lexical scope.",
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!(scope instanceof CSharpLexicalScope)) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`Can't create variable symbol outside of a lexical scope, got a ${scope.constructor.name}.`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
return new CSharpSymbol(
|
|
185
|
+
originalName,
|
|
186
|
+
scope.localVariables,
|
|
187
|
+
withNamePolicy(options, "variable"),
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function withNamePolicy<T extends { namePolicy?: NamePolicyGetter }>(
|
|
192
|
+
options: T,
|
|
193
|
+
elementType: CSharpElements,
|
|
194
|
+
) {
|
|
195
|
+
return {
|
|
196
|
+
...options,
|
|
197
|
+
namePolicy: options.namePolicy ?? useCSharpNamePolicy().for(elementType),
|
|
198
|
+
};
|
|
199
|
+
}
|
package/src/symbols/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export * from "./csharp
|
|
1
|
+
export * from "./csharp.js";
|
|
2
|
+
export * from "./factories.js";
|
|
3
|
+
export * from "./method.js";
|
|
4
|
+
export * from "./named-type.js";
|
|
5
|
+
export * from "./namespace.js";
|
|
2
6
|
export * from "./reference.js";
|
|
3
|
-
export * from "./scopes.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Namekey, OutputSpace } from "@alloy-js/core";
|
|
2
|
+
import { CSharpSymbol, CSharpSymbolOptions } from "./csharp.js";
|
|
3
|
+
|
|
4
|
+
export type MethodKinds = "ordinary" | "constructor";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A symbol for a method or constructor of a class, interface, or struct.
|
|
8
|
+
*/
|
|
9
|
+
export class MethodSymbol extends CSharpSymbol {
|
|
10
|
+
public readonly symbolKind = "method";
|
|
11
|
+
|
|
12
|
+
#methodKind: MethodKinds;
|
|
13
|
+
get methodKind() {
|
|
14
|
+
return this.#methodKind;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
name: string | Namekey,
|
|
19
|
+
spaces: OutputSpace | undefined,
|
|
20
|
+
kind: MethodKinds,
|
|
21
|
+
options: CSharpSymbolOptions = {},
|
|
22
|
+
) {
|
|
23
|
+
super(name, spaces, options);
|
|
24
|
+
this.#methodKind = kind;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Namekey, OutputSpace, OutputSymbolOptions } from "@alloy-js/core";
|
|
2
|
+
import { CSharpSymbol } from "./csharp.js";
|
|
3
|
+
|
|
4
|
+
// represents a symbol from a .cs file. Class, enum, interface etc.
|
|
5
|
+
|
|
6
|
+
export type NamedTypeTypeKind =
|
|
7
|
+
| "class"
|
|
8
|
+
| "interface"
|
|
9
|
+
| "enum"
|
|
10
|
+
| "namespace"
|
|
11
|
+
| "struct"
|
|
12
|
+
| "record";
|
|
13
|
+
export type NamedTypeSymbolKind = "named-type" | "namespace";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A symbol for a named type in C# such as a class, interface, enum, and so
|
|
17
|
+
* forth. Named types are generally defined in a namespace, and can have members
|
|
18
|
+
* of their own.
|
|
19
|
+
*/
|
|
20
|
+
export class NamedTypeSymbol extends CSharpSymbol {
|
|
21
|
+
public readonly symbolKind: NamedTypeSymbolKind = "named-type";
|
|
22
|
+
public static readonly memberSpaces = ["members"];
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
name: string | Namekey,
|
|
26
|
+
spaces: OutputSpace[] | OutputSpace | undefined,
|
|
27
|
+
kind: NamedTypeTypeKind,
|
|
28
|
+
options?: OutputSymbolOptions,
|
|
29
|
+
) {
|
|
30
|
+
super(name, spaces, options);
|
|
31
|
+
this.#typeKind = kind;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#typeKind: NamedTypeTypeKind;
|
|
35
|
+
get typeKind() {
|
|
36
|
+
return this.#typeKind;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
copy() {
|
|
40
|
+
const options = this.getCopyOptions();
|
|
41
|
+
const copy = new NamedTypeSymbol(
|
|
42
|
+
this.name,
|
|
43
|
+
undefined,
|
|
44
|
+
this.#typeKind,
|
|
45
|
+
options,
|
|
46
|
+
);
|
|
47
|
+
this.initializeCopy(copy);
|
|
48
|
+
return copy;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get members() {
|
|
52
|
+
return this.memberSpaceFor("members")!;
|
|
53
|
+
}
|
|
54
|
+
}
|