Skip to content

Commit

Permalink
fix(dotnet): use fully-qualified type names (#651)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RomainMuller committed Jul 30, 2019
1 parent 4945206 commit d32e2cd
Show file tree
Hide file tree
Showing 152 changed files with 309 additions and 630 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# jsii

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

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

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

### Java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,6 @@ System.Action<UsingDirectiveSyntax> GetInspector(string expected)
}
}

[Fact(DisplayName = Prefix + nameof(CreatesUsingStatementForType))]
public void CreatesUsingStatementForType()
{
EnumType type = new EnumType
(
fullyQualifiedName: "myEnumFqn",
assembly: "myModule",
name: "myEnum",
members: new EnumMember[] { }
);

Symbols.MapNamespace(type.QualifiedNamespace, "MyNamespace");

NamespaceSet namespaces = new NamespaceSet(Symbols, SF.ParseName("MyCurrentNamespace"));
namespaces.Add(type);

SyntaxList<UsingDirectiveSyntax> usings = namespaces.GetUsings();
AssertUsings
(
usings,
"using Amazon.JSII.Runtime.Deputy;",
"using MyNamespace;"
);
}

[Fact(DisplayName = Prefix + nameof(CreatesUsingStatementForObjectReference))]
public void CreatesUsingStatementForObjectReference()
{
Expand All @@ -62,8 +37,7 @@ public void CreatesUsingStatementForObjectReference()
AssertUsings
(
usings,
"using Amazon.JSII.Runtime.Deputy;",
"using MyNamespace;"
"using Amazon.JSII.Runtime.Deputy;"
);
}

Expand Down Expand Up @@ -261,7 +235,6 @@ public void SortsUsingStatementsAlphaNumerically()
AssertUsings
(
usings,
"using AAA;",
"using Amazon.JSII.Runtime.Deputy;"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,50 +70,50 @@ public static void MapTypeName(this ISymbolMap symbols, string fullyQualifiedNam
var defaultName = frameworkName;

symbols
.GetInterfaceProxyName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetInterfaceProxyName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(proxyName);
symbols
.GetInterfaceDefaultName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetInterfaceDefaultName(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(defaultName);
symbols
.GetInterfaceProxyNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetInterfaceProxyNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseToken(proxyName));
symbols
.GetInterfaceDefaultNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetInterfaceDefaultNameSyntaxToken(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseToken(defaultName));
symbols
.GetInterfaceProxyNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetInterfaceProxyNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseName(proxyName));
symbols
.GetInterfaceDefaultNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetInterfaceDefaultNameSyntax(Arg.Is<InterfaceType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseName(defaultName));

frameworkName = $"I{frameworkName}";
break;
case TypeKind.Class:
symbols
.GetAbstractClassProxyName(Arg.Is<ClassType>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetAbstractClassProxyName(Arg.Is<ClassType>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(proxyName);
break;
}

symbols
.GetName(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetName(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(frameworkName);
symbols
.GetName(Arg.Is<string>(fqn => fqn == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetName(Arg.Is<string>(fqn => fqn == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(frameworkName);
symbols
.GetNameSyntaxToken(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetNameSyntaxToken(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseToken(frameworkName));
symbols
.GetNameSyntaxToken(Arg.Is<string>(fqn => fqn == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetNameSyntaxToken(Arg.Is<string>(fqn => fqn == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseToken(frameworkName));
symbols
.GetNameSyntax(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetNameSyntax(Arg.Is<Type>(t => t.FullyQualifiedName == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseName(frameworkName));
symbols
.GetNameSyntax(Arg.Is<string>(fqn => fqn == fullyQualifiedName), disambiguate: Arg.Any<bool>())
.GetNameSyntax(Arg.Is<string>(fqn => fqn == fullyQualifiedName), qualified: Arg.Any<bool>())
.Returns(SF.ParseName(frameworkName));
symbols
.GetTypeSyntax(Arg.Is<TypeReference>(t => t.FullyQualifiedName == fullyQualifiedName), false)
Expand Down
Loading

0 comments on commit d32e2cd

Please sign in to comment.