Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dotnet): use fully-qualified type names #651

Merged
merged 4 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ IEnumerable<BaseTypeSyntax> GetBaseTypes()
}
else
{
Namespaces.Add(Symbols.GetTypeFromFullyQualifiedName(Type.Base));
yield return SF.SimpleBaseType(Symbols.GetNameSyntax(Type.Base, disambiguate: true));
}

Expand All @@ -100,7 +99,6 @@ IEnumerable<BaseTypeSyntax> GetBaseTypes()

foreach (var interfaceReference in Type.Interfaces)
{
Namespaces.Add(Symbols.GetTypeFromFullyQualifiedName(interfaceReference));
yield return SF.SimpleBaseType(Symbols.GetNameSyntax(interfaceReference, disambiguate: true));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public interface INamespaceSet
{
SyntaxList<UsingDirectiveSyntax> GetUsings();

void Add(Type type);

void Add(TypeReference typeReference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ IEnumerable<BaseTypeSyntax> GetBaseTypes()
{
foreach (string interfaceReference in Type.Interfaces ?? Enumerable.Empty<string>())
{
Namespaces.Add(Symbols.GetTypeFromFullyQualifiedName(interfaceReference));
yield return SF.SimpleBaseType(Symbols.GetNameSyntax(interfaceReference, disambiguate: true));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@ public SyntaxList<UsingDirectiveSyntax> GetUsings()
return SF.List(usings);
}

public void Add(Type type)
{
_referencedNamespaces.Add(_symbols.GetNamespaceSyntax(type));
}

public void Add(TypeReference typeReference)
{
if (typeReference.FullyQualifiedName != null)
{
_referencedNamespaces.Add(_symbols.GetNamespaceSyntax(typeReference.FullyQualifiedName));
// Not generating "using" statements for stuff from dependencies - we won't use those.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,21 @@ public string GetName(Assembly assembly)
return GetAssemblyName(assembly.Name);
}

public string GetName(Type type, bool disambiguate = false)
public string GetName(Type type, bool qualified = false)
{
type = type ?? throw new ArgumentNullException(nameof(type));

TypeMetadata metadata = _types[type.FullyQualifiedName];

disambiguate = disambiguate && _types.Values
.Any(m => m.Type.FullyQualifiedName != metadata.Type.FullyQualifiedName && m.Name == metadata.Name);

return disambiguate ? metadata.FrameworkFullyQualifiedName : metadata.Name;
return qualified ? metadata.FrameworkFullyQualifiedName : metadata.Name;
}

public string GetName(string fullyQualifiedName, bool disambiguate = false)
public string GetName(string fullyQualifiedName, bool qualified = false)
{
return GetName(GetTypeFromFullyQualifiedName(fullyQualifiedName), disambiguate);
return GetName(GetTypeFromFullyQualifiedName(fullyQualifiedName), qualified);
}

public string GetAbstractClassProxyName(ClassType type, bool disambiguate = false)
public string GetAbstractClassProxyName(ClassType type, bool qualified = false)
{
type = type ?? throw new ArgumentNullException(nameof(type));

Expand All @@ -124,7 +121,7 @@ public string GetAbstractClassProxyName(ClassType type, bool disambiguate = fals
throw new ArgumentException($"Cannot get proxy name for '{type.FullyQualifiedName}' because it is not an abstract class.");
}

public string GetInterfaceProxyName(InterfaceType type, bool disambiguate = false)
public string GetInterfaceProxyName(InterfaceType type, bool qualified = false)
{
type = type ?? throw new ArgumentNullException(nameof(type));

Expand All @@ -136,7 +133,7 @@ public string GetInterfaceProxyName(InterfaceType type, bool disambiguate = fals
throw new ArgumentException($"Cannot get proxy name for '{type.FullyQualifiedName}' because it is not an interface.");
}

public string GetInterfaceDefaultName(InterfaceType type, bool disambiguate = false)
public string GetInterfaceDefaultName(InterfaceType type, bool qualified = false)
{
type = type ?? throw new ArgumentNullException(nameof(type));

Expand Down Expand Up @@ -185,24 +182,24 @@ public SyntaxToken GetNameSyntaxToken(Assembly assembly)
return SF.Identifier(GetName(assembly ?? throw new ArgumentNullException(nameof(assembly))));
}

public SyntaxToken GetNameSyntaxToken(Type type, bool disambiguate = false)
public SyntaxToken GetNameSyntaxToken(Type type, bool qualified = false)
{
return SF.Identifier(GetName(type ?? throw new ArgumentNullException(nameof(type)), disambiguate));
return SF.Identifier(GetName(type ?? throw new ArgumentNullException(nameof(type)), qualified));
}

public SyntaxToken GetNameSyntaxToken(string fullyQualifiedName, bool disambiguate = false)
public SyntaxToken GetNameSyntaxToken(string fullyQualifiedName, bool qualified = false)
{
return GetNameSyntaxToken(GetTypeFromFullyQualifiedName(fullyQualifiedName), disambiguate);
return GetNameSyntaxToken(GetTypeFromFullyQualifiedName(fullyQualifiedName), qualified);
}

public SyntaxToken GetInterfaceProxyNameSyntaxToken(InterfaceType type, bool disambiguate = false)
public SyntaxToken GetInterfaceProxyNameSyntaxToken(InterfaceType type, bool qualified = false)
{
return SF.Identifier(GetInterfaceProxyName(type ?? throw new ArgumentNullException(nameof(type)), disambiguate));
return SF.Identifier(GetInterfaceProxyName(type ?? throw new ArgumentNullException(nameof(type)), qualified));
}

public SyntaxToken GetInterfaceDefaultNameSyntaxToken(InterfaceType type, bool disambiguate = false)
public SyntaxToken GetInterfaceDefaultNameSyntaxToken(InterfaceType type, bool qualified = false)
{
return SF.Identifier(GetInterfaceDefaultName(type ?? throw new ArgumentNullException(nameof(type)), disambiguate));
return SF.Identifier(GetInterfaceDefaultName(type ?? throw new ArgumentNullException(nameof(type)), qualified));
}

public SyntaxToken GetNameSyntaxToken(Type type, Method method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ IEnumerable<BaseTypeSyntax> GetBaseTypes()
yield return SF.SimpleBaseType(SF.ParseTypeName("DeputyBase"));
}

Namespaces.Add(Type);
yield return SF.SimpleBaseType(Symbols.GetNameSyntax(Type, disambiguate: true));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/bin/jsii-pacmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ import { VERSION_DESC } from '../lib/version';
// ``argv.target`` is guaranteed valid by ``yargs`` through the ``choices`` directive.
const targetConstructor = targetConstructors[targetName];
if (!targetConstructor) {
throw new Error(`Unsupported target ${targetName}`);
throw new Error(`Unsupported target: "${targetName}"`);
}

const target = new targetConstructor({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Amazon.JSII.Runtime.Deputy;
using Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
[JsiiByValue]
public class BaseProps : IBaseProps
public class BaseProps : Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IBaseProps
{
[JsiiProperty(name: "bar", typeJson: "{\"primitive\":\"string\"}", isOverride: true)]
public string Bar
Expand All @@ -14,7 +13,7 @@ public string Bar
}

[JsiiProperty(name: "foo", typeJson: "{\"fqn\":\"@scope/jsii-calc-base-of-base.Very\"}", isOverride: true)]
public Very Foo
public Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very Foo
{
get;
set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Amazon.JSII.Runtime.Deputy;
using Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
[JsiiTypeProxy(nativeType: typeof(IBaseProps), fullyQualifiedName: "@scope/jsii-calc-base.BaseProps")]
internal sealed class BasePropsProxy : DeputyBase, IBaseProps
internal sealed class BasePropsProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IBaseProps
{
private BasePropsProxy(ByRefValue reference): base(reference)
{
Expand All @@ -17,9 +16,9 @@ public string Bar
}

[JsiiProperty(name: "foo", typeJson: "{\"fqn\":\"@scope/jsii-calc-base-of-base.Very\"}")]
public Very Foo
public Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very Foo
{
get => GetInstanceProperty<Very>();
get => GetInstanceProperty<Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.Very>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
/// <summary>A base class.</summary>
[JsiiTypeProxy(nativeType: typeof(Base), fullyQualifiedName: "@scope/jsii-calc-base.Base")]
internal sealed class BaseProxy : Base
internal sealed class BaseProxy : Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.Base
{
private BaseProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
[JsiiTypeProxy(nativeType: typeof(IIBaseInterface), fullyQualifiedName: "@scope/jsii-calc-base.IBaseInterface")]
internal sealed class IBaseInterfaceProxy : DeputyBase, IIBaseInterface
internal sealed class IBaseInterfaceProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IIBaseInterface
{
private IBaseInterfaceProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Amazon.JSII.Runtime.Deputy;
using Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
[JsiiInterface(nativeType: typeof(IBaseProps), fullyQualifiedName: "@scope/jsii-calc-base.BaseProps")]
public interface IBaseProps : IVeryBaseProps
public interface IBaseProps : Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.IVeryBaseProps
{
[JsiiProperty(name: "bar", typeJson: "{\"primitive\":\"string\"}")]
string Bar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Amazon.JSII.Runtime.Deputy;
using Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
[JsiiInterface(nativeType: typeof(IIBaseInterface), fullyQualifiedName: "@scope/jsii-calc-base.IBaseInterface")]
public interface IIBaseInterface : IIVeryBaseInterface
public interface IIBaseInterface : Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.IIVeryBaseInterface
{
[JsiiMethod(name: "bar")]
void Bar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>stability: Deprecated</remarks>
[JsiiTypeProxy(nativeType: typeof(IIDoublable), fullyQualifiedName: "@scope/jsii-calc-lib.IDoublable")]
[System.Obsolete()]
internal sealed class IDoublableProxy : DeputyBase, IIDoublable
internal sealed class IDoublableProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable
{
private IDoublableProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// </remarks>
[JsiiTypeProxy(nativeType: typeof(IIFriendly), fullyQualifiedName: "@scope/jsii-calc-lib.IFriendly")]
[System.Obsolete()]
internal sealed class IFriendlyProxy : DeputyBase, IIFriendly
internal sealed class IFriendlyProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIFriendly
{
private IFriendlyProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Amazon.JSII.Runtime.Deputy;
using Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace;

namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
{
Expand All @@ -11,7 +10,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// </remarks>
[JsiiInterface(nativeType: typeof(IIThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")]
[System.Obsolete()]
public interface IIThreeLevelsInterface : IIBaseInterface
public interface IIThreeLevelsInterface : Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IIBaseInterface
{
/// <remarks>stability: Deprecated</remarks>
[JsiiMethod(name: "baz")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// </remarks>
[JsiiTypeProxy(nativeType: typeof(IIThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")]
[System.Obsolete()]
internal sealed class IThreeLevelsInterfaceProxy : DeputyBase, IIThreeLevelsInterface
internal sealed class IThreeLevelsInterfaceProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIThreeLevelsInterface
{
private IThreeLevelsInterfaceProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <summary>This is the first struct we have created in jsii.</summary>
/// <remarks>stability: Deprecated</remarks>
[JsiiByValue]
public class MyFirstStruct : IMyFirstStruct
public class MyFirstStruct : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IMyFirstStruct
{
/// <summary>An awesome number value.</summary>
/// <remarks>stability: Deprecated</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>stability: Deprecated</remarks>
[JsiiTypeProxy(nativeType: typeof(IMyFirstStruct), fullyQualifiedName: "@scope/jsii-calc-lib.MyFirstStruct")]
[System.Obsolete()]
internal sealed class MyFirstStructProxy : DeputyBase, IMyFirstStruct
internal sealed class MyFirstStructProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IMyFirstStruct
{
private MyFirstStructProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>stability: Deprecated</remarks>
[JsiiClass(nativeType: typeof(Number), fullyQualifiedName: "@scope/jsii-calc-lib.Number", parametersJson: "[{\"name\":\"value\",\"type\":{\"primitive\":\"number\"}}]")]
[System.Obsolete()]
public class Number : Value_, IIDoublable
public class Number : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Value_, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable
{
/// <summary>Creates a Number object.</summary>
/// <param name = "value">The number.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>stability: Deprecated</remarks>
[JsiiClass(nativeType: typeof(Operation), fullyQualifiedName: "@scope/jsii-calc-lib.Operation")]
[System.Obsolete()]
public abstract class Operation : Value_
public abstract class Operation : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Value_
{
protected Operation(): base(new DeputyProps(new object[]{}))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>stability: Deprecated</remarks>
[JsiiTypeProxy(nativeType: typeof(Operation), fullyQualifiedName: "@scope/jsii-calc-lib.Operation")]
[System.Obsolete()]
internal sealed class OperationProxy : Operation
internal sealed class OperationProxy : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Operation
{
private OperationProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <summary>This is a struct with only optional properties.</summary>
/// <remarks>stability: Deprecated</remarks>
[JsiiByValue]
public class StructWithOnlyOptionals : IStructWithOnlyOptionals
public class StructWithOnlyOptionals : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IStructWithOnlyOptionals
{
/// <summary>The first optional!</summary>
/// <remarks>stability: Deprecated</remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>stability: Deprecated</remarks>
[JsiiTypeProxy(nativeType: typeof(IStructWithOnlyOptionals), fullyQualifiedName: "@scope/jsii-calc-lib.StructWithOnlyOptionals")]
[System.Obsolete()]
internal sealed class StructWithOnlyOptionalsProxy : DeputyBase, IStructWithOnlyOptionals
internal sealed class StructWithOnlyOptionalsProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IStructWithOnlyOptionals
{
private StructWithOnlyOptionalsProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>stability: Deprecated</remarks>
[JsiiTypeProxy(nativeType: typeof(Value_), fullyQualifiedName: "@scope/jsii-calc-lib.Value")]
[System.Obsolete()]
internal sealed class ValueProxy : Value_
internal sealed class ValueProxy : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Value_
{
private ValueProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Amazon.JSII.Runtime.Deputy;
using Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace;

namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
{
/// <summary>Abstract class which represents a numeric value.</summary>
/// <remarks>stability: Deprecated</remarks>
[JsiiClass(nativeType: typeof(Value_), fullyQualifiedName: "@scope/jsii-calc-lib.Value")]
[System.Obsolete()]
public abstract class Value_ : Base
public abstract class Value_ : Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.Base
{
protected Value_(): base(new DeputyProps(new object[]{}))
{
Expand Down
Loading