Skip to content

Commit

Permalink
feat(dotnet): drop the useless I prefix for non datatype interfaces (#…
Browse files Browse the repository at this point in the history
…728)

Drop the useless I prefix for non datatype interfaces as they are guaranteed by jsii to start with I.

This removes a bunch of II* interfaces.

Updated the tests, and tested with the CDK successfully.

BREAKING CHANGE: names of .NET behavioral interfaces have changed (the duplicate prefix I was removed).

Fixes #109
  • Loading branch information
Hamza Assyad authored and RomainMuller committed Aug 22, 2019
1 parent 68ef42a commit b9621f1
Show file tree
Hide file tree
Showing 93 changed files with 221 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public override string TheProperty
}
}

class InterfaceWithProperties : DeputyBase, IIInterfaceWithProperties
class InterfaceWithProperties : DeputyBase, IInterfaceWithProperties
{
string _x;

Expand Down Expand Up @@ -630,10 +630,10 @@ public void SyncOverrides_CallsDoubleAsyncPropertySetterFails()
[Fact(DisplayName = Prefix + nameof(TestInterfaces))]
public void TestInterfaces()
{
IIFriendly friendly;
IIFriendlier friendlier;
IIRandomNumberGenerator randomNumberGenerator;
IIFriendlyRandomGenerator friendlyRandomGenerator;
IFriendly friendly;
IFriendlier friendlier;
IRandomNumberGenerator randomNumberGenerator;
IFriendlyRandomGenerator friendlyRandomGenerator;

Add add = new Add(new Number(10), new Number(20));
friendly = add;
Expand Down Expand Up @@ -700,10 +700,10 @@ public void TestNativeObjectsWithInterfaces()
public void TestLiteralInterface()
{
JSObjectLiteralForInterface obj = new JSObjectLiteralForInterface();
IIFriendly friendly = obj.GiveMeFriendly();
IFriendly friendly = obj.GiveMeFriendly();
Assert.Equal("I am literally friendly!", friendly.Hello());

IIFriendlyRandomGenerator gen = obj.GiveMeFriendlyGenerator();
IFriendlyRandomGenerator gen = obj.GiveMeFriendlyGenerator();
Assert.Equal("giveMeFriendlyGenerator", gen.Hello());
Assert.Equal((double) 42, gen.Next());
}
Expand Down Expand Up @@ -1014,7 +1014,7 @@ public override String ConsumePartiallyInitializedThis(ConstructorPassesThisOut
return "OK";
}
}
class NumberReturner : DeputyBase, IIReturnsNumber
class NumberReturner : DeputyBase, IReturnsNumber
{
public NumberReturner(double number)
{
Expand All @@ -1025,12 +1025,12 @@ public NumberReturner(double number)
public Number NumberProp { get; }

[JsiiMethod(name: "obtainNumber", returnsJson: "{\"type\":{\"fqn\":\"@scope/jsii-calc-lib.IDoublable\"}}", isOverride: true)]
public IIDoublable ObtainNumber()
public IDoublable ObtainNumber()
{
return new Doublable(this.NumberProp);
}

class Doublable : DeputyBase, IIDoublable
class Doublable : DeputyBase, IDoublable
{
public Doublable(Number number)
{
Expand Down Expand Up @@ -1130,7 +1130,7 @@ public override string TheProperty
public string AnotherTheProperty { get; set; }
}

class PureNativeFriendlyRandom : DeputyBase, IIFriendlyRandomGenerator
class PureNativeFriendlyRandom : DeputyBase, IFriendlyRandomGenerator
{
int _nextNumber = 1000;

Expand All @@ -1149,7 +1149,7 @@ public string Hello()
}
}

class SubclassNativeFriendlyRandom : Number, IIFriendly, IIRandomNumberGenerator
class SubclassNativeFriendlyRandom : Number, IFriendly, IRandomNumberGenerator
{
int _nextNumber;

Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class DotNetGenerator extends Generator {

protected onBeginInterface(ifc: spec.InterfaceType) {
const implementations = this.typeresolver.resolveImplementedInterfaces(ifc);
const interfaceName = this.nameutils.convertInterfaceName(ifc.name);
const interfaceName = this.nameutils.convertInterfaceName(ifc);
const namespace = ifc.namespace ? `${this.assembly.targets!.dotnet!.namespace}.${ifc.namespace}` : this.assembly.targets!.dotnet!.namespace;
this.openFileIfNeeded(interfaceName, namespace, this.isNested(ifc));

Expand All @@ -137,7 +137,7 @@ export class DotNetGenerator extends Generator {
}

protected onEndInterface(ifc: spec.InterfaceType) {
const interfaceName = this.nameutils.convertInterfaceName(ifc.name);
const interfaceName = this.nameutils.convertInterfaceName(ifc);
this.code.closeBlock();
this.closeFileIfNeeded(interfaceName, this.isNested(ifc));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class DotNetRuntimeGenerator {
*/
public emitAttributesForInterface(ifc: spec.InterfaceType) {
const jsiiAttribute =
`[JsiiInterface(nativeType: typeof(${this.nameutils.convertInterfaceName(ifc.name)}), fullyQualifiedName: "${ifc.fqn}")]`;
`[JsiiInterface(nativeType: typeof(${this.nameutils.convertInterfaceName(ifc)}), fullyQualifiedName: "${ifc.fqn}")]`;
this.code.line(jsiiAttribute);
this.emitDeprecatedAttributeIfNecessary(ifc);
}
Expand Down Expand Up @@ -104,7 +104,7 @@ export class DotNetRuntimeGenerator {
* Ex: [JsiiTypeProxy(nativeType: typeof(IVeryBaseProps), fullyQualifiedName: "@scope/jsii-calc-base-of-base.VeryBaseProps")]
*/
public emitAttributesForInterfaceProxy(ifc: spec.ClassType | spec.InterfaceType): void {
const name = ifc.kind === spec.TypeKind.Interface ? this.nameutils.convertInterfaceName(ifc.name)
const name = ifc.kind === spec.TypeKind.Interface ? this.nameutils.convertInterfaceName(ifc)
: this.typeresolver.toNativeFqn(ifc.fqn);
this.code.line(`[JsiiTypeProxy(nativeType: typeof(${name}), fullyQualifiedName: \"${ifc.fqn}\")]`);
this.emitDeprecatedAttributeIfNecessary(ifc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class DotNetTypeResolver {
let typeName: string = '';
switch (type.kind) {
case spec.TypeKind.Interface:
typeName = this.nameutils.convertInterfaceName(type.name);
typeName = this.nameutils.convertInterfaceName(type);
break;
case spec.TypeKind.Class:
typeName = this.nameutils.convertClassName(type as spec.ClassType);
Expand Down
15 changes: 10 additions & 5 deletions packages/jsii-pacmak/lib/targets/dotnet/nameutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ export class DotNetNameUtils {
return this.capitalizeWord(original);
}

public convertInterfaceName(original: string) {
if (this.isInvalidName(original)) {
throw new Error(`Invalid interface name: ${original}`);
public convertInterfaceName(original: spec.InterfaceType) {
if (this.isInvalidName(original.name)) {
throw new Error(`Invalid interface name: ${original.name}`);
}
if (original.datatype) {
// Datatype interfaces need to be prefixed by I so that they don't clash with the prop object implementation
return 'I' + this.capitalizeWord(original.name);
} else {
// Non datatype interfaces are guaranteed by JSII to be prefixed by I already
return this.capitalizeWord(original.name);
}
const capitalizedName = this.capitalizeWord(original);
return 'I' + capitalizedName;
}

public convertClassName(original: spec.ClassType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Amazon.JSII.Runtime.Deputy;

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
[JsiiInterface(nativeType: typeof(IBaseInterface), fullyQualifiedName: "@scope/jsii-calc-base.IBaseInterface")]
public interface IBaseInterface : Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace.IVeryBaseInterface
{
[JsiiMethod(name: "bar")]
void Bar();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace
{
[JsiiTypeProxy(nativeType: typeof(IIBaseInterface), fullyQualifiedName: "@scope/jsii-calc-base.IBaseInterface")]
internal sealed class IBaseInterfaceProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IIBaseInterface
[JsiiTypeProxy(nativeType: typeof(IBaseInterface), fullyQualifiedName: "@scope/jsii-calc-base.IBaseInterface")]
internal sealed class IBaseInterfaceProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IBaseInterface
{
private IBaseInterfaceProxy(ByRefValue reference): base(reference)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>
/// stability: Deprecated
/// </remarks>
[JsiiInterface(nativeType: typeof(IIDoublable), fullyQualifiedName: "@scope/jsii-calc-lib.IDoublable")]
[JsiiInterface(nativeType: typeof(IDoublable), fullyQualifiedName: "@scope/jsii-calc-lib.IDoublable")]
[System.Obsolete()]
public interface IIDoublable
public interface IDoublable
{
/// <remarks>
/// stability: Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// <remarks>
/// stability: Deprecated
/// </remarks>
[JsiiTypeProxy(nativeType: typeof(IIDoublable), fullyQualifiedName: "@scope/jsii-calc-lib.IDoublable")]
[JsiiTypeProxy(nativeType: typeof(IDoublable), fullyQualifiedName: "@scope/jsii-calc-lib.IDoublable")]
[System.Obsolete()]
internal sealed class IDoublableProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable
internal sealed class IDoublableProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IDoublable
{
private IDoublableProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// a "hello" or "goodbye" blessing and they will respond back in a fun and friendly manner.
/// stability: Deprecated
/// </remarks>
[JsiiInterface(nativeType: typeof(IIFriendly), fullyQualifiedName: "@scope/jsii-calc-lib.IFriendly")]
[JsiiInterface(nativeType: typeof(IFriendly), fullyQualifiedName: "@scope/jsii-calc-lib.IFriendly")]
[System.Obsolete()]
public interface IIFriendly
public interface IFriendly
{
/// <summary>Say hello!</summary>
/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// a "hello" or "goodbye" blessing and they will respond back in a fun and friendly manner.
/// stability: Deprecated
/// </remarks>
[JsiiTypeProxy(nativeType: typeof(IIFriendly), fullyQualifiedName: "@scope/jsii-calc-lib.IFriendly")]
[JsiiTypeProxy(nativeType: typeof(IFriendly), fullyQualifiedName: "@scope/jsii-calc-lib.IFriendly")]
[System.Obsolete()]
internal sealed class IFriendlyProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIFriendly
internal sealed class IFriendlyProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IFriendly
{
private IFriendlyProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// far enough up the tree.
/// stability: Deprecated
/// </remarks>
[JsiiInterface(nativeType: typeof(IIThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")]
[JsiiInterface(nativeType: typeof(IThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")]
[System.Obsolete()]
public interface IIThreeLevelsInterface : Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IIBaseInterface
public interface IThreeLevelsInterface : Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace.IBaseInterface
{
/// <remarks>
/// stability: Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// far enough up the tree.
/// stability: Deprecated
/// </remarks>
[JsiiTypeProxy(nativeType: typeof(IIThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")]
[JsiiTypeProxy(nativeType: typeof(IThreeLevelsInterface), fullyQualifiedName: "@scope/jsii-calc-lib.IThreeLevelsInterface")]
[System.Obsolete()]
internal sealed class IThreeLevelsInterfaceProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIThreeLevelsInterface
internal sealed class IThreeLevelsInterfaceProxy : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IThreeLevelsInterface
{
private IThreeLevelsInterfaceProxy(ByRefValue reference): base(reference)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace.LibNamespace
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Number), fullyQualifiedName: "@scope/jsii-calc-lib.Number", parametersJson: "[{\"docs\":{\"summary\":\"The number.\"},\"name\":\"value\",\"type\":{\"primitive\":\"number\"}}]")]
[System.Obsolete()]
public class Number : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Value_, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIDoublable
public class Number : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Value_, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IDoublable
{
/// <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
/// stability: Experimental
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.AbstractClass), fullyQualifiedName: "jsii-calc.AbstractClass")]
public abstract class AbstractClass : Amazon.JSII.Tests.CalculatorNamespace.AbstractClassBase, Amazon.JSII.Tests.CalculatorNamespace.IIInterfaceImplementedByAbstractClass
public abstract class AbstractClass : Amazon.JSII.Tests.CalculatorNamespace.AbstractClassBase, Amazon.JSII.Tests.CalculatorNamespace.IInterfaceImplementedByAbstractClass
{
protected AbstractClass(): base(new DeputyProps(new object[]{}))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public virtual Amazon.JSII.Tests.CalculatorNamespace.AbstractClass GiveMeAbstrac
/// stability: Experimental
/// </remarks>
[JsiiMethod(name: "giveMeInterface", returnsJson: "{\"type\":{\"fqn\":\"jsii-calc.IInterfaceImplementedByAbstractClass\"}}")]
public virtual Amazon.JSII.Tests.CalculatorNamespace.IIInterfaceImplementedByAbstractClass GiveMeInterface()
public virtual Amazon.JSII.Tests.CalculatorNamespace.IInterfaceImplementedByAbstractClass GiveMeInterface()
{
return InvokeInstanceMethod<Amazon.JSII.Tests.CalculatorNamespace.IIInterfaceImplementedByAbstractClass>(new object[]{});
return InvokeInstanceMethod<Amazon.JSII.Tests.CalculatorNamespace.IInterfaceImplementedByAbstractClass>(new object[]{});
}

/// <remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace
/// stability: Experimental
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.BinaryOperation), fullyQualifiedName: "jsii-calc.BinaryOperation", parametersJson: "[{\"docs\":{\"summary\":\"Left-hand side operand.\"},\"name\":\"lhs\",\"type\":{\"fqn\":\"@scope/jsii-calc-lib.Value\"}},{\"docs\":{\"summary\":\"Right-hand side operand.\"},\"name\":\"rhs\",\"type\":{\"fqn\":\"@scope/jsii-calc-lib.Value\"}}]")]
public abstract class BinaryOperation : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Operation, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IIFriendly
public abstract class BinaryOperation : Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.Operation, Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IFriendly
{
/// <summary>Creates a BinaryOperation.</summary>
/// <param name = "lhs">Left-hand side operand.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace
/// stability: Experimental
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.ClassThatImplementsTheInternalInterface), fullyQualifiedName: "jsii-calc.ClassThatImplementsTheInternalInterface")]
public class ClassThatImplementsTheInternalInterface : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IINonInternalInterface
public class ClassThatImplementsTheInternalInterface : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.INonInternalInterface
{
public ClassThatImplementsTheInternalInterface(): 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
/// stability: Experimental
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.ClassThatImplementsThePrivateInterface), fullyQualifiedName: "jsii-calc.ClassThatImplementsThePrivateInterface")]
public class ClassThatImplementsThePrivateInterface : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IINonInternalInterface
public class ClassThatImplementsThePrivateInterface : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.INonInternalInterface
{
public ClassThatImplementsThePrivateInterface(): base(new DeputyProps(new object[]{}))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected ClassWithMutableObjectLiteralProperty(DeputyProps props): base(props)
/// stability: Experimental
/// </remarks>
[JsiiProperty(name: "mutableObject", typeJson: "{\"fqn\":\"jsii-calc.IMutableObjectLiteral\"}")]
public virtual Amazon.JSII.Tests.CalculatorNamespace.IIMutableObjectLiteral MutableObject
public virtual Amazon.JSII.Tests.CalculatorNamespace.IMutableObjectLiteral MutableObject
{
get => GetInstanceProperty<Amazon.JSII.Tests.CalculatorNamespace.IIMutableObjectLiteral>();
get => GetInstanceProperty<Amazon.JSII.Tests.CalculatorNamespace.IMutableObjectLiteral>();
set => SetInstanceProperty(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Amazon.JSII.Tests.CalculatorNamespace
/// stability: Experimental
/// </remarks>
[JsiiClass(nativeType: typeof(Amazon.JSII.Tests.CalculatorNamespace.ClassWithPrivateConstructorAndAutomaticProperties), fullyQualifiedName: "jsii-calc.ClassWithPrivateConstructorAndAutomaticProperties")]
public class ClassWithPrivateConstructorAndAutomaticProperties : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IIInterfaceWithProperties
public class ClassWithPrivateConstructorAndAutomaticProperties : DeputyBase, Amazon.JSII.Tests.CalculatorNamespace.IInterfaceWithProperties
{
protected ClassWithPrivateConstructorAndAutomaticProperties(ByRefValue reference): base(reference)
{
Expand Down
Loading

0 comments on commit b9621f1

Please sign in to comment.