Skip to content

Commit 03103f3

Browse files
authored
fix: match behavioral interface to 'I'-prefix (#271)
This change incorporates two fixes that will make the tagging of interfaces as datatypes more correct going forward: - If a datatype candidate interface is named with an I-prefix (such as IConnectable), it will no longer be considered a datatype interface, regardless of whether it would qualify as one. - If an interface contains behavior (is definitely not a datatype interface) then the name must start with an I as well.
1 parent 1c56902 commit 03103f3

30 files changed

+430
-398
lines changed

packages/jsii-calc/lib/compliance.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,17 @@ export class GiveMeStructs {
520520
}
521521
}
522522

523-
export interface IInterfaceWithProperties {
523+
export interface InterfaceWithProperties {
524524
readonly readOnlyString: string;
525525
readWriteString: string;
526526
}
527527

528-
export interface IInterfaceWithPropertiesExtension extends IInterfaceWithProperties {
528+
export interface InterfaceWithPropertiesExtension extends InterfaceWithProperties {
529529
foo: number;
530530
}
531531

532532
export class UsesInterfaceWithProperties {
533-
constructor(public readonly obj: IInterfaceWithProperties) {
533+
constructor(public readonly obj: InterfaceWithProperties) {
534534

535535
}
536536

@@ -543,7 +543,7 @@ export class UsesInterfaceWithProperties {
543543
return this.obj.readWriteString;
544544
}
545545

546-
public readStringAndNumber(ext: IInterfaceWithPropertiesExtension) {
546+
public readStringAndNumber(ext: InterfaceWithPropertiesExtension) {
547547
return `base=${ext.readOnlyString} child=${ext.foo} keys=[${Object.keys(ext).join(',')}]`;
548548
}
549549
}
@@ -573,13 +573,13 @@ export class AllowedMethodNames {
573573
}
574574
}
575575

576-
export interface ReturnsNumber {
576+
export interface IReturnsNumber {
577577
obtainNumber(): Number;
578578
readonly numberProp: Number;
579579
}
580580

581581
export class OverrideReturnsObject {
582-
public test(obj: ReturnsNumber) {
582+
public test(obj: IReturnsNumber) {
583583
return obj.obtainNumber().doubleValue + obj.numberProp.doubleValue;
584584
}
585585
}
@@ -832,7 +832,7 @@ export namespace InterfaceInNamespaceIncludesClasses {
832832
* awslabs/jsii#175
833833
* Interface proxies (and builders) do not respect optional arguments in methods
834834
*/
835-
export interface InterfaceWithOptionalMethodArguments {
835+
export interface IInterfaceWithOptionalMethodArguments {
836836
hello(arg1: string, arg2?: number): void
837837
}
838838

@@ -918,7 +918,7 @@ export class DoNotOverridePrivates {
918918
/**
919919
* Class that implements interface properties automatically, but using a private constructor
920920
*/
921-
export class ClassWithPrivateConstructorAndAutomaticProperties implements IInterfaceWithProperties {
921+
export class ClassWithPrivateConstructorAndAutomaticProperties implements InterfaceWithProperties {
922922
public static create(readOnlyString: string, readWriteString: string) {
923923
return new ClassWithPrivateConstructorAndAutomaticProperties(readOnlyString, readWriteString);
924924
}

packages/jsii-calc/test/assembly.jsii

+94-94
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@
10431043
"fqn": "jsii-calc.ClassWithPrivateConstructorAndAutomaticProperties",
10441044
"interfaces": [
10451045
{
1046-
"fqn": "jsii-calc.IInterfaceWithProperties"
1046+
"fqn": "jsii-calc.InterfaceWithProperties"
10471047
}
10481048
],
10491049
"kind": "class",
@@ -1076,7 +1076,7 @@
10761076
"immutable": true,
10771077
"name": "readOnlyString",
10781078
"overrides": {
1079-
"fqn": "jsii-calc.IInterfaceWithProperties"
1079+
"fqn": "jsii-calc.InterfaceWithProperties"
10801080
},
10811081
"type": {
10821082
"primitive": "string"
@@ -1085,7 +1085,7 @@
10851085
{
10861086
"name": "readWriteString",
10871087
"overrides": {
1088-
"fqn": "jsii-calc.IInterfaceWithProperties"
1088+
"fqn": "jsii-calc.InterfaceWithProperties"
10891089
},
10901090
"type": {
10911091
"primitive": "string"
@@ -1498,50 +1498,35 @@
14981498
}
14991499
]
15001500
},
1501-
"jsii-calc.IInterfaceWithProperties": {
1501+
"jsii-calc.IInterfaceWithOptionalMethodArguments": {
15021502
"assembly": "jsii-calc",
1503-
"datatype": true,
1504-
"fqn": "jsii-calc.IInterfaceWithProperties",
1503+
"docs": {
1504+
"comment": "awslabs/jsii#175\nInterface proxies (and builders) do not respect optional arguments in methods"
1505+
},
1506+
"fqn": "jsii-calc.IInterfaceWithOptionalMethodArguments",
15051507
"kind": "interface",
1506-
"name": "IInterfaceWithProperties",
1507-
"properties": [
1508-
{
1509-
"abstract": true,
1510-
"immutable": true,
1511-
"name": "readOnlyString",
1512-
"type": {
1513-
"primitive": "string"
1514-
}
1515-
},
1508+
"methods": [
15161509
{
15171510
"abstract": true,
1518-
"name": "readWriteString",
1519-
"type": {
1520-
"primitive": "string"
1521-
}
1522-
}
1523-
]
1524-
},
1525-
"jsii-calc.IInterfaceWithPropertiesExtension": {
1526-
"assembly": "jsii-calc",
1527-
"datatype": true,
1528-
"fqn": "jsii-calc.IInterfaceWithPropertiesExtension",
1529-
"interfaces": [
1530-
{
1531-
"fqn": "jsii-calc.IInterfaceWithProperties"
1511+
"name": "hello",
1512+
"parameters": [
1513+
{
1514+
"name": "arg1",
1515+
"type": {
1516+
"primitive": "string"
1517+
}
1518+
},
1519+
{
1520+
"name": "arg2",
1521+
"type": {
1522+
"optional": true,
1523+
"primitive": "number"
1524+
}
1525+
}
1526+
]
15321527
}
15331528
],
1534-
"kind": "interface",
1535-
"name": "IInterfaceWithPropertiesExtension",
1536-
"properties": [
1537-
{
1538-
"abstract": true,
1539-
"name": "foo",
1540-
"type": {
1541-
"primitive": "number"
1542-
}
1543-
}
1544-
]
1529+
"name": "IInterfaceWithOptionalMethodArguments"
15451530
},
15461531
"jsii-calc.IRandomNumberGenerator": {
15471532
"assembly": "jsii-calc",
@@ -1565,6 +1550,31 @@
15651550
],
15661551
"name": "IRandomNumberGenerator"
15671552
},
1553+
"jsii-calc.IReturnsNumber": {
1554+
"assembly": "jsii-calc",
1555+
"fqn": "jsii-calc.IReturnsNumber",
1556+
"kind": "interface",
1557+
"methods": [
1558+
{
1559+
"abstract": true,
1560+
"name": "obtainNumber",
1561+
"returns": {
1562+
"primitive": "number"
1563+
}
1564+
}
1565+
],
1566+
"name": "IReturnsNumber",
1567+
"properties": [
1568+
{
1569+
"abstract": true,
1570+
"immutable": true,
1571+
"name": "numberProp",
1572+
"type": {
1573+
"primitive": "number"
1574+
}
1575+
}
1576+
]
1577+
},
15681578
"jsii-calc.ImplictBaseOfBase": {
15691579
"assembly": "jsii-calc",
15701580
"datatype": true,
@@ -1659,35 +1669,50 @@
16591669
}
16601670
]
16611671
},
1662-
"jsii-calc.InterfaceWithOptionalMethodArguments": {
1672+
"jsii-calc.InterfaceWithProperties": {
16631673
"assembly": "jsii-calc",
1664-
"docs": {
1665-
"comment": "awslabs/jsii#175\nInterface proxies (and builders) do not respect optional arguments in methods"
1666-
},
1667-
"fqn": "jsii-calc.InterfaceWithOptionalMethodArguments",
1674+
"datatype": true,
1675+
"fqn": "jsii-calc.InterfaceWithProperties",
16681676
"kind": "interface",
1669-
"methods": [
1677+
"name": "InterfaceWithProperties",
1678+
"properties": [
16701679
{
16711680
"abstract": true,
1672-
"name": "hello",
1673-
"parameters": [
1674-
{
1675-
"name": "arg1",
1676-
"type": {
1677-
"primitive": "string"
1678-
}
1679-
},
1680-
{
1681-
"name": "arg2",
1682-
"type": {
1683-
"optional": true,
1684-
"primitive": "number"
1685-
}
1686-
}
1687-
]
1681+
"immutable": true,
1682+
"name": "readOnlyString",
1683+
"type": {
1684+
"primitive": "string"
1685+
}
1686+
},
1687+
{
1688+
"abstract": true,
1689+
"name": "readWriteString",
1690+
"type": {
1691+
"primitive": "string"
1692+
}
1693+
}
1694+
]
1695+
},
1696+
"jsii-calc.InterfaceWithPropertiesExtension": {
1697+
"assembly": "jsii-calc",
1698+
"datatype": true,
1699+
"fqn": "jsii-calc.InterfaceWithPropertiesExtension",
1700+
"interfaces": [
1701+
{
1702+
"fqn": "jsii-calc.InterfaceWithProperties"
16881703
}
16891704
],
1690-
"name": "InterfaceWithOptionalMethodArguments"
1705+
"kind": "interface",
1706+
"name": "InterfaceWithPropertiesExtension",
1707+
"properties": [
1708+
{
1709+
"abstract": true,
1710+
"name": "foo",
1711+
"type": {
1712+
"primitive": "number"
1713+
}
1714+
}
1715+
]
16911716
},
16921717
"jsii-calc.JSObjectLiteralForInterface": {
16931718
"assembly": "jsii-calc",
@@ -2380,7 +2405,7 @@
23802405
{
23812406
"name": "obj",
23822407
"type": {
2383-
"fqn": "jsii-calc.ReturnsNumber"
2408+
"fqn": "jsii-calc.IReturnsNumber"
23842409
}
23852410
}
23862411
],
@@ -2530,31 +2555,6 @@
25302555
}
25312556
]
25322557
},
2533-
"jsii-calc.ReturnsNumber": {
2534-
"assembly": "jsii-calc",
2535-
"fqn": "jsii-calc.ReturnsNumber",
2536-
"kind": "interface",
2537-
"methods": [
2538-
{
2539-
"abstract": true,
2540-
"name": "obtainNumber",
2541-
"returns": {
2542-
"primitive": "number"
2543-
}
2544-
}
2545-
],
2546-
"name": "ReturnsNumber",
2547-
"properties": [
2548-
{
2549-
"abstract": true,
2550-
"immutable": true,
2551-
"name": "numberProp",
2552-
"type": {
2553-
"primitive": "number"
2554-
}
2555-
}
2556-
]
2557-
},
25582558
"jsii-calc.RuntimeTypeChecking": {
25592559
"assembly": "jsii-calc",
25602560
"fqn": "jsii-calc.RuntimeTypeChecking",
@@ -3087,7 +3087,7 @@
30873087
{
30883088
"name": "obj",
30893089
"type": {
3090-
"fqn": "jsii-calc.IInterfaceWithProperties"
3090+
"fqn": "jsii-calc.InterfaceWithProperties"
30913091
}
30923092
}
30933093
]
@@ -3106,7 +3106,7 @@
31063106
{
31073107
"name": "ext",
31083108
"type": {
3109-
"fqn": "jsii-calc.IInterfaceWithPropertiesExtension"
3109+
"fqn": "jsii-calc.InterfaceWithPropertiesExtension"
31103110
}
31113111
}
31123112
],
@@ -3135,7 +3135,7 @@
31353135
"immutable": true,
31363136
"name": "obj",
31373137
"type": {
3138-
"fqn": "jsii-calc.IInterfaceWithProperties"
3138+
"fqn": "jsii-calc.InterfaceWithProperties"
31393139
}
31403140
}
31413141
]
@@ -3401,5 +3401,5 @@
34013401
}
34023402
},
34033403
"version": "0.7.7",
3404-
"fingerprint": "vJH1gHlpRxKo77e0kE+6KATwgsZB0VpBcFEo/9OIG7Q="
3404+
"fingerprint": "ztjwo/sf4owA37SlePL0icwoE4gA3UJyvQ2Zl89FSco="
34053405
}

packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public override string TheProperty
493493
}
494494
}
495495

496-
class InterfaceWithProperties : DeputyBase, IIInterfaceWithProperties
496+
class InterfaceWithProperties : DeputyBase, IInterfaceWithProperties
497497
{
498498
string _x;
499499

packages/jsii-java-runtime-test/project/src/test/java/software/amazon/jsii/testing/ComplianceTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import software.amazon.jsii.tests.calculator.GiveMeStructs;
1717
import software.amazon.jsii.tests.calculator.IFriendlier;
1818
import software.amazon.jsii.tests.calculator.IFriendlyRandomGenerator;
19-
import software.amazon.jsii.tests.calculator.IInterfaceWithProperties;
19+
import software.amazon.jsii.tests.calculator.InterfaceWithProperties;
2020
import software.amazon.jsii.tests.calculator.IRandomNumberGenerator;
2121
import software.amazon.jsii.tests.calculator.InterfaceImplementedByAbstractClass;
2222
import software.amazon.jsii.tests.calculator.JSObjectLiteralForInterface;
@@ -555,7 +555,7 @@ public void setTheProperty(String value) {
555555

556556
@Test
557557
public void propertyOverrides_interfaces() {
558-
IInterfaceWithProperties obj = new IInterfaceWithProperties() {
558+
InterfaceWithProperties obj = new InterfaceWithProperties() {
559559
private String x;
560560

561561
@Override
@@ -581,7 +581,7 @@ public void setReadWriteString(String value) {
581581

582582
@Test
583583
public void interfaceBuilder() {
584-
IInterfaceWithProperties obj = IInterfaceWithProperties.builder()
584+
InterfaceWithProperties obj = InterfaceWithProperties.builder()
585585
.withReadOnlyString("READ_ONLY")
586586
.withReadWriteString("READ_WRITE")
587587
.build();

0 commit comments

Comments
 (0)