Skip to content

Commit d32e2cd

Browse files
authored
fix(dotnet): use fully-qualified type names (#651)
Stop generating `using` statements for types referenced in a particular file, so as to avoid running into cases where a given type (leaf) name corresponds to a locally defined type as well as a dependent type, which breaks compilation as `dotnet` will resolve to the local type with higher priority than the `using` type. Fixes #650
1 parent 4945206 commit d32e2cd

File tree

152 files changed

+309
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+309
-630
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# jsii
22

3+
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=aws/jsii)](https://dependabot.com)
34
![Build Status](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiOThRRFVsVlRBTEhocVZOckE0bFlFWEtwNU0xUmtNUlRRclY0R2VYTGJaOXRlaVdaVnREV2lhVGtDUzQzUDRMMCtuYWpSTWo4N1FGTEV5Zm9yZ0dEb2dBPSIsIml2UGFyYW1ldGVyU3BlYyI6InFVbktYSlpDem1YN1JCeU8iLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
5+
[![npm](https://img.shields.io/npm/v/jsii)](https://www.npmjs.com/package/jsii)
46

57
__jsii__ allows code in any language to naturally interact with JavaScript classes.
68

@@ -281,7 +283,7 @@ jsii configuration is read from the `jsii` section in the module's
281283
__jsii-pacmak__. This is where target artifacts are emitted during packaging.
282284
Each artifact will be emitted under `<outdir>/<target>` (e.g. `dist/java`,
283285
`dist/js`, etc). Conventionally we use `"dist"` for outdir.
284-
* `tsc` - this section allows to adjust the compiler options of the generated `tsconfig.json`.
286+
* `tsc` - this section allows to adjust the compiler options of the generated `tsconfig.json`.
285287
Currently you can set `outDir` and `rootDir`. Setting `rootDir` automatically adjusts the `include` config.
286288

287289
### Java

packages/jsii-dotnet-generator/src/Amazon.JSII.Generator.UnitTests/NamespaceSetTests.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,6 @@ System.Action<UsingDirectiveSyntax> GetInspector(string expected)
2525
}
2626
}
2727

28-
[Fact(DisplayName = Prefix + nameof(CreatesUsingStatementForType))]
29-
public void CreatesUsingStatementForType()
30-
{
31-
EnumType type = new EnumType
32-
(
33-
fullyQualifiedName: "myEnumFqn",
34-
assembly: "myModule",
35-
name: "myEnum",
36-
members: new EnumMember[] { }
37-
);
38-
39-
Symbols.MapNamespace(type.QualifiedNamespace, "MyNamespace");
40-
41-
NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace"));
42-
namespaces.Add(type);
43-
44-
SyntaxList<UsingDirectiveSyntax> usings = namespaces.GetUsings();
45-
AssertUsings
46-
(
47-
usings,
48-
"using Amazon.JSII.Runtime.Deputy;",
49-
"using MyNamespace;"
50-
);
51-
}
52-
5328
[Fact(DisplayName = Prefix + nameof(CreatesUsingStatementForObjectReference))]
5429
public void CreatesUsingStatementForObjectReference()
5530
{
@@ -62,8 +37,7 @@ public void CreatesUsingStatementForObjectReference()
6237
AssertUsings
6338
(
6439
usings,
65-
"using Amazon.JSII.Runtime.Deputy;",
66-
"using MyNamespace;"
40+
"using Amazon.JSII.Runtime.Deputy;"
6741
);
6842
}
6943

@@ -261,7 +235,6 @@ public void SortsUsingStatementsAlphaNumerically()
261235
AssertUsings
262236
(
263237
usings,
264-
"using AAA;",
265238
"using Amazon.JSII.Runtime.Deputy;"
266239
);
267240
}

packages/jsii-dotnet-generator/src/Amazon.JSII.Generator.UnitTests/SymbolMapExtensions.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,50 +70,50 @@ public static void MapTypeName(this ISymbolMap symbols, string fullyQualifiedNam
7070
var defaultName = frameworkName;
7171

7272
symbols
73-
.GetInterfaceProxyName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
73+
.GetInterfaceProxyName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
7474
.Returns(proxyName);
7575
symbols
76-
.GetInterfaceDefaultName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
76+
.GetInterfaceDefaultName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
7777
.Returns(defaultName);
7878
symbols
79-
.GetInterfaceProxyNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
79+
.GetInterfaceProxyNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
8080
.Returns(SF.ParseToken(proxyName));
8181
symbols
82-
.GetInterfaceDefaultNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
82+
.GetInterfaceDefaultNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
8383
.Returns(SF.ParseToken(defaultName));
8484
symbols
85-
.GetInterfaceProxyNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
85+
.GetInterfaceProxyNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
8686
.Returns(SF.ParseName(proxyName));
8787
symbols
88-
.GetInterfaceDefaultNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
88+
.GetInterfaceDefaultNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
8989
.Returns(SF.ParseName(defaultName));
9090

9191
frameworkName = $"I{frameworkName}";
9292
break;
9393
case TypeKind.Class:
9494
symbols
95-
.GetAbstractClassProxyName(Arg.Is<ClassType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
95+
.GetAbstractClassProxyName(Arg.Is<ClassType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
9696
.Returns(proxyName);
9797
break;
9898
}
9999

100100
symbols
101-
.GetName(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
101+
.GetName(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
102102
.Returns(frameworkName);
103103
symbols
104-
.GetName(Arg.Is<string>(fqn => fqn == fullyQualifiedName), disambiguate: Arg.Any<bool>())
104+
.GetName(Arg.Is<string>(fqn => fqn == fullyQualifiedName), qualified: Arg.Any<bool>())
105105
.Returns(frameworkName);
106106
symbols
107-
.GetNameSyntaxToken(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
107+
.GetNameSyntaxToken(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
108108
.Returns(SF.ParseToken(frameworkName));
109109
symbols
110-
.GetNameSyntaxToken(Arg.Is<string>(fqn => fqn == fullyQualifiedName), disambiguate: Arg.Any<bool>())
110+
.GetNameSyntaxToken(Arg.Is<string>(fqn => fqn == fullyQualifiedName), qualified: Arg.Any<bool>())
111111
.Returns(SF.ParseToken(frameworkName));
112112
symbols
113-
.GetNameSyntax(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
113+
.GetNameSyntax(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
114114
.Returns(SF.ParseName(frameworkName));
115115
symbols
116-
.GetNameSyntax(Arg.Is<string>(fqn => fqn == fullyQualifiedName), disambiguate: Arg.Any<bool>())
116+
.GetNameSyntax(Arg.Is<string>(fqn => fqn == fullyQualifiedName), qualified: Arg.Any<bool>())
117117
.Returns(SF.ParseName(frameworkName));
118118
symbols
119119
.GetTypeSyntax(Arg.Is<TypeReference>(t => t.FullyQualifiedName == fullyQualifiedName), false)

0 commit comments

Comments
 (0)